30 lines
859 B
C
30 lines
859 B
C
|
#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;
|
|||
|
}
|