基本信息
源码名称:温度传感器122_stm32_demo.c
源码大小:3.21KB
文件格式:.c
开发语言:C/C++
更新时间:2022-01-26
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 5 元 
   源码介绍

温度传感器122_stm32_demo.c


//**************************************GX122**********************************************//

void spiReadTemp() {
  u16 temp;
float  temp1 = 0;  
u16 cfg;
u16 th;
u16 tl;
 
spiStart();

temp = spiReadWord();//读温度
 
spiWriteWord(0x8008); cfg = spiReadWord();//读配置寄存器
spiWriteWord(0x8010); tl  = spiReadWord();//读 low temp Threshold   低阈值
spiWriteWord(0x8018); th  = spiReadWord();//读 high temp Threshold  高阈值
 
spiStop();


/**温度**/
#if 1
 

if((temp&0x8000) == 0 )
{
 
temp = temp >> 3;
temp1 =temp*0.0625; 
printf("当前温度: %f\r\n",temp1);
}
else 
{
 
    temp = ((~(temp >> 3)) & 0x0FFF) 1;

temp1 = temp * 0.0625; 

printf("当前温度: -%f\r\n",temp1);
}

tl = tl>>3;

th = th>>3;

///**配置寄存器**/
//printf("当前配置寄存器: %04X \r\n",cfg);
//
///**低温阈值寄存器**/
//printf("当前低温阈值寄存器: %04X \r\n",tl);
//
///**高温阈值寄存器**/
//printf("当前高温阈值寄存器: %04X \r\n",th);
//
#endif 
}