Skip to main content
briankaz
Associate III
July 24, 2021
Solved

How to write/read to/from EEPROM via I2C if the peripheral address is 7 bits + one eighth bit for R/W?

  • July 24, 2021
  • 2 replies
  • 1289 views

I have to write code to write/read to/from an ATMEL 24C256 EEPROM which has a 7-bit address and the eighth bit is for R/W. I guess the MCU should be configured for 7-bit addressing (ADD10 = 0) but in this case how does the MCU write the eighth (R/W) bit?

This topic has been closed for replies.
Best answer by Tesla DeLorean

The STM32 expects the slave address in the upper 7-bit. You might need to use (slaveaddr << 1)

Check the bit patterns in your I2C data sheet. 0110000 would be (0x30 << 1)

The low order read/write bit is set by the I2C peripheral of the STM32 based on direction of transaction

2 replies

TDK
Super User
July 24, 2021

That's how I2C normally works. The first byte sent out is comprised of the 7-bit address plus the R/W bit. In HAL, the R/W bit is automatically set based on if the function reads or writes to I2C.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
July 25, 2021

The STM32 expects the slave address in the upper 7-bit. You might need to use (slaveaddr << 1)

Check the bit patterns in your I2C data sheet. 0110000 would be (0x30 << 1)

The low order read/write bit is set by the I2C peripheral of the STM32 based on direction of transaction

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..