[GD32L233C-START Review] On-chip temperature detection and display
[Copy link]
This post was last edited by jinglixixi on 2022-2-16 12:08
The GD32L233C is equipped with a corresponding temperature detection channel, and the on-chip temperature can be detected with the help of the ADC analog-to-digital converter.
With the help of serial communication, the detection effect is shown in Figure 1 .
Figure 1 On-chip temperature detection
However, this is very inconvenient to use. If this function is combined with the display function of the OLED screen, it will be more intuitive and convenient. The implementation effect is shown in Figure 2 .
Figure 2 OLED screen display effect
So how is this achieved?
Since the display works in I2C mode, the clock and digital pins of the display can be directly connected to PB10 and PB11 of the development board , and the power supply can be connected to the 3.3V power supply.
After determining the hardware connection relationship, the next step is how to implement it with software.
Among them, the key is to have the support of digital display function, the content of this function is as follows:
void OLED_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t size2)
{
uint8_t t,temp;
uint8_t enshow=0;
for(t=0;t<len;t++)
{
temp=(num/oled_pow(10,len-t-1))%10;
if(enshow==0&&t<(len-1))
{
if(temp==0)
{
OLED_ShowChar(x+(size2/2)*t,y,' ',size2);
continue;
}
else enshow=1;
}
OLED_ShowChar(x+(size2/2)*t,y,temp+'0',size2);
}
}
In order to facilitate the display and verification of the detection, the main program of the on-chip temperature detection is:
int main(void)
{
uint32_t a,b;
systick_config();
rcu_config();
adc_config();
gd_eval_com_init(EVAL_COM);
usart_transmit_config(EVAL_COM, USART_TRANSMIT_ENABLE);
rcu_periph_clock_enable(RCU_GPIOB);
gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_10 | GPIO_PIN_11);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10 | GPIO_PIN_11);
delay_1ms(500);
OLED_Init();
OLED_Clear();
OLED_ShowString(8,0,"GD32L233C_START",16);
OLED_ShowString(8,2,"Temp= .",16);
OLED_ShowString(8,4,"voltage= .",16);
while(1) {
adc_software_trigger_enable(ADC_INSERTED_CHANNEL);
delay_1ms(2000U);
value = (int32_t)ADC_TEMP_CALIBRATION_VALUE;
temperature = ((float)((int32_t)ADC_IDATA0 - value) * 3.3f / 4095 * 1000 / 3.3f) + 30;
vref_value = (ADC_IDATA1 * 3.3f / 4095);
printf(" the Temperature data is %2.1f degrees Celsius\r\n", temperature);
printf(" the Reference voltage data is %5.3fV \r\n", vref_value);
printf(" \r\n");
a=(uint32_t) (temperature);
OLED_ShowNum(48,2,a,2,16);
a=(uint32_t) (temperature*100)%100;
OLED_ShowNum(72,2,a,2,16);
b=(uint32_t) vref_value;
OLED_ShowNum(72,4,b,1,16);
b=(uint32_t) (vref_value*1000)% 1000;
OLED_ShowNum(88,4,b,3,16);
}
}
After compiling and downloading the program, the displayed value is consistent with the output content of the serial port, which means that the program is correct and valid.
|