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.

MSP430F4152: I2c signals like SDA and SCl are not generated on the controller pins

Part Number: MSP430F4152

I have downloaded one demo code for i2c communication for MSP430F4152 controller

i have 32.768Khz external crystal and 4.7K pullup resistors are connected to the SDA and SCL line

and i checked signals on pin 1 and 2 but it is not showing any pulses on SCL and SDA 

please check the code

int TXByteCtr;
unsigned char PRxData;
int Rx = 0;
char WHO_AM_I = 0x00;

unsigned char itgAddress = 0xA0;

void init_I2C(void);
void Transmit(void);
void Receive(void);


int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P6SEL |= BIT1+BIT2; // Assign I2C pins to USCI_B0
//P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
//P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
init_I2C();


while(1)
{
//Transmit process
Rx = 0;
TXByteCtr = 1;
Transmit();
//Receive process
Rx = 1;
Receive();
}
}

//-------------------------------------------------------------------------------
// The USCI_B0 data ISR is used to move received data from the I2C slave
// to the MSP430 memory. It is structured such that it can be used to receive
//-------------------------------------------------------------------------------
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
if(Rx == 1)
{ // Master Recieve?
PRxData = UCB0RXBUF; // Get RX data
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
else
{ // Master Transmit
if (TXByteCtr) // Check TX byte counter
{
UCB0TXBUF = WHO_AM_I; // Load TX buffer
TXByteCtr--; // Decrement TX byte counter
}
else
{
UCB0CTL1 |= UCTXSTP; // I2C stop condition
IFG2 &= ~UCB0TXIFG; // Clear USCI_B0 TX int flag
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
}

}
void init_I2C(void) {
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 1; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = itgAddress; // Slave Address is 069h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0RXIE + UCB0TXIE; //Enable RX and TX interrupt
}

void Transmit(void){
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
__bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts
}
void Receive(void){
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
UCB0CTL1 &= ~UCTR ; // Clear UCTR
UCB0CTL1 |= UCTXSTT; // I2C start condition
while (UCB0CTL1 & UCTXSTT); // Start condition sent?
UCB0CTL1 |= UCTXSTP; // I2C stop condition
__bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts
}

Please guide us as our R & D and further production is struct up

Regards,

Anushka

  • unsigned char itgAddress = 0xA0;

    An I2C address is only 7 bits, so I can tell that this address is incorrect. My first guess is that the correct address is (0xA0 >> 1) = 0x50.

    -----

    UCB0BR0 = 1; // fSCL = SMCLK/12 = ~100kHz

    This runs the I2C at 1MHz, which is not supported by the MSP430. Try:

    > UCB0BR0 = 10; // fSCL = SMCLK/10 = ~100kHz

    -----

    Neither of these quite fits your symptom, since I expect you would see a little bit of activity even though all transactions would fail. All the same, I suggest you fix these so you can see what the next step is.

  • I have chaged the code  as you suggested.

     unsigned char itgAddress = 0x50;

     UCB0BR0 = 10; 

    but waveforms for SCL and SDA are not generated.

    to further check if  USCIAB0RX_VECTOR interrupt is generated

    I use one port pin to drive LED.

    At power on I turn on the LED.

    in  USCIAB0RX_VECTOR interrupt routine Toggle the LED.

     

    When i run the program LED turn on and then turns off and nothing is happened

    Regards,

    Anushka

  • Is it correct that you see no activity at all on SCL and SDA? What voltage level(s) do you see?

    If the I2C slave is holding SCL low ("clock stretching") the MSP430 won't be able to generate a Start condition.

    -----------------------

    I don't see a USCIAB0RX_VECTOR above. Which IE bit(s) are you using to trigger it?

  • Yes  there is no activity at all on SCl and SDA pin . both is the pins and connected to the vcc through 4.7K Pullup resistor.

    and both the pin has 3.2V

    In code I have enabled Tx interrupt 

    see the code.

    Is it required anything in the code. it seems I2C periplaral is not enabled 


    unsigned char *PTxData; // Pointer to TX data
    unsigned char TXByteCtr;
    const unsigned char TxData[] = // Table of data to transmit
    {
    0x11,
    0x22,
    0x33,
    0x44,
    0x55
    };

    int main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT

    #if ADD_BACKLIGHT
    P6OUT = 0x00;
    P6DIR |= 0xff;

    P6DIR |= BIT1; // Set P6.1 output direction
    P6DIR |= BACKLIGHT_CONTROL; // Set P6.7 output direction
    P6OUT ^= BACKLIGHT_CONTROL;
    #endif //
    P6SEL |= BIT1+BIT2; // Assign I2C pins to USCI_B0
    UCB0CTL1 |= UCSWRST; // Enable SW reset
    UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
    UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
    UCB0BR0 = 10; // fSCL = SMCLK/11 = 95.3kHz
    UCB0BR1 = 0;
    UCB0I2CSA = 0x50; // Slave Address is 048h
    UCB0I2CIE |= UCSTTIE; //start condition intrrupt enable
    UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
    IE2 |= UCB0TXIE; // Enable TX interrupt

    while (1)
    {
    PTxData = (unsigned char *)TxData; // TX array start address
    TXByteCtr = sizeof TxData; // Load TX byte counter
    UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
    __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts
    // Remain in LPM0 until all data
    // is TX'd
    __no_operation();
    while (UCB0CTL1 & UCTXSTP); // Loop until STP is TX'd
    }
    }

    //------------------------------------------------------------------------------
    // The USCIAB0TX_ISR is structured such that it can be used to transmit any
    // number of bytes by pre-loading TXByteCtr with the byte count. Also, TXData
    // points to the next byte to transmit.
    //------------------------------------------------------------------------------
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCIAB0TX_VECTOR
    __interrupt void USCIAB0TX_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCIAB0TX_VECTOR))) USCIAB0TX_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {

    #if ADD_BACKLIGHT
    P6OUT ^= BACKLIGHT_CONTROL;
    #endif //
    if (TXByteCtr) // Check TX byte counter
    {
    UCB0TXBUF = *PTxData++; // Load TX buffer
    TXByteCtr--; // Decrement TX byte counter
    }
    else
    {
    UCB0CTL1 |= UCTXSTP; // I2C stop condition
    IFG2 &= ~UCB0TXIFG; // Clear USCI_B0 TX int flag
    __bic_SR_register_on_exit(CPUOFF); // Exit LPM0
    }
    }

  • Today i checked again .I found SDA Line is low and see 20usec Hi to Lo pulse and again SDA goes to high on SDA pin and on SCL pin remains high continuouly

  • UCB0I2CIE |= UCSTTIE; //start condition intrrupt enable

    This will cause the USCIAB0RX_VECTOR to be called, but I don't see one in this code, so it will end up at ISR_Trap.

    You don't seem to have a use for this, so I suggest you remove this line.

  • I deleted the code UCB0I2CIE |= UCSTTIE

    but result is still same SCL and SDA are not generated

    I can see 20 Microsecond pulse on SDA and then SDA becomes High, SCL is continuously High

     

     

  • Hi Anushka,

    Can you try this example from resource explorer and confirm whether it works:

    https://dev.ti.com/tirex/explore/node?node=ADa7OW6O26g9z.bVHAb53A__IOGqZri__LATEST&search=msp430F4152

    BR,
    Leo

**Attention** This is a public forum