This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Issue facing on CC430F5133 interface with SHT15 (temperature sensor) I2C communication

Im post  my code , while setting UCTR for transmitter mode, and setting UCTXSTT to generate a START condition. , in the I2C comm using 10Kohm pull resistor, i cant able figure out the problem , can any one  help me , i hope i get quick solution from TI .

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT  i have using setting  default clock

  PMAPPWD = 0x02D52;                        // Get write-access to port mapping regs
  P1MAP3 = PM_UCB0SDA;                      // Map UCB0SDA output to P1.3
  P1MAP2 = PM_UCB0SCL;                      // Map UCB0SCL output to P1.2
  PMAPPWD = 0;                              // Lock port mapping registers

  P1SEL |= BIT2 + BIT3;                       // Select P1.2 & P1.3 to I2C function

  UCB0CTL1 |= UCSWRST;                                                // Enable SW reset
  UCB0CTL0 = UCMST + UCMODE_3  + UCSYNC;     // I2C Master, synchronous mode
  UCB0CTL1 = UCSSEL_2 + UCSWRST;                      // Use SMCLK, keep SW reset
  UCB0BR0 = 12;                                                                 // fSCL = SMCLK/12 = ~100kHz
  UCB0BR1 = 0;
 // UCB0I2COA = 0x48;
  UCB0I2CSA = slave_address;                         // Slave Address is 048h
  UCB0CTL1 &= ~UCSWRST;                              // Clear SW reset, resume operation
  UCB0IE |= UCRXIE + UCSTPIE + UCSTTIE;                         // Enable RX interrupt
  //UCB0IE |= UCRXIE;
  //isr=1;

  while (1)


        {
          __delay_cycles(50);                     // Delay required between transaction
          PTxData = (unsigned char *)TxData;      // TX array start address
                                                  // Place breakpoint here to see each
                                                  // transmit operation.
          TXByteCtr = sizeof TxData;              // Load TX byte counter

          UCB0CTL1 |= UCTR + UCTXSTT;             // I2C TX, start condition
          //UCB0I2CSA = 000;
          __bis_SR_register(LPM0_bits + GIE);     // Enter LPM0, enable interrupts
          __no_operation();                       // Remain in LPM0 until all data
                                                  // is TX'd
          while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent
           UCB0CTL1 &= ~ UCTR              // I2C RX,

          UCB0CTL1 |= ~UCTXSTT;          //I2C Start
          do
          {
               UCB0CTL1 |= UCTXSTT;                      // RE-START
               while (UCB0CTL1&UCTXSTT);              //wait for STT clear again

          }     while (UCB0STAT & UCNACKIFG);

               PRxData = (unsigned char *)RxBuffer;    // Start of RX buffer
               RXByteCtr = 5;                          // Load RX byte counter
               while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent
               UCB0CTL1 |= UCTXSTT;                    // I2C start condition

               __bis_SR_register(LPM0_bits + GIE);     // Enter LPM0, enable interrupts
                                                       // Remain in LPM0 until all data
                                                       // is RX'd
               __no_operation();                       // Set   breakpoint >>here<< and
        }
}
#pragma vector = USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
      {
        switch(__even_in_range(UCB0IV,12))
        {
        case  0: break;                           // Vector  0: No interrupts
        case  2: break;                           // Vector  2: ALIFG
        case  4: break;                           // Vector  4: NACKIFG
        case  6: break;                           // Vector  6: STTIFG
        case  8: break;                           // Vector  8: STPIFG
        case 10:                                     // Vector 10: RXIFG
        RXByteCtr--;                            // Decrement RX byte counter
          if (RXByteCtr)
          {
            *PRxData++ = UCB0RXBUF;               // Move RX data to address PRxData
            if (RXByteCtr == 1)                   // Only one byte left?
             UCB0CTL1 |= UCTXSTP;                // Generate I2C stop condition
          }
          else
          {
            *PRxData = UCB0RXBUF;                 // Move final RX data to PRxData
            __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
          }
        break;
        case 12:                                  // Vector 12: TXIFG
          if (TXByteCtr)                          // Check TX byte counter
          {
            UCB0TXBUF = *PTxData++;               // Load TX buffer
            TXByteCtr--;                          // Decrement TX byte counter
          }
          else
          {
            UCB0CTL1 |= UCTXSTP;                  // I2C stop condition
            UCB0IFG &= ~UCTXIFG;                  // Clear USCI_B0 TX int flag
            __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
          }break;
        default: break;
        }
      }

after sending command , the UCTXIFG does not set , 

Thank you.

  • Hello Murali,

    I will be moving your question to the  MSP430™ Microcontrollers forums so that your question gets answered in a timely manner.

    Thanks,

    Abhi

  • 10k might be too high. You might want to try 4k7. It depends on line length, line capacitance, number and (electrical) implementation of the slave I2C interface etc. In some case, down to 1k is required at higher lock speeds.

    Do MSP and sensor have common GND? If they have separate supply, or even different supply voltage, ensure that the pull-ups are not above MSP supply, but still sufficient for the sensor to be accepted as high.

    If you map the I2C pins to something different than the original pins, you need to map the original pins to PM_ANALOG, as multiple assignments are OR’d and result in a constant high level detected by the USCI.

    (if P1.2/P1.3 are the original mappings, then there is no need to remap at all, I didn’t check)

    You should use binary “|” to combine bits, not arithmetic “+”.

    Sure that 0x48 is the slave address? The slave address to be used does NOT include the R/W bit. But most manufacturers give a start byte (where the LSB is the R/W bit) as ‘address’, separate for read and write.

    I don’t see you setting UCTXIE, so the system will stall in LPM  after sending the start byte since no data is sent and sending never ends. This is likely your main problem.

    Before starting the transmission, it is a good idea to clear GIE, so the ISR you want to wake you up isn’t called before you actually got to sleep. It doesn’t matter here, but some time it will.

    No need to clear the TXIFG flag in the ISR – reading UCB0IV has already cleared it.

**Attention** This is a public forum