2021-10-21 07:29 PM
Hello! I'm trying to interface with a sensor that requires a repeated start condition.
Datasheet: https://www.mouser.com/datasheet/2/348/ROHM_S_A0005047448_1-2562246.pdf
I have other sensors on my I2C bus that I can communicate with.
I also get '1' on HAL_I2C_IsDeviceReady(&hi2c1, 0x5B, 3, 5);
I tried using HAL_I2C_Mem_Read, as it's my understanding that this function does a repeated start, but it doesn't seem to work with the sensor (this function works with 3 other sensors on my bus).
I'm assuming the implementation of HAL_I2C_Mem_Read doesn't meet my requirements.
The sensor I'm interfacing requires: [ST][SLAVE ADDR][W/0][ACK][READ REG][ACK][ST][SLAVE ADDR][R/1][ACK][DATA][NACK][SP]
What am I getting wrong here?
Using STM32WB, with CubeIDE.
Thank you!!! :)
Solved! Go to Solution.
2021-10-21 08:36 PM
> I also get '1' on HAL_I2C_IsDeviceReady(&hi2c1, 0x5B, 3, 5);
Getting 1 (HAL_ERROR) means the slave is not responding.
Devices usually specify their slave address as 7 bits, in which case it needs to be left shifted one bit when you send it to HAL_I2C_* functions. The remaining R/W bit gets populated automatically depending on the function type. Try:
HAL_I2C_IsDeviceReady(&hi2c1, 0x5B << 1, 3, 5);
2021-10-21 07:32 PM
To add to this, I don't believe anything is wrong with the HW in this case. I'm using the standard breakout board.
uint8_t count;
count= HAL_I2C_IsDeviceReady(&hi2c1, 0x5B, 3, 5);
HAL_I2C_Mem_Read(&hi2c1, 0x5B, 0x0F, 1, &count, 1, 1500);
And this is all I'm doing to try and read the device ID, which should return E0.
2021-10-21 08:36 PM
> I also get '1' on HAL_I2C_IsDeviceReady(&hi2c1, 0x5B, 3, 5);
Getting 1 (HAL_ERROR) means the slave is not responding.
Devices usually specify their slave address as 7 bits, in which case it needs to be left shifted one bit when you send it to HAL_I2C_* functions. The remaining R/W bit gets populated automatically depending on the function type. Try:
HAL_I2C_IsDeviceReady(&hi2c1, 0x5B << 1, 3, 5);
2021-10-22 04:43 AM
Huzzah! This worked.
Apparently I don't know how to properly address I2C... lol.
I must've missed in the datasheet that the address was only 7 bits.
2021-10-22 07:12 AM