2023-08-25 03:57 PM - edited 2023-08-25 04:04 PM
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:
Failure (0xB0 0x03 0xB1) :
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:
which then drops down to here where the AF bit is set in hardware:
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.
2023-08-25 06:00 PM
Have you tried using another MCU (perhaps Arduino) to test the slave device?
2023-08-28 02:22 AM
Hello @MBish.1 ,
Could you please specify which STM32 board do you use for the I2C communication ?
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-08-28 06:10 AM
It is a custom board.
2023-08-28 09:40 AM
It is a stm32f405 processor.
2023-08-29 02:18 AM
Try to enable the interrupt and use HAL_I2C_MEM_READ_IT() ;
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-09-08 06:48 AM
Hello @MBish.1 ,
Any updates?
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.