linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Howto read I2C on MPC5200 Lite
@ 2007-03-07 12:24 Matthias Fechner
  2007-03-07 21:17 ` John Rigby
  0 siblings, 1 reply; 19+ messages in thread
From: Matthias Fechner @ 2007-03-07 12:24 UTC (permalink / raw)
  To: linuxppc-embedded

Hi,

I started playing with I2C on my MPC5200 Lite board now.
For this a attached a MAX6633 to the I2C bus.
With u-boot I can read the chip so I think in hardware is everything ok.

Now I booted my board and loaded the module i2c-mpc and i2c-dev.
Create the devices with major number 89 and minor number 0 and 1.

I checked now for the kernel docu the file dev-interface.
They suggested to use i2c_smbus_read_word_data, but with this I was
not successfully.

So i tried to open the device and read with read from the device, but
no success.

Here is the final code i tried:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>

#include <linux/i2c.h>
#include <linux/i2c-dev.h>

int main(void)
{
   int file;
   int adapter_nr=0;
   char filename[20];
	    
   // open connection to device driver
   sprintf(filename,"/dev/i2c-%d",adapter_nr);
   if((file=open(filename,O_RDWR)) < 0)
   {
     printf("Cannot open i2c device\n");
     exit(1);
   }
	          
   // open connection to I2C device with address addr
   int addr=0x40;
   if(ioctl(file,I2C_SLAVE,addr) <0)
   {
     printf("Cannot access slave device\n");
     exit(1);
   }
	   
   // comunicate with the I2C device
   // device register to access
   __u8 memToRead = 0x0;
   __s32 res;
   char buf[10];
   if(read(file,buf,1) != 1)
   {
     printf("Cannot read from device\n");
   }else{
     printf("Got %s\n",buf[0]);
   }
   close(file);
   return 0;
}

But I always got Cannot read from device.

Can anyone help me here please?

Best regards,
Matthias

-- 

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the universe trying to
produce bigger and better idiots. So far, the universe is winning." --
Rich Cook

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2007-04-25 18:49 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-07 12:24 Howto read I2C on MPC5200 Lite Matthias Fechner
2007-03-07 21:17 ` John Rigby
2007-03-09 11:35   ` Matthias Fechner
2007-03-09 17:11     ` John Rigby
2007-03-09 23:42       ` Matthias Fechner
2007-03-10  2:18         ` where and how to get the latest 2.6 kernel Nick Droogh
2007-03-11  1:01           ` Matthias Fechner
2007-03-11  0:55         ` Howto read I2C on MPC5200 Lite Matthias Fechner
2007-03-15  9:57           ` Domen Puncer
2007-03-16  4:33             ` Matthias Fechner
2007-03-17  8:57             ` Matthias Fechner
2007-03-18 19:06               ` Charles Krinke
2007-03-18 19:11                 ` gdb question regarding step vs breakpoint Charles Krinke
2007-03-18 23:28                   ` Matthias Fechner
2007-03-19  0:14                 ` Howto read I2C on MPC5200 Lite Wolfgang Denk
2007-03-19  1:11                 ` A question regarding step and breakpoints Charles Krinke
2007-03-21  8:34               ` Howto read I2C on MPC5200 Lite Matthias Fechner
2007-04-04  8:49                 ` Domen Puncer
2007-04-25 18:48                   ` Matthias Fechner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).