STM32驱动MLX90614红外测温模块 |
您所在的位置:网站首页 › mlx90614红外传感器介绍 › STM32驱动MLX90614红外测温模块 |
简介:STM32F103C8T6驱动MLX90614红外测温模块源码介绍。 开发平台:KEIL ARM MCU型号:STM32F103C8T6 传感器型号:MLX90614 特别提示:驱动内可能使用了某些其他组件,比如delay等,在文末外设模板下载地址内有。 1积分源码下载地址在文末!!! 接口图: 使用举例: #include #include "MLX90614.h" int main() { float tem; SMBus_Init(); // 初始化 while(1) { tem = SMBus_ReadTemp(); // 读取温度 printf("tem:%f\n", tem); delayMs(1000); } }驱动源码: MLX90614.c #include "MLX90614.h" #define ACK 0 #define NACK 1 #define SA 0x00 #define RAM_ACCESS 0x00 #define EEPROM_ACCESS 0x20 #define RAM_TOBJ1 0x07 #define SMBUS_PORT GPIOB #define SMBUS_SCK GPIO_Pin_7 #define SMBUS_SDA GPIO_Pin_6 #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 void SMBus_StartBit(void) { SMBUS_SDA_H(); // Set SDA line SMBus_Delay(8); // Wait a few microseconds SMBUS_SCK_H(); // Set SCL line SMBus_Delay(8); // Generate bus free time between Stop SMBUS_SDA_L(); // Clear SDA line SMBus_Delay(8); // Hold time after (Repeated) Start // Condition. After this period, the first clock is generated. //(Thd:sta=4.0us min) SMBUS_SCK_L(); // Clear SCL line SMBus_Delay(8); // Wait a few microseconds } void SMBus_StopBit(void) { SMBUS_SCK_L(); // Clear SCL line SMBus_Delay(8); // Wait a few microseconds SMBUS_SDA_L(); // Clear SDA line SMBus_Delay(8); // Wait a few microseconds SMBUS_SCK_H(); // Set SCL line SMBus_Delay(8); // Stop condition setup time(Tsu:sto=4.0us min) SMBUS_SDA_H(); // Set SDA line } 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 SDA Tx_buffer |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |