I have an application that I have cross-compiled for the USRP N310 that uses the TCA9548 I²C switch to read and write data to and from the TCA6408 I/O Expander on the daughterboard using the built-in Linux I2C driver. To do this, I've been following the tutorial Implementing I2C drivers in UserSpace. I've been able to test out this functionality successfully using the ZC706 embedded platform,however, I'm having issues reading data on the USRP platform. My code is the following
#include "i2c_dev.hpp"
int main()
{
int i2cfd;
__s32 num;
//Opening i2c adapter 6
printf("Opening bus adapter\n");
i2cfd = open("/dev/i2c-6", O_RDWR);
if ( i2cfd <0 )
{
printf("Failed to open /dev/i2c-6: %s\n",strerror( errno ));
return (1);
}
//Instatiating three objects of IO_Expander class
IO_Expander dba;
//Reading data from the IO Expander
printf("Setting slave address of device\n");
if (ioctl(i2cfd, I2C_SLAVE, 0x20) < 0) {
printf("Error setting slave address:%s\n",strerror(errno));
return(1);
}
printf("Reading data from the IO Expander for DB-A Object\n");
num =dba.read_data(i2cfd, 0x00);
if (num<0){
printf("Error reading data: %s\n",strerror(errno));
}
else {
printf("The input value is %d: \n", num);
}
printf("Leaving DB-A Object \n\n\n");
//Closing the adapter
close(i2cfd);
}
The printout I receive when running this application is a string error No such device or address
when trying to read data from the I/O Expander. The slave address of the device is the 7 bit address of 010 0000 or hex 20 and the address of the input register is 0x00 according to the data sheet. At the moment, I'm unclear as to what's going wrong. I'm a bit of a newbie so I'm unsure of what to try next.