2020-08-27 05:15 AM
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?
2020-08-27 06:13 AM
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?