linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Fechner <idefix@fechner.net>
To: linuxppc-embedded@ozlabs.org
Subject: Re: Howto read I2C on MPC5200 Lite
Date: Sun, 11 Mar 2007 01:55:35 +0100	[thread overview]
Message-ID: <20070311005535.GA39488@server.idefix.lan> (raw)
In-Reply-To: <20070309234251.GA68997@server.idefix.lan>

[-- Attachment #1: Type: text/plain, Size: 636 bytes --]

Hi,

* Matthias Fechner <idefix@fechner.net> [10-03-07 00:42]:
> It seems now that everything works fine. I will check it for the next
> days. And will give some feedback.

ok, I checked now the driver some time at it failed. So it seems that
that the patch had not solved the problem.

I have attached the programm to check it.

I changed the time to 2 seconds but that didn't help.

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

[-- Attachment #2: readMax6633.c --]
[-- Type: text/x-csrc, Size: 2176 bytes --]

/* read the data from max6633 */

#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "i2c-dev.h"
#include "version.h"

static __inline__ unsigned short swap_bytes(unsigned short val)
{
   return(val >> 8) | (val << 8);
}

int main(void)
{
   int res,address,file;
   char filename[20];
   unsigned short temp;
   long funcs;
   int i2cbus;
   int errorCount,successfullCount;
   errorCount=successfullCount=0;
   i2cbus=1;
   address=0x40;
   
   sprintf(filename,"/dev/i2c-%d",i2cbus);
   if((file=open(filename,O_RDWR))<0)
   {
      fprintf(stderr,"Error: could not open file %s: %s\n",filename,strerror(errno));
      exit(1);
   }
   
   /* check adapter functionality */
   if(ioctl(file,I2C_FUNCS,&funcs) < 0)
   {
      fprintf(stderr, "Error: could not get the adapter functionality matrix: %s\n",strerror(errno));
      goto ERROR0;
   }
   if(!(funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA))
   {
      fprintf(stderr,"Error: Adapter for i2cbus %d",i2cbus);
      fprintf(stderr," does not have byte read capability\n");
      goto ERROR0;
   }
   if(!(funcs & I2C_FUNC_SMBUS_READ_WORD_DATA))
   {
      fprintf(stderr,"Error: Adapter for i2cbus %d",i2cbus);
      fprintf(stderr," does not have word read capability\n");
      goto ERROR0;
   }
      
   
   /* use FORCE so that we can look at registers even when a driver
      is also running */
   if(ioctl(file,I2C_SLAVE,address) <0)
   {
      fprintf(stderr,"Error: Could not set address to %d: %s\n",address, strerror(errno));
      goto ERROR0;
   }
   
   fprintf(stderr,"Read with word_data\n");
   while(1)
   {
      
      temp=res=i2c_smbus_read_word_data(file,0);
      if(res<0)
      {
	 fprintf(stderr,"Error: Could not read the value from the i2c device\n");
	 errorCount++;
      }else
      {
	 successfullCount++;
      }
      
      temp=swap_bytes(temp);
      temp=temp >> 3;
      
      printf("Succes: %i, Errorcount: %i, Temp: %f\n",successfullCount,errorCount,(float)(temp*0.0625));
      sleep(1);
   }
   
   printf("\nCalculate temp\n");
  
   close(file);
   exit(0);

  ERROR0:
   close(file);
   exit(1);
}


  parent reply	other threads:[~2007-03-11  0:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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         ` Matthias Fechner [this message]
2007-03-15  9:57           ` Howto read I2C on MPC5200 Lite 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=20070311005535.GA39488@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 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).