Open niraj-2112 opened 6 years ago
It looks like maybe the write_i2c_block_data method is truncating the first value in the array, try sending them separately:
bus.write_i2c_block_data(80, 0, [0x00, 0x01, 30])
bus.write_i2c_block_data(80, 0, [0x00, 0x01])
bus.read_byte(80)
i2cdetect -y 1 shows eeprom IC M24512 at 0x50
python code:
import smbus import time
bus = smbus.SMBus(1)
time.sleep(0.5) print 'write 1 30' bus.write_i2c_block_data(80, 0, [0x0001, 30]) time.sleep(0.5) bus.write_i2c_block_data(80, 0, [0x0001]) time.sleep(0.5) print 'read 1 ', bus.read_byte(80) time.sleep(0.5) bus.write_i2c_block_data(80, 0, [0x0002]) time.sleep(0.5) print 'read 2 ', bus.read_byte(80) time.sleep(0.5) bus.write_i2c_block_data(80, 0, [0x0003]) time.sleep(0.5) print 'read 3 ', bus.read_byte(80) time.sleep(0.5)
time.sleep(0.5) print 'write 2 40' bus.write_i2c_block_data(80, 0, [0x0002, 40]) time.sleep(0.5) bus.write_i2c_block_data(80, 0, [0x0001]) time.sleep(0.5) print 'read 1 ', bus.read_byte(80) time.sleep(0.5) bus.write_i2c_block_data(80, 0, [0x0002]) time.sleep(0.5) print 'read 2 ', bus.read_byte(80) time.sleep(0.5) bus.write_i2c_block_data(80, 0, [0x0003]) time.sleep(0.5) print 'read 3 ', bus.read_byte(80) time.sleep(0.5)
time.sleep(0.5) print 'write 3 50' bus.write_i2c_block_data(80, 0, [0x0003, 50]) time.sleep(0.5) bus.write_i2c_block_data(80, 0, [0x0001]) time.sleep(0.5) print 'read 1 ', bus.read_byte(80) time.sleep(0.5) bus.write_i2c_block_data(80, 0, [0x0002]) time.sleep(0.5) print 'read 2 ', bus.read_byte(80) time.sleep(0.5) bus.write_i2c_block_data(80, 0, [0x0003]) time.sleep(0.5) print 'read 3 ', bus.read_byte(80) time.sleep(0.5)
Output: write 1 30 read 1 30 read 2 30 read 3 30 write 2 40 read 1 40 read 2 40 read 3 40 write 3 50 read 1 50 read 2 50 read 3 50