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.

MSP432E401Y: How to read I2C device registers using DriverLib?

Part Number: MSP432E401Y

Hi forum,

I have an I2C device that has a slave address, followed by a register address within the slave device and then 4 bytes of data for that register. 

Following the MSP432E4 Example Project for I2C-Master for Simple Write and Read, I am able to Start a write the slave address (0x23), the register address (0x05), and then the 4 bytes of data (0xFF, 0x7F, 0x3F, 0x00), followed by a Stop.  This works exactly as expected:

However, I should also be able to read back the values from the specified register address, but the example I based this off doesn't seem to handle the sending of an which address to read from.  It simply reads a specified number of bytes from a slave address.

I think what I need to do is something like the following:

  • Send master start with write to slave device address (0x23)
  • Send register address I want to read (0x05)
  • Send master restart with read to slave device address (0x23)
  • Read data from slave address four times (0xFF, 0x7F, 0x3F, 0x00)
  • Send stop

Can anyone explain how to do this using DriverLib?  The (simplistic) example is interrupt-driven, so the I2C write of the data is a simple call that starts the write and then waits for the state I2C_MASTER_TX to end.  All of the intermediate transitions are handled inside the ISR.  It simply performs a loopback of two MSP432 boards, one acting as the master and the other acting as the slave.

Thanks in advance for any guidance - this is driving me crazy, and it just can't be that hard.

surrealist14

  • Hello surrealist14,

    So the drivelib APIs give you full control of sending/receiving bytes via I2C. You do still need to tell the APIs how many bytes you want to read, whether that's single, burst, or FIFO modes. So if you know that you need to read 4 bytes every time for that register, then you would just need to utilize the read API and tell it four bytes. 

  • Thanks, Jace,

    Maybe I didn't make myself clear.  The problem isn't with reading 4 bytes.  The problem is that I need to send the _register_ I want to read from before I read the 4 bytes.  As I suspected earlier, this involved writing the slave address and register number, then, in the same transaction, reading from the slave address for 4 bytes.  I revised the ISR code in the example to provide the ability to start a write to the slave address, then write the register address, then switch to starting a burst read and reading in the 4 bytes as before.  It's now working as expected.  An example reading from register 0 is shown below.

    Best regards!

    Scott