cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_I2C_Mem_Write() is not setting the address Write bit

CGrov.1
Associate II

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?

1 REPLY 1
TDK
Guru

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".