先看实验现象

MLX90614 简介(资料来自商家文档)

MLX90614 存储器

RAM

测试所需硬件
MCU一块(主脑)
GY-906

OLED(0.96)

软件部分
mlx90614.c(代码来自网络)

/* Includes ------------------------------------------------------------------*/#include "mlx90614.h"/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define ACK  0 //应答
#define NACK 1 //无应答
#define SA              0x00 //Slave address 单个MLX90614时地址为0x00,多个时地址默认为0x5a
#define RAM_ACCESS      0x00 //RAM access command RAM存取命令
#define EEPROM_ACCESS   0x20 //EEPROM access command EEPROM存取命令
#define RAM_TOBJ1       0x07 //To1 address in the eeprom 目标1温度,检测到的红外温度 -70.01 ~ 382.19度#define SMBUS_PORT  GPIOA      //PB端口(端口和下面的两个针脚可自定义)
#define SMBUS_SCK       GPIO_Pin_5 //PB6:SCL
#define SMBUS_SDA       GPIO_Pin_4 //PB7:SDA#define RCC_APB2Periph_SMBUS_PORT        RCC_APB2Periph_GPIOB#define SMBUS_SCK_H()       SMBUS_PORT->BSRR = SMBUS_SCK //置高电平
#define SMBUS_SCK_L()       SMBUS_PORT->BRR = SMBUS_SCK  //置低电平
#define SMBUS_SDA_H()       SMBUS_PORT->BSRR = SMBUS_SDA
#define SMBUS_SDA_L()       SMBUS_PORT->BRR = SMBUS_SDA#define SMBUS_SDA_PIN()      SMBUS_PORT->IDR & SMBUS_SDA //读取引脚电平/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*//*******************************************************************************
* Function Name  : SMBus_StartBit
* Description    : Generate START condition on SMBus
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void SMBus_StartBit(void)
{SMBUS_SDA_H();     // Set SDA lineSMBus_Delay(5);      // Wait a few microsecondsSMBUS_SCK_H();        // Set SCL lineSMBus_Delay(5);      // Generate bus free time between StopSMBUS_SDA_L();        // Clear SDA lineSMBus_Delay(5);        // Hold time after (Repeated) Start// Condition. After this period, the first clock is generated.//(Thd:sta=4.0us min)在SCK=1时,检测到SDA由1到0表示通信开始(下降沿)SMBUS_SCK_L();        // Clear SCL lineSMBus_Delay(5);        // Wait a few microseconds
}/*******************************************************************************
* Function Name  : SMBus_StopBit
* Description    : Generate STOP condition on SMBus
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void SMBus_StopBit(void)
{SMBUS_SCK_L();     // Clear SCL lineSMBus_Delay(5);        // Wait a few microsecondsSMBUS_SDA_L();        // Clear SDA lineSMBus_Delay(5);        // Wait a few microsecondsSMBUS_SCK_H();        // Set SCL lineSMBus_Delay(5);      // Stop condition setup time(Tsu:sto=4.0us min)SMBUS_SDA_H();      // Set SDA line在SCK=1时,检测到SDA由0到1表示通信结束(上升沿)
}/*******************************************************************************
* Function Name  : SMBus_SendByte
* Description    : Send a byte on SMBus
* Input          : Tx_buffer
* Output         : None
* Return         : None
*******************************************************************************/
u8 SMBus_SendByte(u8 Tx_buffer)
{u8 Bit_counter;u8  Ack_bit;u8  bit_out;for(Bit_counter=8; Bit_counter; Bit_counter--){if (Tx_buffer&0x80){bit_out=1;   // If the current bit of Tx_buffer is 1 set bit_out}else{bit_out=0;  // else clear bit_out}SMBus_SendBit(bit_out);       // Send the current bit on SDATx_buffer<<=1;             // Get next bit for checking}Ack_bit=SMBus_ReceiveBit();       // Get acknowledgment bitreturn Ack_bit;
}/*******************************************************************************
* Function Name  : SMBus_SendBit
* Description    : Send a bit on SMBus 82.5kHz
* Input          : bit_out
* Output         : None
* Return         : None
*******************************************************************************/
void SMBus_SendBit(u8 bit_out)
{if(bit_out==0){SMBUS_SDA_L();}else{SMBUS_SDA_H();}SMBus_Delay(2);                    // Tsu:dat = 250ns minimumSMBUS_SCK_H();                   // Set SCL lineSMBus_Delay(6);                  // High Level of Clock PulseSMBUS_SCK_L();                  // Clear SCL lineSMBus_Delay(3);                    // Low Level of Clock Pulse
//  SMBUS_SDA_H();                  // Master release SDA line ,return;
}/*******************************************************************************
* Function Name  : SMBus_ReceiveBit
* Description    : Receive a bit on SMBus
* Input          : None
* Output         : None
* Return         : Ack_bit
*******************************************************************************/
u8 SMBus_ReceiveBit(void)
{u8 Ack_bit;SMBUS_SDA_H();          //引脚靠外部电阻上拉,当作输入SMBus_Delay(2);          // High Level of Clock PulseSMBUS_SCK_H();          // Set SCL lineSMBus_Delay(5);          // High Level of Clock Pulseif (SMBUS_SDA_PIN()){Ack_bit=1;}else{Ack_bit=0;}SMBUS_SCK_L();            // Clear SCL lineSMBus_Delay(3);            // Low Level of Clock Pulsereturn   Ack_bit;
}/*******************************************************************************
* Function Name  : SMBus_ReceiveByte
* Description    : Receive a byte on SMBus
* Input          : ack_nack
* Output         : None
* Return         : RX_buffer
*******************************************************************************/
u8 SMBus_ReceiveByte(u8 ack_nack)
{u8     RX_buffer;u8    Bit_Counter;for(Bit_Counter=8; Bit_Counter; Bit_Counter--){if(SMBus_ReceiveBit())          // Get a bit from the SDA line{RX_buffer <<= 1;          // If the bit is HIGH save 1  in RX_bufferRX_buffer |=0x01;}else{RX_buffer <<= 1;           // If the bit is LOW save 0 in RX_bufferRX_buffer &=0xfe;}}SMBus_SendBit(ack_nack);            // Sends acknowledgment bitreturn RX_buffer;
}/*******************************************************************************
* Function Name  : SMBus_Delay
* Description    : 延时  一次循环约1us
* Input          : time
* Output         : None
* Return         : None
*******************************************************************************/
void SMBus_Delay(u16 time)
{u16 i, j;for (i=0; i<4; i++){for (j=0; j<time; j++);}
}/*******************************************************************************
* Function Name  : SMBus_Init
* Description    : SMBus初始化
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void SMBus_Init()
{GPIO_InitTypeDef    GPIO_InitStructure;/* Enable SMBUS_PORT clocks */RCC_APB2PeriphClockCmd(RCC_APB2Periph_SMBUS_PORT, ENABLE);/*配置SMBUS_SCK、SMBUS_SDA为集电极开漏输出*/GPIO_InitStructure.GPIO_Pin = SMBUS_SCK | SMBUS_SDA;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(SMBUS_PORT, &GPIO_InitStructure);SMBUS_SCK_H();SMBUS_SDA_H();
}/******************************************************************************** Function Name  : SMBus_ReadMemory* Description    : READ DATA FROM RAM/EEPROM* Input          : slaveAddress, command* Output         : None* Return         : Data
*******************************************************************************/
u16 SMBus_ReadMemory(u8 slaveAddress, u8 command)
{u16 data;          // Data storage (DataH:DataL)u8 Pec;                // PEC byte storageu8 DataL=0;         // Low data byte storageu8 DataH=0;            // High data byte storageu8 arr[6];         // Buffer for the sent bytesu8 PecReg;          // Calculated PEC byte storageu8 ErrorCounter;  // Defines the number of the attempts for communication with MLX90614ErrorCounter=0x00;                // Initialising of ErrorCounterslaveAddress <<= 1;   //2-7位表示从机地址do{repeat:SMBus_StopBit();             //If slave send NACK stop comunication--ErrorCounter;                   //Pre-decrement ErrorCounterif(!ErrorCounter)               //ErrorCounter=0?{break;                       //Yes,go out from do-while{}}SMBus_StartBit();              //Start conditionif(SMBus_SendByte(slaveAddress))//Send SlaveAddress 最低位Wr=0表示接下来写命令{goto  repeat;             //Repeat comunication again}if(SMBus_SendByte(command))     //Send command{goto repeat;             //Repeat comunication again}SMBus_StartBit();                   //Repeated Start conditionif(SMBus_SendByte(slaveAddress+1))   //Send SlaveAddress 最低位Rd=1表示接下来读数据{goto   repeat;                 //Repeat comunication again}DataL = SMBus_ReceiveByte(ACK);    //Read low data,master must send ACKDataH = SMBus_ReceiveByte(ACK); //Read high data,master must send ACKPec = SMBus_ReceiveByte(NACK);   //Read PEC byte, master must send NACKSMBus_StopBit();              //Stop conditionarr[5] = slaveAddress;     //arr[4] = command;            //arr[3] = slaveAddress+1;    //Load array arrarr[2] = DataL;                //arr[1] = DataH;              //arr[0] = 0;                  //PecReg=PEC_Calculation(arr);//Calculate CRC}while(PecReg != Pec);       //If received and calculated CRC are equal go out from do-while{}data = (DataH<<8) | DataL;  //data=DataH:DataLreturn data;
}/*******************************************************************************
* Function Name  : PEC_calculation
* Description    : Calculates the PEC of received bytes
* Input          : pec[]
* Output         : None
* Return         : pec[0]-this byte contains calculated crc value
*******************************************************************************/
u8 PEC_Calculation(u8 pec[])
{u8     crc[6];u8   BitPosition=47;u8  shift;u8    i;u8    j;u8    temp;do{/*Load pattern value 0x000000000107*/crc[5]=0;crc[4]=0;crc[3]=0;crc[2]=0;crc[1]=0x01;crc[0]=0x07;/*Set maximum bit position at 47 ( six bytes byte5...byte0,MSbit=47)*/BitPosition=47;/*Set shift position at 0*/shift=0;/*Find first "1" in the transmited message beginning from the MSByte byte5*/i=5;j=0;while((pec[i]&(0x80>>j))==0 && i>0){BitPosition--;if(j<7){j++;}else{j=0x00;i--;}}/*End of while *//*Get shift value for pattern value*/shift=BitPosition-8;/*Shift pattern value */while(shift){for(i=5; i<0xFF; i--){if((crc[i-1]&0x80) && (i>0)){temp=1;}else{temp=0;}crc[i]<<=1;crc[i]+=temp;}/*End of for*/shift--;}/*End of while*//*Exclusive OR between pec and crc*/for(i=0; i<=5; i++){pec[i] ^=crc[i];}/*End of for*/}while(BitPosition>8); /*End of do-while*/return pec[0];
}/******************************************************************************** Function Name  : SMBus_ReadTemp* Description    : Calculate and return the temperature* Input          : None* Output         : None* Return         : SMBus_ReadMemory(0x00, 0x07)*0.02-273.15
*******************************************************************************/
float SMBus_ReadTemp(void)
{   float temp;temp = SMBus_ReadMemory(SA, RAM_ACCESS|RAM_TOBJ1)*0.02-273.15;return temp;
}/*********************************END OF FILE*********************************/

mlx90614.h

/*******************************************************************************
* 文件名       : mlx90614.h
* 作  者  :
* 版  本  :
* 日  期  : 2013-08-07
* 描  述  : mlx90614函数
*******************************************************************************//* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MLX90614_H
#define __MLX90614_H/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
/* Exported types ------------------------------------------------------------*/
/* Exported variables --------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void SMBus_StartBit(void);
void SMBus_StopBit(void);
void SMBus_SendBit(u8);
u8 SMBus_SendByte(u8);
u8 SMBus_ReceiveBit(void);
u8 SMBus_ReceiveByte(u8);
void SMBus_Delay(u16);
void SMBus_Init(void);
u16 SMBus_ReadMemory(u8, u8);
u8 PEC_Calculation(u8*);
float SMBus_ReadTemp(void); //获取温度值#endif/*********************************END OF FILE*********************************/

总结
个人觉得数据不太准确,网上找过很多驱动程序要么是付费,要么是文件发一半,几个能用的这个驱动相对稳定。

工程免费分享,评论区获取。

基于STM32的MLX90614(GY-906)人体红外测温相关推荐

  1. 第二十七篇、基于Arduino uno,获取mlx90614非接触式红外测温传感器的温度值——结果导向

    0.结果 说明:先来看看串口调试助手显示的结果,第一个值是空气的温度,第二个值是被测量的物体温度,如果是你想要的,可以接着往下看. 1.外观 说明:虽然mlx90614非接触式红外测温传感器形态各异, ...

  2. GY906 MLX90614 非接触式 红外测温传感器 LabVIEW i2c总线数据读取

    GY906使用的红外测温芯片为MLX90614. 使用LabVIEW读取i2c总线数据时,需要知道传感器的地址,出厂默认为0x5A.传感器地址支持自己修改,存放在芯片EEPROM的0x0E位置,可以通 ...

  3. Arduino使用MLX90614 非接触式红外测温传感器

    相关资料链接 链接:https://pan.baidu.com/s/1eE0rkaSJsKJMU_RUorS5OA 提取码:3ujh 1.1 介绍: MLX90614是一款由迈来芯公司提供的低成本,无 ...

  4. 【单片机毕业设计】【mcuclub-jk-003】基于单片机的非接触红外测温的设计

    最近设计了一个项目基于单片机的非接触红外测温系统,与大家分享一下: 一.基本介绍 项目名:非接触红外测温 项目编号:mcuclub-jk-003 单片机类型:STC89C52.STM32F103C8T ...

  5. 基于stm32人脸识别和红外测温

    目录 一.项目功能 二.原理图 三.实物视频 四.实物图片 五.程序 资料下载地址:基于STM32人脸识别和红外测温 一.项目功能 本系统由stm32f103c8t6单片机最小系统电路+k210人脸识 ...

  6. 26、基于51单片机mlx90614(GY-906)非接触式红外测温上下限声光报警系统设计

    摘要 门式红外人体测温安检仪与传统的安检系统比较,增加了人体测温功能,在流行病多发季节可以适当的提醒人们减少外出,必要时可采取强制措施禁止出行以减少疾病的传播:并且测温为非接触式,与传统的接触式测温相 ...

  7. STM32驱动MLX90614红外测温模块

    简介:STM32F103C8T6驱动MLX90614红外测温模块源码介绍. 开发平台:KEIL ARM MCU型号:STM32F103C8T6 传感器型号:MLX90614 特别提示:驱动内可能使用了 ...

  8. 基于stm32的非接触式红外测温系统

    一.硬件材料清单: 1.STM32核心板 2.OLED显示屏 3.mlx90614 红外测温传感器 4.蜂鸣器 5.按键 二.实现的功能 1.mlx90614红外温度数据的实时检测 2.本地OLED数 ...

  9. STM32+MLX90614红外测温

    红外测温 文章目录 红外测温 前言 一.传感器 二.代码 1.MLX90614.C 2.MLX90614.h 总结 前言 手上有一个红外测温模块,拿出来玩一玩 一.传感器 一共有四个引脚,看到SCL和 ...

  10. STM32系列(HAL库)——F103C8T6 通过GY906/MLX90614红外测温模块实现温度测量

    1.软件准备 (1)编程平台:Keil5 (2)CubeMX (3)XCOM(串口调试助手) 2.硬件准备 (1)GY-906-BCC红外测温模块 (2)F1的板子,本例使用经典F103C8T6 (3 ...

最新文章

  1. AI视频行为分析系统项目复盘——技术篇2:视频流GPU硬解码
  2. Sarg安装配置使用
  3. python smtp模块发送邮件
  4. [leetcode-515-Find Largest Value in Each Tree Row]
  5. OpenCV中像素逻辑运算:逻辑非运算
  6. 可重入锁(递归锁) 互斥锁属性设置
  7. 分布式系统的一致性协议之 2PC 和 3PC
  8. AtCoder Regular Contest 105 部分 NIM游戏
  9. php static 访问,使用PHP访问Static方法的最佳方法
  10. 18. RSS订阅(RSS Feeds)and price rule
  11. 公式编辑器MathType中矩阵模板的使用技巧
  12. C语言作业NOTES
  13. Spring实战第五版(中文版)学习笔记-第一章 Spring起步
  14. 打印 条码 CodeSoft JsBarCode
  15. WPS 表格中单元格文字后插入公式
  16. u-boot编译错误1:dtc: not found make
  17. 批处理从入门到精通_DOS/BAT
  18. Pygame简易版2048小游戏:超详细解说,看完还不会可以剁手了(附完整源码)
  19. 安卓Trustzone有巨大漏洞?降级攻击为你做出解析!
  20. 周鸿祎:没钱也能创业 怎样写商业计划书

热门文章

  1. chrome主页被毒霸网址大全劫持解决办法
  2. python入门学习——6种方法求n的阶乘(8种写法)
  3. 怎样为自己计算机设置共享密码错误,如何忘记共享电脑的账号和密码怎么办
  4. win7共享文件提示输入网络密码
  5. oracle中if语句用法,Oracle IF语句的使用 | 学步园
  6. 【第三十一期】360后台开发实习面经 - 两轮技术面
  7. 营销公众号该如何运营大纲
  8. 你的编程能力从什么时候开始突飞猛进?
  9. layui调用相册功能和点击按钮调用相册功能
  10. 【Other】千字文 硬笔 楷书 字帖