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.

I2C configuration

Other Parts Discussed in Thread: MSP430FR5739, DLPC2607

Hi,

I am really want some help in understanding I2C interfacing.

I am using accelerometer which has its device address 0x31(7-bits) and the control register address is 0x20 which is r/w register and i want to write data 0x65 to this register and to check whether this data is written i want to read the same register so i have to receive the same data which is 0x65.

The MCU is MSP430FR5739 exp board.

The question here is which order i have to follow for the above said description ?

Here master is the MSP430 and slave is the accelerometer.

i have set UCB0I2COA0 =0x31; and to read and write the control register do i need to set again UCB0I2COA0 =0x20 ? 

MASTER_TX(0x31);       (where this will set       UCB0I2COA0 =0x31)

MASTER_TX(0x02);        (where this will set       UCB0I2COA0 =0x20)

MASTER_TX(0x65);      (where this will set       UCB0I2COA0 =0x31 and Tx_buffer = 0x65)

SLAVE_RX();                    

SLAVE_TX();

MASTER_RX();

is this order is correct ? and i am following device example codes but not working.

 i am calling all these function under the same program.

Please help me..

Regards.

  • The UCBxI2COAy registers are for teh case where the USCI operates as slave adn has more than one slave address.

    OA means Own Address.

    Since you operate the MSP as master, you don't need these registers at all.

    You write the address of the slave to UCB0I2CSA register (SA for Slave Address). Then you set the UCTR bit (to send something), set the UCTXSTT bit, and the USCI will send the content of the SA register and the R/W bit (inverted UCTR bit). Then you write the register address to TXBUF, so the USCI will send it to the slave. Note that the slave register address is a high-level protocol thing and depends on the slave. For I2C protocol (and therefore for the USCI), it is just a data byte that is sent. It's just the slave that interprets the first byte written to it as a register address. Followed by more data that is written to this and the following registers.
    To read the register, you start a new transmission and send only the address, then immediately start a read operation to read the content of this register (and the following ones).

    I don' tknow what your MASTER_RX/TX or SLAVE_RX/TX do but it seems wrong (at least) to use both in the same code. Except you try to send to yourself (which won't work anyway within the same USCI module, but might work with two independent USCI modules on the same MSP)

    The low-level sequence for register write is:

    0x31->UCB0I2CSA
    set UCTR
    set UCTXSTT
    0x20->UCB0TXBUF
    wait for UCTXSTT to clear
    check for UCNACKIFG (if set, the slave didn't answer -> set UCTXSTP and exit)
    check UCTXIFG (should be set at this point)
    0x65-> UCB0TXBUF
    wait for UCTXIFG set again
    set UCTXSTP
    wait for UCTXSTP to clear

    For reading the data back, do the same as above, but instead of writing 0x65 to TXBUF:
    clear UCTR
    set UCTXSTT
    wait for UCTXSTT to clear
    check UCNACKIFG once more (just to be sure -  if you got that far already, the slave should answer, but some slaves might not, e.g. flash memory chips which are still writing the last data)
    set UCTXSTP
    wait for UCRXIFG
    read the content of register 0x20 from UCB0RXBUF

  • Hi, Could you please tell me how did you get the device address of your accelerometer?

    Thanks,

    Jully

  • It should be in the device data sheet.

  • Thanks for the reply. But I cannot find the device address in DLPC2607 Datasheet :(

  • jully song said:

    Thanks for the reply. But I cannot find the device address in DLPC2607 Datasheet :(

    It's at the top of page 12.

**Attention** This is a public forum