MPC5748G how do you read a register using I2C

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MPC5748G how do you read a register using I2C

Jump to solution
1,496 Views
MattJCole
Contributor V

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.

Tags (1)
0 Kudos
Reply
1 Solution
1,481 Views
PetrS
NXP TechSupport
NXP TechSupport

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

View solution in original post

0 Kudos
Reply
5 Replies
1,428 Views
MattJCole
Contributor V

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. 

0 Kudos
Reply
1,475 Views
MattJCole
Contributor V

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.   

0 Kudos
Reply
1,438 Views
PetrS
NXP TechSupport
NXP TechSupport

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

PetrS_0-1644827462454.png

BR, Petr

0 Kudos
Reply
1,475 Views
MattJCole
Contributor V

I looked at the code for I2C_DRV_MasterReceiveDataBlocking and it will send the I2C address again.

0 Kudos
Reply
1,482 Views
PetrS
NXP TechSupport
NXP TechSupport

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

0 Kudos
Reply