2010年12月23日 星期四

數位鬧鐘: (2) I2C實驗-溫度感應器,軟體DIY部分

NXP SA56004x data sheet中,
表1



表2
如表1,  分別讀回High Byte 與 Low Byte.
接著在return的時候將High/Low byte合併,參考表2. 回傳值是溫度值x10
不過這邊未考慮 "負"值.


uint32_t read_temp(void)
{
uint32_t tempH,tempL;

I2CWriteLength = 2;
I2CReadLength = 1;
I2CMasterBuffer[0] = NXP5600_I2C_WRITE;
I2CMasterBuffer[1] = NXP_5600_REG_LTHB;
I2CMasterBuffer[2] = NXP5600_I2C_READ;
I2CEngine();
tempH = I2CSlaveBuffer[0];

I2CWriteLength = 2;
I2CReadLength = 1;
I2CMasterBuffer[0] = NXP5600_I2C_WRITE;
I2CMasterBuffer[1] = NXP_5600_REG_ATLB;
I2CMasterBuffer[2] = NXP5600_I2C_READ;
I2CEngine();

tempL = I2CSlaveBuffer[0];

tempL = (tempL >> 5)*125;

return (tempH*10+tempL/100) ;

}

0 留言:

張貼留言

Related Posts Plugin for WordPress, Blogger...