当前位置: 首页 > news >正文

海阳网站建设制作图网官网在线制作

海阳网站建设,制作图网官网在线制作,百度站长工具查询,免费拓客100个方法目录 模块选择 编程环境 MLX90614基本原理 通信协议#xff08;SMBus通信#xff0c;类IIC通信#xff09; 代码实现 STM32与模块之间接线表 1.标准库实现温度采集 2.HAL库实现温度采集 模块选择 STM32F103C8T6 MLX90614 非接触式红外测温传感器 编程环境 KEIL5…目录 模块选择 编程环境 MLX90614基本原理 通信协议SMBus通信类IIC通信 代码实现 STM32与模块之间接线表 1.标准库实现温度采集 2.HAL库实现温度采集 模块选择 ·STM32F103C8T6 ·MLX90614 非接触式红外测温传感器 编程环境 ·KEIL5μVision V5.30.0.0 其它版本影响并不大 ·STM32CubeMX版本不限 ·串口助手 MLX90614基本原理 引脚说明 编号名称功能1VCC电源正3-5V2GND电源地3SCL串行时钟输入4SDA串行地址和数据输入/输出 MLX90614是一种红外温度计用于非接触式温度测量。红外测温是根据被测物体的红外辐射能量来确定物体的温度不与被测物体接触具有不影响被测物体温度分布场温度分辨率高、响应速度快、测温范围广、不受测温上限的限制、稳定性好等特点。适合于汽车空调、室内暖气、家用电器、手持设备以及医疗设备应用等。 MLX90614的出厂校准温度范围很广环境温度为-40°C——125°C目标温度为-70°C——380°C。测量值是传感器视场中所有物体的平均温度。在室温下MLX90614的标准精确度为±0.5°C。 MLX90614由MLX81101红外热电堆传感器和包括含有稳压电路、低噪声放大器、A/D转换器、DSP单元、脉宽调制电路及逻辑控制电路的MLX90302信号处理芯片构成。 其工作原理为:红外热电堆传感器输出的温度信号经过内部低噪声、低失调的运算放大器(OPA)放大后经过A/D转换器(ADC)转换为17位数字信号通过可编程FIR及IIR低通数字滤波器(即DSP)处理后输出,输出结果存储在其内部RAM存储单元中。 MLX90614 是由内部状态机控制物体温度和环境温度的测量和计算进行温度后处理并将结果通过 PWM 或是 SMBus 模式输出。 ASSP 支持两个 IR 传感器。 (MLX90614xAx 只有一个 IR 传感器) IR 传感器的输出通过增益可编程的低噪声低失 调电压放大器放大经过 Sigma Delta 调制器转换为单一比特流并反馈给 DSP 做后续的处理。信号通过可编程的 (用 EEPROM 实现) FIR 和 IIR 低通滤波器以进一步减低输入信号的带宽从而达到所需的噪声特性和刷新率。IIR 滤波器的输出为测量结果并存于内部 RAM 中其中三个单元可被用到一个是片内温度传感器片上 PTAT 或 PTC其余两个为 IR 传感器。 基于以上测量结果计算出对应的环境温度 Ta 和物体温度 To两个温度分辨率都为 0.01 ˚C。Ta 和 To 可通过两种方式读取通过两线接口读取 RAM 单元(0.02°C 分辨率固定范围) 或者通过 PWM 数字模式输出。 (10 位分辨率 范围可配置) 测量周期的最后一步为测量所得 Ta 和 To 被重新调节为 PWM 所需的输出分辨率并且该数据存在 PWM 状态 机的寄存器中状态机可以产生固定频率和一定占空比来表示测量的数据。 通信协议SMBus通信类IIC通信 单片机与MLX90614红外测温模块之间通信的方式是“类IIC”通信意思就是通信方式跟IIC通信方式很像但又不是IIC它有另外一个名字叫做SMBus。SMBus (System Management Bus)是 1995 年由 intel 公司提出的一种高效同步串行总线SMBus 只有两根信号线:双向数据线和时钟信号线容许 CPU 与各种外围接口器件以串行方式进行通信、交换信息既可以提高传输速度也可以减小器件的资源占用另外即使在没有SMBus 接口的单片机上也可利用软件进行模拟。 代码实现 STM32与模块之间接线表 MLX90614STM32F103C8T6VCCVCCGNDGNDSCLPB8SDAPB9-PA9USART1_ TX-PA10USART1_RX 1.标准库实现温度采集 主函数 int main(void) { float Temperature10;char temStr[100] ;int i 0; // 循环变量delay_init(); // 延时函数初始化配置uart_init(115200);USART_SendData(USART1, A);Mlx96014_Configuration();/* Infinite loop */while (1){TemperatureSMBus_ReadTemp();sprintf(temStr,The Temperature is:%.2f\r\n,Temperature);for(i0;istrlen(temStr);i){USART_SendData(USART1, temStr[i]);delay_ms(1);}delay_ms(500);} } mlx90614.c /******************************************************************************* * 文件名 : mlx90614.c * 作 者 : * 版 本 : * 日 期 : 2015-08-07 * 描 述 : mlx90614函数 *******************************************************************************/ #include stm32f10x.h #include mlx90614.h/******************************************************************************* * Function Name : Mlx90614_Configuration * Description : Mlx90614_Configuration * Input : None * Output : None * Return : None *******************************************************************************/ void Mlx96014_Configuration(void) {GPIO_InitTypeDef GPIO; //声明一个结构体变量RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);// 温度传感器引脚配置GPIO.GPIO_Pin GPIO_Pin_9;//非接触温度传感器SDA 连接PB9GPIO.GPIO_Speed GPIO_Speed_50MHz;//管脚频率为50MHZGPIO.GPIO_Mode GPIO_Mode_Out_OD;//输出模式为GPIO_Init(GPIOB,GPIO);//初始化GPIOB寄存器GPIO.GPIO_Pin GPIO_Pin_8;//非接触温度传感器SCL 连接PB8GPIO.GPIO_Speed GPIO_Speed_50MHz;//管脚频率为50MHZGPIO.GPIO_Mode GPIO_Mode_Out_OD;//输出模式为GPIO_Init(GPIOB,GPIO);//初始化GPIOB寄存器SDA_H;SCL_H; //因为SMBus是下降沿触发 }/******************************************************************************* * Function Name : SMBus_StartBit * Description : Generate START condition on SMBus * Input : None * Output : None * Return : None *******************************************************************************/ void SMBus_StartBit(void) {SDA_H; // Set SDA line SMBus_Delay(1); // Wait a few microseconds SCL_H; // Set SCK line SMBus_Delay(5); // Generate bus free time between StopSDA_L; // Clear SDA lineSMBus_Delay(10); // Hold time after (Repeated) Start// Condition. After this period, the first clock is generated.//(Thd:sta4.0us min)SCL_L; // Clear SCK lineSMBus_Delay(2); // Wait a few microseconds }/******************************************************************************* * Function Name : SMBus_StopBit * Description : Generate STOP condition on SMBus * Input : None * Output : None * Return : None *******************************************************************************/void SMBus_StopBit(void) {SCL_L; // Clear SCK lineSMBus_Delay(5); // Wait a few microsecondsSDA_L; // Clear SDA lineSMBus_Delay(5); // Wait a few microsecondsSCL_H; // Set SCK lineSMBus_Delay(10); // Stop condition setup time(Tsu:sto4.0us min)SDA_H; // Set SDA line }/******************************************************************************* * 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_counter8; Bit_counter; Bit_counter--){if (Tx_buffer0x80){bit_out1; // If the current bit of Tx_buffer is 1 set bit_out}else{bit_out0; // else clear bit_out}SMBus_SendBit(bit_out); // Send the current bit on SDATx_buffer1; // Get next bit for checking}Ack_bitSMBus_ReceiveBit(); // Get acknowledgment bitreturn Ack_bit; }/******************************************************************************* * Function Name : SMBus_SendBit * Description : Send a bit on SMBus * Input : bit_out * Output : None * Return : None *******************************************************************************/ void SMBus_SendBit(u8 bit_out) {if(bit_out0){SDA_L; }else{SDA_H;}SMBus_Delay(2); // Tsu:dat 250ns minimumSCL_H; // Set SCK lineSMBus_Delay(10); // High Level of Clock PulseSCL_L; // Clear SCK lineSMBus_Delay(10); // 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;SDA_H; //引脚靠外部电阻上拉当作输入SCL_H; // Set SCL lineSMBus_Delay(2); // High Level of Clock Pulseif (SMBUS_SDA_PIN){Ack_bit1;}else{Ack_bit0;}SCL_L; // Clear SCL lineSMBus_Delay(4); // 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_Counter8; 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 (i0; i4; i){for (j0; jtime; j);} }/******************************************************************************** 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 DataL0; // Low data byte storageu8 DataH0; // 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 MLX90614ErrorCounter0x00; // Initialising of ErrorCounterslaveAddress 1; //2-7位表示从机地址do{ repeat:SMBus_StopBit(); //If slave send NACK stop comunication--ErrorCounter; //Pre-decrement ErrorCounterif(!ErrorCounter) //ErrorCounter0?{break; //Yes,go out from do-while{}}SMBus_StartBit(); //Start conditionif(SMBus_SendByte(slaveAddress))//Send SlaveAddress 最低位Wr0表示接下来写命令{goto repeat; //Repeat comunication again}if(SMBus_SendByte(command)) //Send command{goto repeat; //Repeat comunication again}SMBus_StartBit(); //Repeated Start conditionif(SMBus_SendByte(slaveAddress1)) //Send SlaveAddress 最低位Rd1表示接下来读数据{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] slaveAddress1; //Load array arrarr[2] DataL; arr[1] DataH; arr[0] 0; PecRegPEC_Calculation(arr); //Calculate CRC}while(PecReg ! Pec); //If received and calculated CRC are equal go out from do-while{}data (DataH8) | DataL; //dataDataH: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 BitPosition47;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,MSbit47)*/BitPosition47;/*Set shift position at 0*/shift0;/*Find first 1 in the transmited message beginning from the MSByte byte5*/i5;j0;while((pec[i](0x80j))0 i0){BitPosition--;if(j7){j;}else{j0x00;i--;}}/*End of while *//*Get shift value for pattern value*/shiftBitPosition-8;/*Shift pattern value */while(shift){for(i5; i0xFF; i--){if((crc[i-1]0x80) (i0)){temp1;}else{temp0;}crc[i]1;crc[i]temp;}/*End of for*/shift--;}/*End of while*//*Exclusive OR between pec and crc*/for(i0; i5; i){pec[i] ^crc[i];}/*End of for*/}while(BitPosition8); /*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) { return SMBus_ReadMemory(SA, RAM_ACCESS|RAM_Ta)*0.02-273.15; }/*********************************END OF FILE*********************************/ 注意 float SMBus_ReadTemp(void) { return SMBus_ReadMemory(SA, RAM_ACCESS|RAM_Ta)*0.02-273.15; } 测的是环境温度如果需要测量物体表面温度。 #define RAM_TOBJ1 0x07 //To1 address in the eeprom 表面温度 #define RAM_Ta 0x06 //Ta address in the eeprom 环境温度 实现效果 2.HAL库实现温度采集 因为代码封装的较好移植性较好和标准库代码基本相似只需要修改部分核心代码。 修改片段 #define SMBUS_SCK_H() HAL_GPIO_WritePin(GPIOB, SMBus_SCL_Pin, GPIO_PIN_SET) #define SMBUS_SCK_L() HAL_GPIO_WritePin(GPIOB, SMBus_SCL_Pin, GPIO_PIN_RESET) #define SMBUS_SDA_H() HAL_GPIO_WritePin(GPIOB, SMBus_SDA_Pin, GPIO_PIN_SET) #define SMBUS_SDA_L() HAL_GPIO_WritePin(GPIOB, SMBus_SDA_Pin, GPIO_PIN_RESET)#define SMBUS_SDA_PIN() HAL_GPIO_ReadPin(GPIOB,SMBus_SDA_Pin) 基本就可以实现数据采集了。 注意 float SMBus_ReadTemp(void) { return (SMBus_ReadMemory(SA, RAM_ACCESS|RAM_TaA)*0.02-273.15); }例子中测试的是物体温度物体表面温度修改 #define RAM_TOBJ1 0x07 // 物体表面温度 #define RAM_TaA 0x06 // 环境温度 这里需要需要注意的地方CubeMX生成的代码需要修改一下不然不能实现采集功能。 推挽输出 GPIO_MODE_OUTPUT_PP 修改成 开漏输出模式 GPIO_MODE_OUTPUT_OD 实现效果 源码下载链接 STM32实现MLX90614非接触测温串口显示标准库与HAL库实现资源-CSDN文库 吾芯电子工作室
http://www.sadfv.cn/news/85182/

