All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthias Fechner <idefix@fechner.net>
To: linuxppc-embedded@ozlabs.org
Subject: Howto read I2C on MPC5200 Lite
Date: Wed, 7 Mar 2007 13:24:30 +0100	[thread overview]
Message-ID: <20070307122430.GA73298@server.idefix.lan> (raw)

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

             reply	other threads:[~2007-03-07 12:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-07 12:24 Matthias Fechner [this message]
2007-03-07 21:17 ` Howto read I2C on MPC5200 Lite 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070307122430.GA73298@server.idefix.lan \
    --to=idefix@fechner.net \
    --cc=linuxppc-embedded@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.