Skip to main content
Visitor II
August 25, 2023
Question

STM32fxx I2C mem read issue

  • August 25, 2023
  • 3 replies
  • 2320 views

I am trying to use the HAL driver - HAL_I2C_MEM_READ(....)

The stm32 is the master and there is a slave i2c device that I want to read from.  The I2C transaction goes like this: <start> <dev address> <register that I want to read address> <start> <dev address> <value sent from slave><stop>

Using an Aardvark I can read the register value and I have captured the I2C transaction.  I assume this verifies the hardware.  When I attempt to use the HAL driver I can see an I2C transfer start, but it fails.   The transaction is this: <start> <dev address> <register that I want to read address> <start> <dev address> At this point the ADDR bit is not set in the status register which indicates "No end of address transmission", but this makes no sense because I see the address being sent and the ACK from the slave.  The I2C controller flags AF (acknowledgement failure) next, but I see the pin go low on the 9th bit.   

Working (0xB0 0x03 0xB1 0xC5) 0xC5 is the expected value read from register 0x03: 

MBish1_0-1693003461005.png

Failure (0xB0 0x03 0xB1) :

MBish1_1-1693003626403.png

the last clock pulse is the ACK from the slave. And then HAL_I2C_MEM(...) returns HAL_ERROR and that is from the call I2C_RequestMemoryRead(..) which then calls and fails here:

MBish1_2-1693003982048.png

which then drops down to here where the AF bit is set in hardware:

MBish1_3-1693004047187.png

The hardware is telling me that there is an acknowledgement failure but the logic analyzer is telling there isn't.  Any advice?

I wanted to add I've also tried to use a HAL_I2C_Master_Transmit(...) followed by a HAL_I2C_Master_Receive(...) and that seems to fail in the same way.

    This topic has been closed for replies.

    3 replies

    Graduate II
    August 26, 2023

    Have you tried using another MCU (perhaps Arduino) to test the slave device?

    ST Employee
    August 28, 2023

    Hello @MBish.1 , 

    Could you please specify which STM32 board do you use for the I2C communication ?

    Foued

    MBish.1Author
    Visitor II
    August 28, 2023

    It is a custom board.

    ST Employee
    September 8, 2023

    Hello @MBish.1 , 

    Any updates?

    Foued