All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: "Dajka Tamás" <tdajka-PYL80EbDKh9BDgjK7y7TUQ@public.gmane.org>
Cc: "linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: Help needed
Date: Mon, 8 Dec 2008 11:42:59 +0100	[thread overview]
Message-ID: <20081208114259.6ef784a6@hyperion.delvare> (raw)
In-Reply-To: <D6509B586112EA4B98E1AF0B4D58DF3016EA8A4E74-f5hAeJvXNqs9gvzQRsMqH0EOCMrvLtNR@public.gmane.org>

Hi Tamas,

On Thu, 27 Nov 2008 21:33:36 +0100, Dajka Tamás wrote:
> Hi all,
> 
> I’m trying to use a Texas Instruments TMP175 temprature sensor on an AT91RM9200 system ( i2c-gpio).
> 
> The code (part of it):
> 
> //global vars
> int i2c_handler;
> 
> int main( int argc, char *argv[] ) {
>     int i=0;
>     int value=0;
>     int adapter_nr;
>     int err;
>     int funcs;
>     char buf[8];
> 
>     //we don't have to initialize the I2C, since it's done by the driver
> 
>     //opening the device
>     printf("Opening /dev/i2c\n");
>     if ( ( err = ( i2c_handler = open("/dev/i2c-0",O_RDWR) ) ) < 0 ) {
>         printf("Error opening /dev/i2c-0! Exiting (%d - %s).\n",err,strerror(errno));
>         exit(1);
>     }
> 
>     // check for req funcs
>     printf("Getting available IOCTLs\n");
>     // get funcs list
>     if((err = ioctl(i2c_handler, I2C_FUNCS, &funcs) < 0)) {
>         printf( "Error eeprom_open: %s\n", strerror(err));
>         exit(1);
>     }
>     CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_READ_BYTE );
>     CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_WRITE_BYTE );
>     CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_READ_BYTE_DATA );
>     CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_WRITE_BYTE_DATA );
>     CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_READ_WORD_DATA );
>     CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_WRITE_WORD_DATA );
> 
>     printf("Setting slave addr to 0x79\n");
>     if ( ( err = ioctl(i2c_handler,I2C_SLAVE,0x79) ) < 0 ) {
>         printf("Error setting SLAVE address! Exiting (%d).\n",err);
>         exit(1);
>     }
> 
>     value = i2c_smbus_read_byte(i2c_handler);
>     if ( value < 0 )
>         fprintf( stderr, "Failed to read from I2C device: %m\n" );
> 
>     printf("Reading with read\n");
>     if ( read(i2c_handler,buf,1) != 1 ) {
>         printf("Error reading byte! (%s)\n",buf);
>     }
> 
>     printf("Reading with i2c_read\n");
>     if ( ( value = i2c_smbus_read_byte(i2c_handler)) < 0 ) {
>         printf("Error readiny byte! (%d)\n",value);
>     }
> 
>     printf("Trying direct write!\n");
>     buf[0] = 0;
> 
>     if ( write(i2c_handler,buf,1) != 1 ) {
>         printf("Error writing byte! (%s)\n",buf);
>         return -1;
>     }
> 
> The result:
> root@(none):/mnt/tmp175# ./tmp175
> Opening /dev/i2c
> Getting available IOCTLs
> Setting slave addr to 0x79
> Failed to read from I2C device: Operation not permitted
> Reading with read
> Error reading byte! (X†)
> Reading with i2c_read
> Error readiny byte! (-1)
> Trying direct write!
> Error writing byte! ()
> 
> The ’dmesg’ output, since debug messages are turned on:
> i2c-adapter i2c-0: ioctl, cmd=0x705, arg=0xbee5fde4
> i2c-adapter i2c-0: ioctl, cmd=0x703, arg=0x79
> i2c-adapter i2c-0: ioctl, cmd=0x720, arg=0xbee5fd74
> i2c-adapter i2c-0: master_xfer[0] R, addr=0x79, len=1
> i2c-adapter i2c-0: NAK from device addr 0x79 msg #0
> i2c-dev: i2c-0 reading 1 bytes.
> i2c-adapter i2c-0: master_xfer[0] R, addr=0x79, len=1
> i2c-adapter i2c-0: NAK from device addr 0x79 msg #0
> i2c-adapter i2c-0: ioctl, cmd=0x720, arg=0xbee5fd74
> i2c-adapter i2c-0: master_xfer[0] R, addr=0x79, len=1
> i2c-adapter i2c-0: NAK from device addr 0x79 msg #0
> i2c-dev: i2c-0 writing 1 bytes.
> i2c-adapter i2c-0: master_xfer[0] W, addr=0x79, len=1
> i2c-adapter i2c-0: NAK from device addr 0x79 msg #0
> 
> What’s wrong? Am I just lame, or it’s something with the device?

