关于在Linux下读取I2C数据。该程序主要是在树莓派中读取AMG8833传感器中的64个温度数据,借鉴了一些网上的方法,然后参考芯片的数据手册,数据的存储格式,本芯片是2个字节存放一个数据。
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#define I2C_ADDR 0x69
#define REG_ADDR 0X80 //寄存器地址
#define I2C_DEV"/dev/i2c-1"//i2c_dev为i2c adapter创建的别名
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
static int iic_read(int fd, char buff[],int addr, int count)
{
int res;
char sendbuffer1[2];
sendbuffer1[0]=addr>>8;
sendbuffer1[1]=addr;
write(fd,sendbuffer1,128);
res=read(fd,buff,count);
return res;
}
float signedMag