I believe the EEPROM is working fine. I can read/write to it flawlessly using a PICAxe chip. I am pretty sure I have the Pi set up correctly as I can read from the EEPROM using the following Python code:
Code: Select all
import smbus
address = 0x50 # 24LC256 i2c bus address
i2cmsbyte = 0
i2clsbyte = 24 # Reads starting from EEPROM register 24
bus.write_byte(address,i2cmsbyte)
bus.write_byte(address,i2clsbyte)
eevalue1 = bus.read_byte(address)
eevalue2 = bus.read_byte(address)
eevalue = (eevalue2<<8) + eevalue1
print (eevalue)
I have tried using 0xA1 for writing the most significant address byte and 0x50 for the least significant byte and that bombs too. This is part of my confusion. In any case, the above code reads the value stored at register 24 perfectly.
To write, I started with the following:
Code: Select all
import smbus
address1 = 0xA0 # i2c bus address 0x50 and write bit = 0
address2 = 0x50 # i2c bus address only
i2cmsbyte = 0
i2clsbyte = 24 # Writes to EEPROM address 24
eevaluemsbyte = 1
eevaluelsbyte = 4 # word value = 260
bus.write_byte(address1,i2cmsbyte)
bus.write_byte(address2,i2clsbyte)
bus.write_byte(address2,eevaluelsbyte)
bus.write_byte(address2,eevaluemsbyte)
I have tried different SMBUS commands and have played with the addresses. Nothing works. I suspect that SMBUS won't accept an 8-bit i2c device address (0x50 doesn't bomb, 0xA1 bombs). If I'm right, how do I transmit the read/write bit?
I am about to punt! Any help would be greatly appreciated.