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.

USI I2C Library for MSP430 LaunchPad

Other Parts Discussed in Thread: PCF8574, MSP430G2231, MSP430F2002, MSP430G2332

Hello TI Community,

I would like to know how to use the TI USI I2C Library with my MSP430 LaunchPad.

PS: I ran the TI sample codes without any problems.

I will appreciate any comments or suggestions.

Thanks,

Andres Rada. 

  • Dear aBUGSworstnightmare,

    I tried this part of the example with and I/O Expander (PCF8574) and I noticed that the program executes all lines but it didn't send anything  via IIC bus.

    I would like to know if I made a mistake in this code.

    Thanks for your advice,

    Andres Rada.

     

    #include<msp430g2231.h>

    #include "USI_I2CMaster.h"

    unsigned char TxData0[] = {8};

    int StatusCallback(unsigned char c);  

     

    void main(void)

    {

      int i;

      WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog

      if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)                                     

      {  

        while(1);                               // If calibration constants erased

                                                // do not load, trap CPU!!

      } 

      BCSCTL1 = CALBC1_1MHZ;                    // Load DCO constants

      DCOCTL = CALDCO_1MHZ;

      P1DIR |= 0x01;                            // P1.0 as output (LED)

      P1OUT = 0x00;

     

      /* Initialize USI module, clock ~ SMCLK/128 */

      TI_USI_I2C_MasterInit(USIDIV_7+USISSEL_2+USICKPL, StatusCallback); 

     

      /* Acknowledge polling function - LED blinks continuously until slave device 

      provides an ACK 

      TI_USI_I2CSelect(unsigned char SlaveAddress) */

      while(TI_USI_I2CSelect(0x20))

      { 

        P1OUT ^= 0x01;                          // Toggle LED

        for (i = 0; i < 0x3000; i++);           // Delay

      }

     

      P1OUT =0;                                 // Slave acknowledged, LED off

     

      /* Transmit data to the EEPROM device, prefixed by page address 0x01 

       TI_USI_I2CWrite(SlaveAddress, Length, Multi, TxData) */

      __disable_interrupt();

      TI_USI_I2CWrite(0x20,1,0,TxData0);

      __bis_SR_register(LPM0_bits + GIE);

     

      /* Acknowledge polling function - loops continuously until slave device 

      provides an ACK */

      while(TI_USI_I2CSelect(0x20));              

     

      /* This function can be used to end any open I2C transaction.

      Use only if I2C transaction was left open previously by setting stop

      condition bit =1 */

      TI_USI_I2CStop();                          

     

      P1OUT |= 0x01;                            // data valid, LED on

      while(1);                                 // program ends here

     

    int StatusCallback(unsigned char c)

    {

      return TI_USI_EXIT_LPM;                   // Exit active for next transfer

    }

  • I don't see the port being configured for USI control by settign the appropriate bits in PxSEL.
    Is it done in the I2C init funciton, and if so, does this function use constants you need to adjust to the exact MSP you're using?

    On different MSPs, the USI signals are routed to different port pins and therefore need different port initialization in addition to the USI module itself. (this applies to every hardware module with I/O funcitonality)

  • I'm into the same problem with EEPROM At24c02.I'm also not getting the o/p(on reading the EEPROm ;Nothing is writtem their ).It is very urgent please rply asap.I have also removed the jumper 5 but even after this it is not working.

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    #include

     

     

    <msp430g2231.h>

    char

     

     

    MST_Data = 0x01;

    // Variable for transmitted data

    char

     

     

    SLV_Addr = 0x50;

    int

     

     

    I2C_State = 0;

    // State variable

     

    void

     

     

    initialize(void

    )

    {

    WDTCTL = WDTPW + WDTHOLD;

     

    // Stop watchdog

     

     

    if

    (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)

    {

     

     

    while(1);

    // If calibration constants erased

     

     

    // do not load, trap CPU!!

    }

    BCSCTL1 = CALBC1_1MHZ;

     

    // Set DCO

    DCOCTL = CALDCO_1MHZ;

     

    P1OUT = 0xC0;

     

    // P1.6 & P1.7 Pullups, others to 0

    P1REN |= 0xC0;

     

    // P1.6 & P1.7 Pullups

    P1DIR = 0xFF;

     

    // Unused pins as outputs

     

    USICTL0 = USIPE6+USIPE7+USIMST+USISWRST;

     

    // Port & USI mode setup

    USICTL1 = USII2C+USIIE;

     

    // Enable I2C mode & USI interrupt

    USICKCTL = USIDIV_3+USISSEL_2+USICKPL;

    USICNT |= USIIFGCC;

     

    // Disable automatic clear control

    USICTL0 &= ~USISWRST;

     

    // Enable USI

    USICTL1 &= ~USIIFG;

     

    // Clear pending flag

    _EINT();

    }

     

     

     

    void

     

     

    main(void

    )

    {

    initialize();

     

     

     

    while

    (1)

    {

    USICTL1 |= USIIFG;

     

    // Set flag and start communication

    }

    }

     

     

     

    /******************************************************

    // USI interrupt service routine

    ******************************************************/

    #pragma

     

     

    vector = USI_VECTOR

    __interrupt

     

    void USI_TXRX (void

    )

    {

     

     

    switch

    (I2C_State)

    {

     

     

    case 0:

    // Generate Start Condition & send address to slave

    // P1OUT |= 0x01; // LED on: sequence start

    USISRL = 0x00;

     

    // Generate Start Condition...

    USICTL0 |= USIGE+USIOE;

    USICTL0 &= ~USIGE;

     

    USISRL = SLV_Addr;

     

    // ... and transmit address, R/W = 0

    USICNT = (USICNT & 0xE0) + 0x08;

     

    // Bit counter = 8, TX Address

    I2C_State = 2;

     

    // Go to next state: receive address (N)Ack

     

     

    break

    ;

     

     

     

    case 2:

    // Receive Address Ack/Nack bit

    USICTL0 &= ~USIOE;

     

    // SDA = input

    USICNT |= 0x01;

     

    // Bit counter = 1, receive (N)Ack bit

    I2C_State = 4;

     

    // Go to next state: check (N)Ack

     

     

    break

    ;

     

     

     

    case 4:

    // Process Address Ack/Nack & handle data TX

    USICTL0 |= USIOE;

     

    // SDA = output

     

     

    if (USISRL & 0x01)

    // If Nack received...

    {

     

    // Send stop...

    USISRL = 0x00;

    USICNT |= 0x01;

     

    // Bit counter = 1, SCL high, SDA low

    I2C_State = 10;

     

    // Go to next state: generate Stop

    P1OUT |= 0x01;

     

    // Turn on LED: error

    }

     

     

    else

    {

     

    // Ack received, TX data to slave...

    USISRL = MST_Data;

     

    // Load data byte

    USICNT |= 0x08;

     

    // Bit counter = 8, start TX

    I2C_State = 6;

     

    // Go to next state: receive data (N)Ack

    // P1OUT &= ~0x01; // Turn off LED

    }

     

     

    break

    ;

     

     

     

    case 6:

    // Receive Data Ack/Nack bit

    USICTL0 &= ~USIOE;

     

    // SDA = input

     

    USICNT |= 0x01;

     

    // Bit counter = 1, receive (N)Ack bit

     

    I2C_State = 8;

     

    // Go to next state: check (N)Ack

     

     

    break

    ;

     

     

     

    case 8:

    // Process Data Ack/Nack & send Stop

    USICTL0 |= USIOE;

     

     

    if (USISRL & 0x01)

    // If Nack received...

    {

    P1OUT |= 0x01;

     

    // Turn on LED: error

    }

     

     

    else

    // Ack received

    {

    P1OUT &= ~0x01;

     

    // Turn off LED

    }

     

     

    // Send stop...

    USISRL = 0x00;

    USICNT |= 0x01;

     

    // Bit counter = 1, SCL high, SDA low

    I2C_State = 10;

     

    // Go to next state: generate Stop

     

     

    break

    ;

     

     

     

    case 10:

    // Generate Stop Condition

    USISRL = 0x0FF;

     

    // USISRL = 1 to release SDA

    USICTL0 |= USIGE;

     

    // Transparent latch enabled

    USICTL0 &= ~(USIGE+USIOE);

     

    // Latch/SDA output disabled

    I2C_State = 0;

     

    // Reset state machine for next transmission

     

     

    // LPM0_EXIT; // Exit active for next transfer

     

     

    break

    ;

    }

     

    USICTL1 &= ~USIIFG;

     

    // Clear pending flag

    }

     

     

     

     

     

     

  • .

     

     

    Did you solve the problem? I have same problem here

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  • The same problem here. I got a msp430f2002 and got the same behavior. I ordered about 5 msp430 chips and all of the use USI. I have only tested two without luck. Anybody out there that can explain this to us??

  • I am new in MSP430 world. Appreciate if someone point me to a link where I can get the I2C USI library for the MSP430G2332. I could not find it with CCS V5.3. Thanks

**Attention** This is a public forum