OpenQNX :: The QNX Community Portal

May 13, 2008 - 10:20 AM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 56 unlogged users and 0 registered users online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
gagan
Post subject: I2C Driver.  PostPosted: 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
 
 View user's profile Send private message  
Reply with quote Back to top
maschoen
Post subject: RE: I2C Driver.  PostPosted: 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?
 
 View user's profile Send private message Send e-mail Visit poster's website  
Reply with quote Back to top
gagan
Post subject: I2C Driver  PostPosted: 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
 
 View user's profile Send private message  
Reply with quote Back to top
kingraja84
Post subject: RE: I2C Driver  PostPosted: 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
 
 View user's profile Send private message  
Reply with quote Back to top
ed1k
Post subject: Re: RE: I2C Driver  PostPosted: Feb 09, 2008 - 12:04 AM
QNX Master


Joined: Jul 23, 2002
Posts: 94

kingraja84 wrote:

_________________
Driving Tommorows Technology

How true...
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.