This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/EmbededSTM32/lab6/Core/Src/LM75A.c
2023-06-23 17:30:03 +08:00

29 lines
859 B
C
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}