Skip to main content
CGrov.1
Associate III
August 27, 2020
Question

HAL_I2C_Mem_Write() is not setting the address Write bit

  • August 27, 2020
  • 1 reply
  • 910 views

I am using the HAL library on a STM32L476RG and have been having trouble getting data out of a sensor. By looking at the signal with a scope I've noticed that the write bit of the device address is not being set when I try to write to the sensor's registers. I am able to read the device ID just fine. I have been going through the HAL_I2C_Mem_Write() function but nothing jumps out at me. I have used this library before with great results.

What could be causing this?

This topic has been closed for replies.

1 reply

TDK
August 27, 2020

I2C is pretty popular. Seems like if there was a catastrophic bug like that it would have been spotted.

Code clearly sets the write bit:

...
 /* Send slave address */
 hi2c->Instance->DR = I2C_7BIT_ADD_WRITE(DevAddress);
...
 
#define I2C_7BIT_ADD_WRITE(__ADDRESS__) ((uint8_t)((__ADDRESS__) & (uint8_t)(~I2C_OAR1_ADD0)))

Is it possible you're not looking at the right trace?

The bit should be low for write and high for read. Sure you're not just misinterpreting?

"If you feel a post has answered your question, please click ""Accept as Solution""."