From: <fo...@it...> - 2007-07-02 16:19:32
|
Hi Michael, > I2C doesn't know about 16-bit things. > So how are you splitting your value and reassembling it? Thanks for pointing this out. Here is what I am now doing to split my value: // ***************************************************************** // < In i2c-Sensor-io.h typedef struct { uint8_t SensorIdx; ///< Index of the sensor to be read. uint8_t Sts; ///< Status of the Read command uint8_t distH; ///< High byte of distance value returned by the sensor. uint8_t distL; ///< Low byte of distance value returned by the sensor. } I2C_IO_TrgrPing_Snsr_t; #define I2C_IO_TRGR_PING_SNSR 0x21 // ***************************************************************** //< In I2C-Sensor-io-api.c int I2C_IO_Trgr_PING_Snsr( int i2cDev, uint8_t SensorIdx, uint16_t* range, uint8_t* status ) { uint8_t bytesRead = 0; I2C_IO_TrgrPing_Snsr_t trgrPing; trgrPing.SensorIdx = SensorIdx; if ( I2cProcessBlock( i2cDev, I2C_IO_TRGR_PING_SNSR, &SensorIdx, sizeof( SensorIdx ), &trgrPing, sizeof( trgrPing ), &bytesRead ) != 0 ) { LogError( "I2C_IO_Trgr_PING_Sensor: I2cProcessBlockFailed: %s (%d)\n", strerror( errno ), errno ); return FALSE; } *range = trgrPing.distH; *range = (*range << 8) + trgrPing.distL; *status = trgrPing.Sts; return TRUE; } // I2C_IO_Trgr_PING_Sensor // ***************************************************************** // < In I2C-Sensor.c (runs on the robostix). Part of my ProcessCommand() // function. case I2C_IO_TRGR_PING_SNSR: { uint8_t *snsrIdx = (uint8_t *)&packet->m_data[2]; PingStatus[*snsrIdx] = ReadPingSensor( *snsrIdx, Dist ); I2C_IO_TrgrPing_Snsr_t *trgr = (I2C_IO_TrgrPing_Snsr_t *)&packet->m_data[ 1 ]; // +1 for cmd, +1 for len trgr->SensorIdx = *snsrIdx; trgr->Sts = PingStatus[*snsrIdx]; trgr->distH = (( Dist[*snsrIdx] >> 8 ) & 0xFF ); trgr->distL = ( Dist[*snsrIdx] & 0xFF ); packet->m_data[ 0 ] = sizeof( *trgr ); return sizeof( *trgr ) + 1; // + 1 for len; } // ***************************************************************** Daniel |