4、AMG8833.c
#include "AMG8833.h"
void AMG8833_Init(void)
{
AMG8833_IIC_Init(); //IIC初始化
//enter normal mode
AMG_IIC_Write_1Byte(AMG88xx_ADR,AMG88xx_PCTL,AMG88xx_NORMAL_MODE);
//software reset
AMG_IIC_Write_1Byte(AMG88xx_ADR,AMG88xx_RST,AMG88xx_INITIAL_RESET);
//set to 10 FPS
AMG_IIC_Write_1Byte(AMG88xx_ADR,AMG88xx_FPSC,AMG88xx_FPS_10);
}
float signedMag12ToFloat(uint16_t val)
{
//take first 11 bits as absolute val
uint16_t absVal = (val & 0x7FF);
return (val & 0x800) ? 0 - (float)absVal : (float)absVal ;
}
float AMG88xx_ReadThermistor(void)
{
uint8_t raw[2];
uint16_t recast;
AMG_I2C_Read_nByte(AMG88xx_ADR,AMG88xx_TTHL, raw, 2);
recast = ((uint16_t)raw[1] << 8) | ((uint16_t)raw[0]);
return signedMag12ToFloat(recast) * AMG88xx_THERMISTOR_CONVERSION;
}
void amg88xx_readPixels(float *buf, uint8_t size)
{
uint16_t recast;
float converted;
uint8_t rawArray[128],i;
AMG_I2C_Read_nByte(AMG88xx_ADR,AMG88xx_PIXEL_OFFSET,rawArray,128);
for(i=0; i<size; i++)
{
uint8_t pos = i << 1;
recast = ((uint16_t)rawArray[pos + 1] << 8) | ((uint16_t)rawArray[pos]);
converted = signedMag12ToFloat(recast) * AMG88xx_PIXEL_TEMP_CONVERSION;
buf[i] = converted;
}
}
|