相关文章:

  • 帮忙建网站的人合肥网页定制
  • 医院网站建设 费用公司策划方案
  • html5手机移动app网站制作教程手机网站商城建设答辩问题
  • 微商软件商城总站wordpress 发文章漏洞
  • 免费购物网站制作室内设计师招聘简章
  • 重庆孝爱之家网站建设网站开发预算报表
  • 北京企业网站建站哪家好长沙网站建设市场低价
  • 学做蛋糕网站中山seo扣费
  • 蓝色网站特点贵州app开发公司
  • 易物网网站建设管理常州城投建设招标网站
  • 山西网站开发建设网站企业案例
  • 免费有趣的网站塑胶制品塘厦东莞网站建设
  • 今标 网站建设天津市今天新闻头条
  • 什么网站有项目做WordPress.AMP
  • 2010年最具人气的平面设计师必备网站公益建设网站的作用
  • 淘宝客网站根目录网站的备案流程
  • 中英文网站为什么要分开做app比网站的优势
  • 网站重新设计网站建设分解结构
  • 北京改网站公众号编辑 wordpress
  • 东莞网站建设公司辉煌大厦哪里可以接网站开发项目做
  • 揭阳网站建设托管网站建设网站公司哪家好
  • 网站建设织梦怎么样网站建设的五类成员
  • 公司网站设华为外包一般能干多久
  • 网站彩票网站开发石碣做网站优化
  • 公司做网站的费用怎么做账十大保洁公司
  • 建网站难不难注册公司后每年要交什么费用
  • 广州做网站建设的公司哪家好电子简历手机版免费
  • 优秀建筑方案设计文本seo快速排名软件首页
  • 宁波模板建站源码建筑招投标信息网
  • 58同城 网站建设 推广排名电子兼职网站建设