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.

MSP430G2553: I2C Write to specific Register

Part Number: MSP430G2553
Other Parts Discussed in Thread: LP5024,

Hi,

I am looking to get some help on using the MSP430G2553 with I2C. I am trying to change a specific register on a peripheral (LP5024) but don't quite understand how this can be accomplished using an MSP430. I have found the following documentation on how this can be accomplished:

  

What I don't understand is how this can be translated into code. I have been looking at the examples and none of them quite seem to fit into this situation. 

One question that I have is regarding step 2 and the MSP430 buffer UCB0I2CSA. When transmitting a sequence of data, does this automatically get sent at the beginning or do I need to do it manually. For example, say I wanted to write 0xFF to register 0x00 of a peripheral with address 0x88. Do i need to manually send 

const unsigned char TxData ={ 0x00 , 0xFF }; // Table of data to transmit

or

const unsigned char TxData ={ 0x88, 0x00 , 0xFF }; // Table of data to transmit

?

If it is the second option, what is the purpose of the UCB0I2CSA buffer?

I have been using the code msp4302xx3_uscib0_i2c_08.c as the framework for my work. If I want to change two separate registers on my peripheral, can I simply duplicate the code inside the main loop like this?

while (1)
{
    PTxData = (unsigned char *)TxData1;             // TX array start address
    TXByteCtr = sizeof TxData1;                       // Load TX byte counter
    while (UCB0CTL1 & UCTXSTP);                     // Ensure stop condition got sent
    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


    PTxData = (unsigned char *)TxData2;             // TX array start address
    TXByteCtr = sizeof TxData2;                           // Load TX byte counter
    while (UCB0CTL1 & UCTXSTP);                    // Ensure stop condition got sent
    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
}

Thank you for your help!

Kathleen

  • You don't do anything explicit for step 2. The I2C unit will construct this ("SLA") byte based on I2CSA and UCTR, and send it automatically following the Start Condition.

    The slave address (I2CSA) is 7 bits, so supposing ADDR0-1 are tied to GND this would be 0x28 [Ref LPS50xx data sheet (SLVSEB8B) Table 2]

    You should be able to write 2 registers just by repeating the code as you have done. As you add function you'll probably want to write a wrapper function. Most of the work is done in the ISR. When you want to read some bytes you'll probably want to move on to something like i2c_10.c or i2c_12.c.

  • Hi 

    You should follow the programming description in of the LP5024 datasheet page 18

    I think the code example will better for you link

**Attention** This is a public forum