我有一个Beaglebone,我正在尝试连接到中巴(提达-01454 )与I2C。据我所知,当我运行i2cdetect时,它确实检测到了引脚的正确连接:
debian@beaglebone:/sys/devices/virtual/thermal/thermal_zone0$ i2cdetect -r 3
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-3 using receive byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- 4a 4b -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --但是,当我尝试运行基于I2C开发-接口的C代码时
int main(void)
{
fd = open(I2C_DEVICE_FILE,O_RDWR);
/* first lets open the I2C device file */
if (fd < 0) {
perror("Failed to open I2C device file.\n");
return -1;
}
/* set the I2C slave address using ioctl I2C_SLAVE command */
if (ioctl(fd, I2C_SLAVE,U1_PCM1864_I2C_ADDR) < 0) {
perror("Failed to set I2C slave address.\n");
close(fd);
return -1;
}
PCM1864_init();
while(1) {};
}它崩溃时有以下错误:
Ccrawread.cdd/tmp/cloud9 9-示例/rawread.o ./rawread.out未能设置I2C从地址。*/var/lib/cloud9 9/公用/Makefile:172:启动错误255
所以,我想,在试图设置I2C从地址时,任何一个论点都是错误的。第一个“fd”是上面定义的,之前没有出现错误,“I2C_SLAVE”是来自内核I2C-Dev-Interface (我认为)的默认值,第三种是按照TIDA-01454设计指南这样定义的:
#define U1_PCM1864_I2C_ADDR 0x94那么问题是什么呢?
请不要犹豫,问我更多的信息或代码的一部分,以帮助。
发布于 2021-11-19 13:19:35
I2C地址有7位,从0到127小数点(0x00到0x7F十六进制)。
您已经将I2C地址设置为0x94,这不是一个有效的I2C地址。
您可能有错误读取数据表和0x94是7位地址连同1位R/nW位。将其转换为7位地址除以2: 0x4A。
https://stackoverflow.com/questions/70033500
复制相似问题