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.

MSP430F5529 I2C - How to read from slave register

Other Parts Discussed in Thread: MSP430F5529, MSPDRIVERLIB

Hi team,

Let me preface this by saying  I am a power/analog guy struggling in the digital realm :) I am currently attempting to  use an MSP430F5529 to read from one of our battery charger registers using I2C. I understand how to write to the device, but am struggling with the read functionality.

Right now, I am working  with  the TI_USCI_I2C_master  library found in slaa382a, but am open to changing  this.

To  keep things general, let's say my slave address  is  0x6A, and I want to read the data from a 16 bit register located at 0x0E, what would that look like? A quick example would get me on  my feet and running.

Thanks in  advance!

  • Reading a register typically involves a repeated start condition when switching from writing the address to reading the value, and this is not supported by that library.

    If you want to use a library, I'd recommend driverlib, but you could just program the registers directly. Both driverlib and the F5529 have example programs.
  • Hi David,

    That's all right, I struggle with anything and everything involving power/analog! First of all, do not use the I2C library from SLAA382a as the materials/resources from this application report are quite old. I recommend using the latest version of CCS and MSPDRIVERLIB to accomplish the communication you desire. I would start with the usci_b_i2c_ex1_master[Rx,Tx]Single example projects (can be downloaded from Resource Explorer or imported from your MSP430 DriverLib install location), change the SLAVE_ADDRESS definition to 0x6A in both, and change the transmit Data in the Tx example to 0x0E. Initialization should be the same but you will need to merge the two examples so that you Tx the register location and then Rx the data desired, you may also want to use USCI_B_I2C_masterSendMultiByteStart instead of USCI_B_I2C_masterSendSingleByte for a repeated start (to avoid an unnecessary stop condition between the TX and RX) but this step shouldn't be critical.

    If you encounter any difficulties be sure to come back with oscilloscope or logic analyzer screenshots detailing the communication issues you are experiencing. A quick search on the E2E may bring you to similar I2C requests with helpful example code.

    Regards,
    Ryan
  • Clemens and Ryan,

    Thank you guys for the help! I will be sure to look into Driverlib. The above post was very helpful! I just needed a bit of a jump start to get me going I think. I will be sure to have appropriate scope traces if I need further assistance.
  • Ryan (or Clemens),

    I have another general question that I am hoping you can help me out with - when writing(or reading) to a slave internal register I have seen that there will generally be an acknowledge sent. So, the general sequence looks like this:

    Start| TGT ADDRESS | R/W | ACK | COMMAND (register to write/read)| ACK | Low Byte |ACK | High Byte|ACK |Stop

    My question is, does the master (and by extension, my code), need to do anything with the acknowledge bits between commands and low/high bytes? Or can I just send the command and data bytes in one transmit function? I am using the multibyte functions you recommended in the driverlib library, by the way.

    Thank you for helping me out on this. Normally I would steer clear of the embedded world, but I am trying to put together a demo for the BMS Deepdive coming up in a couple weeks so I don't have much of a choice.

  • David,

    I'm finding your sequence to be a bit confusing to interpret so below is my visualization of how a complete 1-byte read sequence from a specific register should occur:

    Start bit | address + write (0x6A<<0x01 + 0x00) | ACK from slave | register location (0x0E) | ACK from slave | repeated start bit | address + read (0x6A<<0x01 + 0x01) | ACK from slave | read byte | ACK from master | stop bit

    This is a link to the I2C protocol guide that I've used in the past and find the most useful: www.robot-electronics.co.uk/i2c-tutorial

    Regards,
    Ryan
  • If you don't get an ACK, UCNACKIFG is set, and you must send a stop or a restart. In most situations, it's unlikely to happen, and the code ignores it.

**Attention** This is a public forum