在FPGA上使用AT24C08,结果发现识别不到,在树莓派上测试一下情况。
在raspi-config命令中打开I2C功能就行了,树莓派Linux系统会利用设备树Overlays将I2C引脚进行复用选择,注意需要重启;
- 扫描地址:这里不知道为何8个地址都会被扫描到
pi@raspberrypi:~ $ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: 50 51 52 53 54 55 56 57 -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- - 读一个字节:
pi@raspberrypi:~ $ i2cget -h Error: Unsupported option "-h"! Usage: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]] I2CBUS is an integer or an I2C bus name ADDRESS is an integer (0x03 - 0x77) MODE is one of: b (read byte data, default) w (read word data) c (write byte/read byte) Append p for SMBus PEC pi@raspberrypi:~ $ i2cget -f -y 1 0x50 0x00 b 0xff - 写一个字节:
pi@raspberrypi:~ $ i2cset -h Error: Unsupported option "-h"! Usage: i2cset [-f] [-y] [-m MASK] [-r] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE] I2CBUS is an integer or an I2C bus name ADDRESS is an integer (0x03 - 0x77) MODE is one of: c (byte, no value) b (byte data, default) w (word data) i (I2C block data) s (SMBus block data) Append p for SMBus PEC pi@raspberrypi:~ $ i2cset -f -y 1 0x50 0x00 0x0F b - 重新读取:
pi@raspberrypi:~ $ i2cget -f -y 1 0x50 0x00 b 0x0f - 查看其他地址,结果获取的
0x50地址结果一样,说明芯片内部使用的是屏蔽位进行译码:pi@raspberrypi:~ $ i2cget -f -y 1 0x51 0x00 b 0x0f pi@raspberrypi:~ $ i2cget -f -y 1 0x52 0x00 b 0x0f pi@raspberrypi:~ $ i2cget -f -y 1 0x53 0x00 b 0x0f pi@raspberrypi:~ $ i2cget -f -y 1 0x54 0x00 b 0x0f pi@raspberrypi:~ $ i2cget -f -y 1 0x55 0x00 b 0x0f pi@raspberrypi:~ $ i2cget -f -y 1 0x56 0x00 b 0x0f pi@raspberrypi:~ $ i2cget -f -y 1 0x57 0x00 b 0x0f pi@raspberrypi:~ $ - 修改0地址值位
0x0E,确认推论:pi@raspberrypi:~ $ i2cset -f -y 1 0x50 0x00 0x0E b pi@raspberrypi:~ $ i2cget -f -y 1 0x57 0x00 b 0x0e
- 扫描地址:
pi@raspberrypi:~ $ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: 50 51 52 53 -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- - 读写地址空间:
pi@raspberrypi:~ $ i2cset -f -y 1 0x50 0x00 0x0E b pi@raspberrypi:~ $ i2cget -f -y 1 0x50 0x00 b 0x0e pi@raspberrypi:~ $ i2cget -f -y 1 0x51 0x00 b 0xff pi@raspberrypi:~ $ i2cset -f -y 1 0x51 0x00 0x0F b pi@raspberrypi:~ $ i2cget -f -y 1 0x51 0x00 b 0x0f pi@raspberrypi:~ $ i2cget -f -y 1 0x50 0x00 b 0x0e