29 lines
859 B
C
Executable file
29 lines
859 B
C
Executable file
#include "LM75A.h"
|
||
#include "stm32f4xx_hal.h"
|
||
#include "i2c.h"
|
||
#include "usart.h"
|
||
|
||
/**************************************************
|
||
@brif 设置设备模式
|
||
@para ConfReg:配置寄存器地址
|
||
Mode:需要配置的模式
|
||
@rev: 无
|
||
****************************************************/
|
||
void LM75SetMode(uint8_t ConfReg, uint8_t Mode)
|
||
{
|
||
while(HAL_I2C_Mem_Write(&hi2c1,LM75A_ADDR,ConfReg,1,&Mode,1,100) != HAL_OK); //写模式寄存器
|
||
}
|
||
|
||
uint16_t LM75GetTempReg(void) //从LM75A读取温度数据(2字节))
|
||
{
|
||
uint8_t data[2];
|
||
while(HAL_I2C_Mem_Read(&hi2c1,LM75A_ADDR,TEMP_ADDR,I2C_MEMADD_SIZE_8BIT,data,2,100)!=HAL_OK);
|
||
return (data[0]<<8) + data[1];
|
||
|
||
}
|
||
double LM75GetTempValue(uint16_t tempreg) //将温度数据转换为温度值
|
||
{
|
||
if (tempreg >> 15 == 0)
|
||
return (double)(tempreg >> 5) * 0.125;
|
||
else return -1*(double)(((~tempreg)>>5) + 1)*0.125;
|
||
}
|