I need to read data from a chip that uses I2C. The I2C driver appears to only have a way to send the address but not away to send the address and the register I need to read from. The function I2C_DRV_MasterReceiveDataBlocking sends a read command over i2c but doesn’t have a way to include the register I wan to read from.
Solved! Go to Solution.
Hi,
per my understanding of the driver you need to do 2 calls
I2C_DRV_MasterSendDataBlocking(INST_I2C1, masterTxBuffer, TRANSFER_SIZE, false, OSIF_WAIT_FOREVER);
I2C_DRV_MasterReceiveDataBlocking(INST_I2C1, masterRxBuffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);
MasterTxBuffer includes register address to be read, if it is 7bit only then TRANSFER_SIZE will be 1. False for "sendStop" parameter is used to chain multiple transfers with repeated START condition between them.
BR, Petr
I did some research over the weekend and you are correct. It has been a while since I had to look a the lower level code for I2C that I forgot you need to do a write before you do a read. The I2C interfaces I have dealt with in the past hide that from me so you forget the fact you need to do a write before you do a read.
I also forgot to say when you call I2C_DRV_MasterSendDataBlocking the R/W bit will not be set so you are doing a write not a read. The i2c driver the K65 did it correctly the one for MPC5748G doesn't seem to be done correctly.
Hi,
you did not specify slave and its protocol, but generally a reading from defined address looks like below. So first you write device and defined address, then read addressing device again
BR, Petr
I looked at the code for I2C_DRV_MasterReceiveDataBlocking and it will send the I2C address again.
Hi,
per my understanding of the driver you need to do 2 calls
I2C_DRV_MasterSendDataBlocking(INST_I2C1, masterTxBuffer, TRANSFER_SIZE, false, OSIF_WAIT_FOREVER);
I2C_DRV_MasterReceiveDataBlocking(INST_I2C1, masterRxBuffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);
MasterTxBuffer includes register address to be read, if it is 7bit only then TRANSFER_SIZE will be 1. False for "sendStop" parameter is used to chain multiple transfers with repeated START condition between them.
BR, Petr