2020-03-10 09:25 AM
I have been struggling to get a simple I2C communication link working so that I can talk to my battery charger device. It's device address is 0x68. I have tried shifting this one bit the the left, not shifting the address. Nether works. Can someone shed some light on this statement in the HAL UM1905 User Manual?
DevAddress: Target device address: The device 7 bits
address value in datasheet must be shift at right before call
interface
2020-03-10 10:43 AM
Cube/HAL is open source. You may be better off finding where is it stored to the actual register.
JW
2020-03-10 12:10 PM
> * @param DevAddress Target device address The device 7 bits address value
> * in datasheet must be shifted to the left before calling the interface
It expects the slave address to be in the upper 7 bits, so shift it one bit to the right when you call HAL_I2C_* functions.
The HAL is documented pretty well without the source code. Perhaps look there first.
2020-03-10 12:21 PM
For the ST I2C driver, I2C addresses are 7 bit, but shifted 1 bit left.
Then you set bit 0 to 1 for write and 0 for read,
In your hardware documentation, the address may be specified as 7 bit without shift.
This form is common in Linux, for example.
So 0x68 may mean either 0x68/0x69, or 0xD0/0xD1. Try both variants.
ST library has a convenient function HAL_I2C_IsDeviceReady , it can be used to probe the addresses. Most decent devices should reply.
-- pa