I have a Beaglebone AI, and I am trying to connect it to the CMB (TIDA-01454 ) with I2C. As far as I know, I have connected the pins correctly since when I run i2cdetect it does detect it:
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: -- -- -- -- -- -- -- --
However when I try to run a C code based on the I2C Dev-Interface:
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) {};
}
It crashes with the following error:
CC rawread.c LD /tmp/cloud9-examples/rawread.o ./rawread.out Failed to set I2C slave address. : Invalid argument make: *** [/var/lib/cloud9/common/Makefile:172: start] Error 255
So I guess any of the arguments it is wrong when trying to set the I2C Slave Address. The first one “fd” is defined above and gives no error before, the “I2C_SLAVE” is default from Kernel I2C-Dev-Interface (I think), and the third one is defined this way according to TIDA-01454 design guide:
#define U1_PCM1864_I2C_ADDR 0x94
So what can be the problem?
Don’t hesitate in asking me more information or parts of the code in order to help.
I2C addresses have 7 bits, they are from 0 to 127 decimal (0x00 to 0x7F hex).
You have set the I2C address to 0x94, this is not a valid I2C address.
Probably you have mis-read the datasheet and 0x94 is the 7-bit address together with the 1-bit R/nW bit. To convert this to just the 7-bit address divide by two: 0x4A.