Subject: RT1040 LPI2C3 – FIFO error while reading WHO_AM_I register from accelerometer

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

Subject: RT1040 LPI2C3 – FIFO error while reading WHO_AM_I register from accelerometer

389 Views
Harisha
Contributor I

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:

  1. Call LPI2C_MasterStart() with slave address 0x18 and write intent.

  2. Wait until TX FIFO count = 0 using LPI2C_MasterGetFifoCounts() to ensure TX FIFO is empty.

  3. Check for acknowledge from the slave — ACK is received.

  4. Send the WHO_AM_I register address (0x13) using LPI2C_MasterSend().

  5. 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, &regAddr, 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!

0 Kudos
Reply
2 Replies

357 Views
gusarambula
NXP TechSupport
NXP TechSupport

Hello  @Harisha 

Would you please share which accelerometer you are using?

Regards,
Gustavo

0 Kudos
Reply

338 Views
Harisha
Contributor I
i am using FXLS8974CFR3 triaxial accelerometer
0 Kudos
Reply