Double check the slave address. 0x79 isn't a valid address for the
TMP175 according to the datasheet. The highest possible address is 0x77.

-- 
Jean Delvare

  parent reply	other threads:[~2008-12-08 10:42 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-27 20:33 Help needed Dajka Tamás
     [not found] ` <D6509B586112EA4B98E1AF0B4D58DF3016EA8A4E74-f5hAeJvXNqs9gvzQRsMqH0EOCMrvLtNR@public.gmane.org>
2008-12-08 10:42   ` Jean Delvare [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-03-10 19:24 Help Needed Alex Mourtziapis
2015-03-10 21:02 ` Emil Velikov
2014-05-22 10:31 help needed Alexandru Vaduva
2014-05-22 12:19 ` Paul Eggleton
2014-05-22 12:26   ` Alexandru Vaduva
2014-05-22 12:34     ` Paul Eggleton
2014-05-22 12:38       ` Alexandru Vaduva
2014-05-22 12:43         ` Paul Eggleton
2014-05-22 13:00           ` Alexandru Vaduva
2014-05-22 13:14             ` Paul Eggleton
2014-05-22 13:24               ` Alexandru Vaduva
2014-05-22 14:05                 ` Burton, Ross
2014-05-22 14:29                   ` Burton, Ross
2014-05-22 19:06                     ` Alexandru Vaduva
2014-05-22 13:09         ` Burton, Ross
2014-01-18 17:34 Help Needed Madhusudhan Rao Sripalle
2014-01-18 22:16 ` Randy Dunlap
2014-01-19  3:08   ` Ryan Cunningham
2014-01-22 14:34 ` Madhusudhan Rao Sripalle
2014-01-22 14:55   ` Mark Knecht
2014-01-22 15:05     ` Madhusudhan Rao Sripalle
2014-01-22 15:08       ` Richard Weinberger
2014-01-22 15:09       ` Mark Knecht
2014-01-22 15:47         ` Madhusudhan Rao Sripalle
2014-01-22 17:41           ` Mark Knecht
2014-01-23 10:21             ` Madhusudhan Rao Sripalle
     [not found] <u2oea05c7011004130706jc7b4a043zd1969eedb92f5069@mail.gmail.com>
2010-04-13 14:17 ` Help needed Akhilesh Soni
2010-04-14  6:18   ` Jaroslav Kysela
2010-04-14  7:06   ` Clemens Ladisch
2005-05-04 11:06 Benjamin Jeeves
2005-05-04 12:26 ` Neil Horman
2005-05-04 12:35   ` Benjamin Jeeves
2005-05-05 13:18     ` Neil Horman
2005-05-04 12:35 ` Trond Myklebust
2005-05-04 12:39   ` Benjamin Jeeves
2003-11-13 15:06 Help Needed Harish Sabnani
2003-11-13 15:35 ` Jeffrey Laramie
2003-11-07 12:40 help needed Mikko Kallio
2003-11-07 12:55 ` Antony Stone
2003-11-07 13:08   ` Jesper Lund
2003-11-07 13:30     ` Antony Stone
2003-03-25  8:53 Help needed steven.mugassa
2003-03-26 12:11 ` Kim Jensen
2002-10-15 17:23 joerg.beyer-htSm2yLGOjU
     [not found] ` <200210151723.g9FHNgX26060-pb599fR3TxVkExQqqHjIK3sFFmKitW5W@public.gmane.org>
2002-10-16 10:58   ` Ruud Koendering
2002-10-15 16:28 Ruud Koendering
2002-05-19 18:27 dvv

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=20081208114259.6ef784a6@hyperion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=tdajka-PYL80EbDKh9BDgjK7y7TUQ@public.gmane.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.