简介
MLX90614是一款红外非接触温度计。由于集成了低噪声放大器、17位默数转化器和强大的数字信号处理单元,使得高精度和高分辨度的温度计得以实现。控制器可以通过SMBus总线协议与之通信,该通信协议与IIC通信协议近似。
1)读取数据
2)写入数据
代码
可以直接使用iic来读取数据,从时序图上可知其逻辑与IIC类似。iic总线驱动只需要随便拷贝一个就行。
1)SMBus写入数据
void MLX_Send_Byte(u8 txd)
{
IIC_Send_Byte(txd);
IIC_SCL=0;
delay_us(10);
IIC_SDA=1;
delay_us(10);
IIC_SCL=1;
delay_us(10);
IIC_SCL=0;
}
2)SMBus读取数据
u8 MLX_Read_Byte()
{
unsigned char i,receive=0;
SDA_IN();
for(i=0;i<8;i++ )
{
IIC_SCL=0;
delay_us(10);
IIC_SCL=1;
delay_us(10);
receive<<=1;
if(READ_SDA)receive++;
delay_us(10);
}
IIC_SCL=0;
delay_us(10);
IIC_SDA=0;
delay_us(10);
IIC_SCL=1;
delay_us(10);
IIC_SCL=0;
return receive;
}
3)获取温度数据
float GY_906ReadByte(){
u8 DataH,DataL,Pecreg;
u32 temp=0;
float tem=0.0;
IIC_Start();
MLX_Send_Byte(0XB4); //
MLX_Send_Byte(0x07); //
IIC_Start();
MLX_Send_Byte(0X01);
DataL=MLX_Read_Byte();
DataH=MLX_Read_Byte();
Pecreg=MLX_Read_Byte();
IIC_Stop();//
delay_us(10);
// printf("H:%x,L:%x\r\n",DataH,DataL);
temp=(DataH<<8)+DataL;
temp=(temp*2)-27315;
temp=temp+5;
tem=(((temp%10000)/1000)*10) + ((temp%1000)/100) + (((temp%100)/10)*0.1) + ((temp%10)*0.01);
return tem;
}