Hello,
I am working on the i.MX RT1040 EVK using LPI2C3 to interface with an accelerometer (slave address = 0x18 base).
My goal is to read the WHO_AM_I register (address = 0x13) to check if the accelerometer is responding.
Steps I am following:
Call LPI2C_MasterStart() with slave address 0x18 and write intent.
Wait until TX FIFO count = 0 using LPI2C_MasterGetFifoCounts() to ensure TX FIFO is empty.
Check for acknowledge from the slave — ACK is received.
Send the WHO_AM_I register address (0x13) using LPI2C_MasterSend().
Check ACK again — slave sends ACK.
Problem:
After sending the register address, TX FIFO count = 1 (not empty), meaning the transaction/byte is not being sent on the bus.
FIFO error flag is set in LPI2C_MasterGetStatusFlags().
No data transfer happens after that.
status = LPI2C_MasterStart(EXAMPLE_I2C_MASTER, 0x18, kLPI2C_Write);
if (status == kStatus_Success) {
LPI2C_MasterGetFifoCounts(EXAMPLE_I2C_MASTER, NULL, &txCount);
while (txCount) {
LPI2C_MasterGetFifoCounts(EXAMPLE_I2C_MASTER, NULL, &txCount);
}
if (LPI2C_MasterGetStatusFlags(EXAMPLE_I2C_MASTER) & kLPI2C_MasterNackDetectFlag) {
return kStatus_LPI2C_Nak;
}
uint8_t regAddr = 0x13;
reVal = LPI2C_MasterSend(EXAMPLE_I2C_MASTER, ®Addr, 1);
if (reVal != kStatus_Success) {
return -1;
}
LPI2C_MasterGetFifoCounts(EXAMPLE_I2C_MASTER, NULL, &txCount);
printf("TX FIFO Count: %d\r\n", txCount);
uint32_t flags = LPI2C_MasterGetStatusFlags(EXAMPLE_I2C_MASTER);
printf("Status = 0x%08X\r\n", flags);
}
Question:
Why is the FIFO error flag set, and why does TX FIFO count remain 1 after LPI2C_MasterSend()?
Is there any specific configuration needed for LPI2C3 TX FIFO flush or clock settings before sending register data?
Additional Info:
Using default LPI2C driver from MCUXpresso SDK.
LPI2C3 clock and pin mux are already configured.
Slave ACK is received correctly during START condition.
Using polling mode (not interrupt/DMA).
Thanks in advance!