/**************************************************************************************************
* @fn HalSensorReadReg
*
* @brief This function implements the I2C protocol to read from a sensor. The sensor must
* be selected before this routine is called.
*
* @param addr - which register to read
* @param pBuf - pointer to buffer to place data
* @param nBytes - numbver of bytes to read
*
* @return TRUE if the required number of bytes are reveived
**************************************************************************************************/
bool HalSensorReadReg(uint8 addr, uint8 *pBuf, uint8 nBytes)
{
uint8 i = 0;
/* Send address we're reading from */
if (HalI2CWrite(1,&addr) == 1)
{
/* Now read data */
i = HalI2CRead(nBytes,pBuf);
}
return i == nBytes;
}
第一张图是eeprom的读操作,然后上面的代码是TI 协议栈里的sensor的. 然后我看了下代码,里面的i2c时序和eeprom里datesheet的时序不一样。
TI显示的i2c时序是:
START -> device_write->write_byte_address->STOP START -> device_read ->data_out -> NACK -> STOP eeprom 的datesheet显示的i2c时序是: START -> device_write->write_byte_address->write_byte_address-> START -> device_read ->data_out -> NACK -> STOP 2者的区别就是在read操作时,先要写一个byte地址(从哪开始读),TI是写完byte地址后STOP然后重新START 而eeprom datesheet里显示的是写完byte地址后,没有STOP,直接重新START.
so i think it should be START .... START ..... STOP but it's START........STOP.......START.......STOP. 所以希望有能人异士给我解答下,应该如果下手。
|