55 lines
1.4 KiB
C
55 lines
1.4 KiB
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>
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/**************************************************
|
|||
|
@brif <EFBFBD><EFBFBD>ȡTemp<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
@para <EFBFBD><EFBFBD>
|
|||
|
@rev temp:Temp<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ֵ(<EFBFBD><EFBFBD>5λ<EFBFBD><EFBFBD>Ч)
|
|||
|
****************************************************/
|
|||
|
uint16_t LM75GetTempReg(void)
|
|||
|
{
|
|||
|
uint16_t temp;
|
|||
|
uint8_t tempReg[2]; //tempReg[0]:<3A>߰<EFBFBD>λ<EFBFBD><CEBB>tempReg[1]:<3A>Ͱ<EFBFBD>λ
|
|||
|
if(HAL_I2C_Mem_Read(&hi2c1,LM75A_ADDR,TEMP_ADDR,2,tempReg,2,100) == HAL_OK)
|
|||
|
{
|
|||
|
temp = ((tempReg[0] << 8) | tempReg[1]) >> 5; //<2F><><EFBFBD>ϳ<EFBFBD>11λ<31>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
return temp;
|
|||
|
}
|
|||
|
|
|||
|
//<2F>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>¶<EFBFBD>ֵ
|
|||
|
/**************************************************
|
|||
|
@brif ʵ<EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>ת<EFBFBD><EFBFBD>
|
|||
|
@para Temp<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
@rev TempValue:ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>ֵ
|
|||
|
****************************************************/
|
|||
|
double LM75GetTempValue(uint16_t tempReg)
|
|||
|
{
|
|||
|
double TempValue;
|
|||
|
if((tempReg & 0x0400) == 0x0000) //<2F><><EFBFBD><EFBFBD>λ D10 = 0 <20><>>ʵ<><CAB5><EFBFBD>¶<EFBFBD>Ϊ<EFBFBD><CEAA>
|
|||
|
{
|
|||
|
TempValue = tempReg * 0.125;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TempValue = ((tempReg^0xffff)+1) * 0.125;
|
|||
|
TempValue = -TempValue;
|
|||
|
}
|
|||
|
return TempValue;
|
|||
|
}
|
|||
|
|