cancel
Showing results for 
Search instead for 
Did you mean: 

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

briankaz
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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 Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2
TDK
Guru

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".

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 Venmo
Up vote any posts that you find helpful, it shows what's working..