RA4L1-SENSOR开发板的温度值,断码屏显示

串口助手显示

RA4L1-SENSOR开发板上面是有个内部温度传感器的,可以直接测量到RA4L2的芯片温度的。这个温度传感器叫TSN,是你们永远都学不会的。

上面这个TSN就是RA4L1的温度传感器。
手册上有解释



要读取到温度值,需要按照上面的算法进行计算,才能读到ADC转换后的温度值。
对应的核心代码,如下,无私分享给你们。记好了!!!

while(1)
{
/* Enable scan triggering from ELC events. */
(void) R_ADC_ScanStart(&g_adc0_ctrl);
scan_complete_flag = false;
while (!scan_complete_flag)
{
/* Wait for callback to set flag. */
}
err = R_ADC_Read(&g_adc0_ctrl, ADC_CHANNEL_TEMPERATURE, &adc_data1);
assert(FSP_SUCCESS == err);
//Get ADC info
err = R_ADC_InfoGet(&g_adc0_ctrl, &adc_info);
assert(FSP_SUCCESS == err);
//Die temperature formula according to TSN documentation: T = ( Vs - V1 ) / slope + 125 C
V1 = ( 3.3 * (int) adc_info.calibration_data ) / 4096 ;
Vs = ( 3.3 * (int) adc_data1 ) / 4096 ;
die_temperature = CONSTANT * ( Vs - V1 ) / ( adc_info.slope_microvolts ) + 125.0;
static char string_die_temp[10] = {0};
sprintf( string_die_temp, "%.2f", die_temperature );
int a = (int)(die_temperature*100);
disp_num(3, (a/100)/10);disp_num(4, (a/100)%10);
disp_num(5, (a%100)/10);disp_num(6, (a%100)%10);
//printf("RA4L1 Sensor current chip temperature=%s a=%d\n", string_die_temp, a);
printf("RA4L1 Sensor开发板芯片当前温度是: %s 度\r\n", string_die_temp);
主要公式如下:
T = (Vs - V1) / slope + T1
● T: Ambient temperature of MCU as calculation result (°C)
● Vs: Voltage output by the temperature sensor on temperature measurement (V)
● T1: Temperature experimentally measured at one point (°C)
● V1: Voltage output by the temperature sensor on measurement of T1 (V)
● T2: Temperature experimentally measured at a second point (°C)
● V2: Voltage output by the temperature sensor on measurement of T2 (V)
● Slope: Temperature gradient of the temperature sensor (V / °C), slope = (V2 - V1) / (T2 -T1)
1。打开smart配置软件
进行如下配置即可:

2。添加核心代码
void hal_entry(void)
{
fsp_err_t err = FSP_SUCCESS;
/* TODO: add your own code here */
UART9_Init();UART1_Init();
ADC_25();
GLCD_Init();
GLCD_OFF();
disp_Battery(4);
/*
uint8_t rtc_second = 34; //秒
uint8_t rtc_minute = 43; //分
uint8_t rtc_hour = 10; //时
uint8_t rtc_day = 0; //日
uint8_t rtc_month = 0; //月
uint16_t rtc_year = 0; //年
uint8_t rtc_week = 0; //周
uint16_t year = 0;
disp_Battery(4);
disp_num(3, rtc_minute/10);disp_num(4, rtc_minute%10);
disp_num(5, rtc_second/10);disp_num(6, rtc_second%10);
*/
uint8_t voltage_1 = 0;
uint8_t voltage_2 = 0;
static adc_info_t adc_info ;
static double die_temperature = 0 ;
static double V1 = 0;
static double Vs = 0;
printf("\r\n测量RA4L1 Sensor开发板芯片温度\r\n");
while(1)
{
(void) R_ADC_ScanStart(&g_adc0_ctrl);
scan_complete_flag = false;
while (!scan_complete_flag)
{
}
err = R_ADC_Read(&g_adc0_ctrl, ADC_CHANNEL_TEMPERATURE, &adc_data1);
assert(FSP_SUCCESS == err);
err = R_ADC_InfoGet(&g_adc0_ctrl, &adc_info);
assert(FSP_SUCCESS == err);
V1 = ( 3.3 * (int) adc_info.calibration_data ) / 4096 ;
Vs = ( 3.3 * (int) adc_data1 ) / 4096 ;
die_temperature = CONSTANT * ( Vs - V1 ) / ( adc_info.slope_microvolts ) + 125.0;
static char string_die_temp[10] = {0};
sprintf( string_die_temp, "%.2f", die_temperature );
int a = (int)(die_temperature*100);
disp_num(3, (a/100)/10);disp_num(4, (a/100)%10);
disp_num(5, (a%100)/10);disp_num(6, (a%100)%10);
printf("RA4L1 Sensor开发板芯片当前温度是: %s 度\r\n", string_die_temp);

烧录代码到板子,打开串口助手

查看断码屏显示的温度

结果一致,到此正确读取到了RA4L1板子的实时温度值。