2
\$\begingroup\$

I have been trying to practise writing drivers using the I2C protocol and as a result, I have checked the drivers written for the BMP180 temperature sensor by Adafruit and written my own some time ago while making some changes and tinkering. The BMP180 is addressed by Adafruit, by using a 7-bit slave address "0x77". I have used this slave address to read and write in the same way i.e. To write to the device:

HAL_I2C_Master_Transmit(i2c, (BMP180_I2C_ADDR << 1), &data, 2, 1000);

where "data" will be the data I transmit. I have used HAL_I2C_Master_Receive to read from the device. The above method worked fine, where Master_Transmit and Master_Receive was used.

However, given the datasheet of the sensor on page 20, the read-address is "0xEF" and the write address is "0xEE". I had taken the device address as "0x77" for granted. However, now I cannot understand how one derives the "0x77" from "0xEE" or "0xEF". I am trying to replicate the drivers, using HAL_I2C_Mem_Read and HAL_I2C_Mem_Write.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

The device's I2C slave address is 0x77 - in binary, 0b01110111. In order to write to the device, you must send the slave address bit shifted left by one, with a WRITE bit (0). Therefore 0b01110111 becomes 0b11101110, which is 0xEE. To read from the device, you send the address bit shifted with a READ bit which is 1. 0b01110111 --> 0b11101111, which is 0xEF.

I will also refer you to this question which is close enough that I thought about voting this question a duplicate.

\$\endgroup\$
3
  • \$\begingroup\$ @suva23 You already shift the device address one bit left. Did you never contemplate on this expression? \$\endgroup\$ Commented Jul 11, 2023 at 5:55
  • \$\begingroup\$ @thebusybee From knowing the slave address is 0x77, ST specifies that the slave address must be shifted to the left by 1, irrespective, so I took this for granted. \$\endgroup\$
    – Suva23
    Commented Jul 11, 2023 at 9:10
  • 1
    \$\begingroup\$ @Suva23 Right. And what is the result of 0x77 << 1? And what is the reason to shift? See, I like to nudge you to read documentation and to understand what you do. ;-) Did you look into an I²C documentation? It is enlightening! \$\endgroup\$ Commented Jul 11, 2023 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.