public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* Help needed
@ 2008-11-27 20:33 Dajka Tamás
       [not found] ` <D6509B586112EA4B98E1AF0B4D58DF3016EA8A4E74-f5hAeJvXNqs9gvzQRsMqH0EOCMrvLtNR@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Dajka Tamás @ 2008-11-27 20:33 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

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?

Thanks,

                Tamas

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

end of thread, other threads:[~2008-12-08 10:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox