Big thanks !!!!

It's working now :)

I try to read the result now with this : ( registre 2, size 16bits )
    uint8_t dataByte[ I2C_MAX_DATA_LEN ];
    int gByteCount=2;
    uint8_t addr=2;
    I2cReadBytes( i2cDev, addr, dataByte, gByteCount );

But I have to convert the result for hexa to dec with this :
    sprintf(str,"%x",dataByte[0]);
    distancecm=255*strtoul(str, NULL, 16);
    sprintf(str,"%x",dataByte[1]);
    distancecm=distancecm+strtoul(str, NULL, 16);
    printf("Distance en cm : %u \n",distancecm);

It's seem to be a bit stranger because the max value that i can found is 60cm. Have you got an other solution ??

Thank for your help !

2008/4/23 Dave Hylands <dhylands@gmail.com>:
Hi,

>  I have a problem with SRF08 sonar, I try to change the address of mine using
>  this code :
>
>  #define chgtaddresse1          0xA0
>  #define chgtaddresse2          0xAA
>  #define chgtaddresse3          0xA5
>  #define chgtaddresse4          0xF2
>
>         gI2cAddr = 0x74;
>
>
>         if (( i2cDev = open( i2cDevName, O_RDWR )) < 0 )
>         {
>                 LogError( "Error  opening '%s': %s\n", i2cDevName, strerror( errno ));
>                 exit( 1 );
>         }
>         I2cSetSlaveAddress( i2cDev, gI2cAddr, I2C_USE_CRC );

The SRF08 sonar device doesn't use CRC's. So pass I2C_NO_CRC instead.

>         I2cTransfer( i2cDev, chgtaddresse1, NULL, 0, NULL, 0, NULL );
>         close( i2cDev );

Why are you closing and reopening? Just leave the file descriptor open.

You're also sending the wrong data. The SRF08 datasheet says that you
need to send a 4 seperate commands to register 0. What you're doing is
sending no data to register A0 and then no data to register AA, etc.

So you should be doing something like:

I2cWriteByte( i2cDev, 0, 0xA0 );
I2cWriteByte( i2cDev, 0, 0xAA );
I2cWriteByte( i2cDev, 0, 0xA5 );
I2cWriteByte( i2cDev, 0, 0xF2 );

--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
gumstix-users mailing list
gumstix-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gumstix-users