2021-12-14 09:00 PM
I have a problem of the HAL Driver function HAL_I2C_Master_Transmit's parameter 'DevAddress'. It says that the device 7 bits address value in datasheet must be shifted to the left before calling the interface, that is, if I want to transmit to a device addressed 0x60, the parameter should be 0xc0. And that's exactly what happened. But when I use the function HAL_I2C_Mem_Read, which has same require, the parameter was 0x60, the 0xc0 was wrong.
MCU: STM32F407ZGT6
CubeMX Firmware Package: V1.26.2
I'am confused now. Please help me.:sad_but_relieved_face:
Solved! Go to Solution.
2021-12-14 09:44 PM
Don't understand what exactly caused you confusion, maybe showing a minimal code example would help.
All I2C API functions behave the same.
Let's take the MPU-9250 as example. The 7-bit I2C slave address in the datasheet is 0x68. You define in your code
#define IMU_I2C_SLAVE_ADDR (0x68 << 1)
and use that macro in your code. Debug step into the HAL source code to see what happens. Finally, you find a line
hi2c->Instance->DR = I2C_7BIT_ADD_WRITE(DevAddress);
Moreover, check all HAL return codes to find errors as soon as possible.
hth
KnarfB
2021-12-14 09:44 PM
Don't understand what exactly caused you confusion, maybe showing a minimal code example would help.
All I2C API functions behave the same.
Let's take the MPU-9250 as example. The 7-bit I2C slave address in the datasheet is 0x68. You define in your code
#define IMU_I2C_SLAVE_ADDR (0x68 << 1)
and use that macro in your code. Debug step into the HAL source code to see what happens. Finally, you find a line
hi2c->Instance->DR = I2C_7BIT_ADD_WRITE(DevAddress);
Moreover, check all HAL return codes to find errors as soon as possible.
hth
KnarfB
2021-12-14 10:45 PM
Build a handy sw tool that scan all slave addresses and stops when one is acknowledged, and put a breakpoint. You will get the idea and the answer to your question very fast.
2021-12-17 12:42 AM
Thank you. I had resolved this question as your reply.