Hello Everbody,
Currently i am working on I2C driver , and to check wether my driver is working as i have designed it I have to write an application which i am finding it little hard as for that i have to use Devctl command which my driver supports , the following posted application code i am using but every time i compile this it says invalid argument ( in send section ) and same for receive ( recv ) …
int main()
{
int file;
int add = 0x90; /* The I2C address */
char buf[40] = {0};
char buf1[50]={0};
char buf2[50]={0};
char buf3[90];
int error;
int speed =100000;
i2c_send_t send;
i2c_recv_t recv;
i2c_send_t send1;
i2c_addr_t address;
send.slave.addr = 0x90;
send.slave.fmt = 2;
send.len = 1;
send.stop = 1;
send1.slave.addr = 0x0;
send1.slave.fmt = 2;
send1.len = 1;
send1.stop =1;
recv.slave.addr = 90;
recv.slave.fmt = 002;
recv.len = 2;
recv.stop = 1;
address.addr = add;
address.fmt=2;
if ((file = open("/dev/i2c0",O_RDWR)) < 0)
{
/* ERROR HANDLING; you can check errno to see what went wrong */
printf("Error Occured while opening Device File.!!\n");
}
else
{
printf("Device File Opened Successfully !!\n");
}
if (error = devctl(file,DCMD_I2C_SET_BUS_SPEED,&(speed),sizeof(speed),NULL))
{
/* ERROR HANDLING; you can check errno to see what went wrong */
fprintf(stderr, "Error setting the bus speed: %s\n",strerror ( error ));
exit(EXIT_FAILURE);
}
if (error = devctl(file,DCMD_I2C_SET_SLAVE_ADDR,&address,sizeof(address),NULL))
{
/* ERROR HANDLING; you can check errno to see what went wrong */
fprintf(stderr, "Error setting the slave address: %s\n",strerror ( error ));
exit(EXIT_FAILURE);
}
if (error = devctl(file,DCMD_I2C_SEND,&send,sizeof(send),NULL))
{
/* ERROR HANDLING; you can check errno to see what went wrong */
fprintf(stderr, "Error in sending the data 0: %s\n",strerror ( error ));
exit(EXIT_FAILURE);
}
if (error = devctl(file,DCMD_I2C_SEND,&send1,sizeof(send1),NULL))
{
/* ERROR HANDLING; you can check errno to see what went wrong */
fprintf(stderr, "Error in sending the data 1: %s\n",strerror ( error ));
exit(EXIT_FAILURE);
}
if (error =devctl(file,DCMD_I2C_RECV,&buf2,sizeof(buf2),NULL))
{
/* ERROR HANDLING; you can check errno to see what went wrong */
fprintf(stderr, "Error in receiving the data: %s\n",strerror ( error ));
exit(EXIT_FAILURE);
}
else
{
read(file,buf3,40);
puts(buf3);
printf(" the received temperature %x", buf2[0]);
}
if (error =devctl(file,DCMD_I2C_DRIVER_INFO,&buf,sizeof(buf),NULL))
{
/* ERROR HANDLING; you can check errno to see what went wrong */
fprintf(stderr, "Error in getting driver info data: %s\n",strerror ( error ));
exit(EXIT_FAILURE);
}
else
{
printf(" i2c version: buf[0] = %d\n",buf[0]);
printf(" i2c address mode :buf[1] = %d\n", buf[1]);
}
printf("Successfull !!\n");
close(file);
return 0;
}
Please reply any help would be appreciated
Thanks
Regards