嵌入式实操----基于RT1170 首板硬件之tempsensor温度传感器调试(二十一)
本文主要是通过迁移的思维,记录本人初次使用NXP MCUXpresso SDK API进行BSP开发
本文主要是描述整合tempsensor模块接口,供应用开发人员使用。这当中有一个重要的功能,就是CPU的结温达到设置的阈值时,CPU主动复位,本文的阈值的110度。
1. 首先阅读原理图
NA
2. 调试过程
2. 1 tempsensor初始化
/*----------------------------------------------*
* macros *
*----------------------------------------------*/
#define DEMO_TMPSNS TMPSNS
#define DEMO_LOWALARMTEMP 0U
#define DEMO_HIGHALARMTEMP 70
#define DEMO_PINICALARMTEMP 110U
/**
* @brief tempsensor init
*
* @param [in] void
* @param [out] None
*
* @return
*
* @history
* 1.Date : 2021-5-28 14:7:9
* Author : panzidong
* Modification : Created function
*/
void bsp_tempsensor_init(void)
{
tmpsns_config_t config;
TMPSNS_GetDefaultConfig(&config);
config.measureMode = kTEMPSENSOR_ContinuousMode;
config.frequency = 0x03U;
/*设置MCU高温警告阈值*/
config.highAlarmTemp = DEMO_HIGHALARMTEMP;
/*设置MCU低温警告阈值*/
config.lowAlarmTemp = DEMO_LOWALARMTEMP;
/*设置MCU 复位警告阈值*/
config.panicAlarmTemp = DEMO_PINICALARMTEMP;
TMPSNS_Init(DEMO_TMPSNS, &config);
TMPSNS_StartMeasure(DEMO_TMPSNS);
}
2. 2 tempsensor值获取
**
* @brief print mcu tempsensor info
*
* @param [in] void
* @param [out] None
*
* @return
*
* @history
* 1.Date : 2021-5-28 14:11:18
* Author : panzidong
* Modification : Created function
*/
void bsp_dump_tempsensor(void){
float temperature = 0U;
/* Get temperature */
temperature = TMPSNS_GetCurrentTemperature(DEMO_TMPSNS);
PRINTF("temperature is %f celsius degree \r\n", temperature);
SDK_DelayAtLeastUs(1000*1000, SystemCoreClock);
/* Get current temperature */
temperature = TMPSNS_GetCurrentTemperature(DEMO_TMPSNS);
PRINTF("temperature is %f celsius degree. \r\n", temperature);
}
3. 总结
NA