 |
|
 |
| Author |
Message |
|
|
Post subject: I2C Driver.
Posted: Sep 25, 2007 - 05:15 AM
|
|
New Member
Joined: Jun 19, 2007
Posts: 7
|
|
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 |
|
|
| |
|
|
|
 |
|
|
Post subject: RE: I2C Driver.
Posted: Sep 25, 2007 - 06:16 AM
|
|
QNX Master
Joined: Jun 25, 2003
Posts: 974
|
|
| Can you be a little more specific about where the error occurs? |
|
|
| |
|
|
|
 |
|
|
Post subject: I2C Driver
Posted: Sep 25, 2007 - 10:45 AM
|
|
New Member
Joined: Jun 19, 2007
Posts: 7
|
|
In the send ( where some data is passed using I2C_SEND) its gives an error saying invalid arguement and same is for thye receive when i use command I2C_RECV , and for setting the slave address and setting up the bus speed .by using their respective coomand , its actually gets nothing done on the respective registers of the board means when SET_SLAVE_ADDRESS gets executed it should put some contents in its respective register but it will not
so there are two things thats come in to my mind
1. either i am not using these devctl properly as they should be .
2. or there is some linking problem of devctl commands with the driver ..
actually how will devctl will call these functions ( written by me ) is i am not getting .
Hoping for a good reply
Regards |
|
|
| |
|
|
|
 |
|
|
Post subject: RE: I2C Driver
Posted: Feb 07, 2008 - 03:08 PM
|
|
New Member
Joined: Aug 09, 2007
Posts: 7
|
|
I am new to developing resource manager,I have gr8 interset in learning them can you post your resource manager for this I2C serial communication, how you mapped open,read,write for file operations in resource manager.
gagan if you can help me i will be very happy. |
_________________ Driving Tommorows Technology
|
| |
|
|
|
 |
|
|
Post subject: Re: RE: I2C Driver
Posted: Feb 09, 2008 - 12:04 AM
|
|
QNX Master
Joined: Jul 23, 2002
Posts: 94
|
|
|
kingraja84 wrote:
_________________
Driving Tommorows Technology
How true... |
|
|
| |
|
|
|
 |
|
|
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group Credits |
|
|
|
 |