problem about I2C read sequence

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

problem about I2C read sequence

595 Views
李珍珍
Contributor I

when i used the demo code of I2C read function in thetext named "I2C_read_access _valu_ Transfer" ,the code cannot be run correctly,it alwals stoped in the code of while((!nakFlag) && (!completionFlag)),therefor, I can write datas to the slave correct,so i am sure the slave address and the configuration of the I2C is correct.and now, I don't know how to solve the problem,and read datas from the slave address.
here is the demo code and the read sequence of my slave device:
demo code of I2C read function :
static bool I2C_ReadAccelRegs(I2C_Type *base, uint8_t device_addr, uint8_t reg_addr, uint8_t *rxBuff, uint32_t rxSize)
{
i2c_master_transfer_t masterXfer;
memset(&masterXfer, 0, sizeof(masterXfer));
masterXfer.slaveAddress = device_addr;
masterXfer.direction = kI2C_Read;
masterXfer.subaddress = reg_addr;
masterXfer.subaddressSize = 1;
masterXfer.data = rxBuff;
masterXfer.dataSize = rxSize;
masterXfer.flags = kI2C_TransferDefaultFlag;
/* direction=write : start+device_write;cmdbuff;xBuff; */
/* direction=recive : start+device_write;cmdbuff;repeatStart+device_read;xBuff; */
I2C_MasterTransferNonBlocking(BOARD_ACCEL_I2C_BASEADDR, &g_m_handle, &masterXfer);
/* wait for transfer completed. */
while ((!nakFlag) && (!completionFlag))
{
}
nakFlag = false;
if (completionFlag == true)
{
completionFlag = false;
return true;
}
else
{
return false;
}
}
the read sequence of my slave device:

IMG_1048.JPG

Labels (1)
0 Kudos
3 Replies

433 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi,

your code is exactly same as the demo. I think it should be ok if you send 1 to rxSize. Do you have an oscilloscope to observe the waveform?

Regards,

Jing 

0 Kudos

433 Views
李珍珍
Contributor I

the trouble is i have no  oscilloscope now,so i don't know where the problem is.the problem confused me is i used the read function in the demo code,but it cannot work,so i just want to know,can the demo code work correctly,or if i need do some work when use the demo code?

thanks 

0 Kudos

433 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi,

Yes of course, you can try the demo code.

Regards,

Jing

0 Kudos