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

30 lines
859 B
C
Raw Permalink Normal View History

2023-06-23 09:30:03 +00:00
#include "LM75A.h"
#include "stm32f4xx_hal.h"
#include "i2c.h"
#include "usart.h"
/**************************************************
@brif <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
@para ConfReg:<EFBFBD><EFBFBD><EFBFBD>üĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
Mode:<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ģʽ
@rev: <EFBFBD><EFBFBD>
****************************************************/
void LM75SetMode(uint8_t ConfReg, uint8_t Mode)
{
while(HAL_I2C_Mem_Write(&hi2c1,LM75A_ADDR,ConfReg,1,&Mode,1,100) != HAL_OK); //дģʽ<C4A3>Ĵ<EFBFBD><C4B4><EFBFBD>
}
uint16_t LM75GetTempReg(void) //<2F><>LM75A<35><41>ȡ<EFBFBD><EFBFBD><C2B6><EFBFBD><EFBFBD>ݣ<EFBFBD>2<EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD>
{
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) //<2F><><EFBFBD><EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><EFBFBD>ֵ
{
if (tempreg >> 15 == 0)
return (double)(tempreg >> 5) * 0.125;
else return -1*(double)(((~tempreg)>>5) + 1)*0.125;
}