发新帖我要提问
12
返回列表
打印
[应用相关]

AMG8833的使用与stm32驱动代码

[复制链接]
楼主: xiaoqizi
手机看帖
扫描二维码
随时随地手机跟帖
21
xiaoqizi|  楼主 | 2021-6-4 14:58 | 只看该作者 回帖奖励 |倒序浏览
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;
        }
}


使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则