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
prev parent reply other threads:[~2008-12-08 10:42 UTC|newest]
Thread overview: 2+ 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]
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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox