IC无法按官方GitHub页面上的建议工作
这是我的代码:
i2cdetect -y 1
显示
eeprom IC M24512 at 0x50
Python代码:
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)
终端输出: 写1 30 阅读1 30 阅读2 30 阅读3 30 写2 40 阅读1 40 阅读2 40 阅读3 40 写3 50 阅读1 50 阅读2 50 阅读3 50