5315 views|5 replies

6818

Posts

11

Resources
The OP
 

【GD32F310G-START】ADC obtains the on-chip temperature and displays it [Copy link]

【GD32F310G-START】HELLO WORLD - GD32 MCU - Electronic Engineering World - Forum (eeworld.com.cn)

【GD32F310G-START】OLED HELLO EEWORLD——Hardware I2C - GD32 MCU - Electronic Engineering World-Forum

【GD32F310G-START】SPI driver ST7735 - GD32 MCU - Electronic Engineering World - Forum (eeworld.com.cn)

【GD32F310G-START】Hardware SPI driver for ST7735 - GD32 MCU - Electronic Engineering World - Forum (eeworld.com.cn)

ADC is one of the commonly used peripherals. Today, we will get the temperature value inside the chip according to the routine and display it on the LCD screen:

1. Initialize ADC:

/*!
    \brief      初始化ADC
    \param[in]  none
    \param[out] none
    \retval     none
*/
void my_adc_init(void)
{
  /*   开启时ADC时钟       */
    rcu_periph_clock_enable(RCU_ADC);
    /* config ADC clock */
    rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
    /* ADC channel length config */
    adc_channel_length_config(ADC_INSERTED_CHANNEL, 2U);
    
  /* ADC temperature sensor channel config */
    adc_inserted_channel_config(0U, ADC_CHANNEL_16, ADC_SAMPLETIME_239POINT5);
    /* ADC internal reference voltage channel config */
    adc_inserted_channel_config(1U, ADC_CHANNEL_17, ADC_SAMPLETIME_239POINT5);
  
   /* ADC trigger config */
    adc_external_trigger_source_config(ADC_INSERTED_CHANNEL, ADC_EXTTRIG_INSERTED_NONE);
    /* ADC data alignment config */
    adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
    /* ADC SCAN function enable */
    adc_special_function_config(ADC_SCAN_MODE, ENABLE);
    /* ADC temperature and Vrefint enable */
    adc_tempsensor_vrefint_enable();

    adc_external_trigger_config(ADC_INSERTED_CHANNEL, ENABLE);

    /* enable ADC interface */
    adc_enable();
    delay_1ms(1U);

    /* ADC calibration and reset calibration */
    adc_calibration_enable();
}

2. Get temperature:

float get_gd32f310g_temper(void)
{
float temperature;
adc_software_trigger_enable(ADC_INSERTED_CHANNEL);

/* value convert */
temperature = (1.45f - ADC_IDATA0 * 3.3f / 4096) * 1000 / 4.3f + 25;
return temperature;

}

3. Get the temperature in the main loop and scan it on the LCD screen:

main.c

#include "gd32f3x0.h"
#include "gd32f310g_eval.h"
#include "my_i2c.h"
#include "systick.h"
#include "ssd1306.h"
#include "lcd.h"
#include "lcd_init.h"
#include "adc.h"
uint8_t i2c_transmitter[16];

/*!
  \brief   main function
  \param[in]  none
  \param[out none
  \retval none
 */
int main(void)
{
    
  float temper_val;
  uint8_t str_temper[10];
  systick_config();
//  my_i2c0_init();
 // oled_display_test();
  LCD_Init();//LCD初始化
	LCD_Fill(0,0,LCD_W,LCD_H,BLUE);
	LCD_ShowString(12,0,"GD32F320G",WHITE,BLUE,32,0);
  LCD_ShowString(18,36,"EEWORDL",WHITE,BLUE,32,0);
  LCD_ShowString(16,72,"2022-5-7",BLACK,BLUE,32,0);
  LCD_ShowString(12,100,"gd32f310g_adc_demo",RED,BLUE,16,0);
  my_adc_init();
    /* infinite loop */
    while(1)
    {
      temper_val = get_gd32f310g_temper();
      sprintf(str_temper,"T:%.2f  ",temper_val);
      LCD_ShowString(18,36,str_temper,WHITE,BLUE,32,0);
      delay_1ms(500);
    }
}

Display effect:

【Summary】This can be easily accomplished through the ADC routine, but the on-chip temperature only reflects the temperature of the MCU, which is not proportional to the temperature of the external environment, so an external sensor is required to obtain the temperature.


This post is from GD32 MCU

Latest reply

really   Details Published on 2022-5-24 09:25
 

2

Posts

0

Resources
2
 

1

This post is from GD32 MCU

Comments

Hello, thank you for watching. I have a suggestion for you. If you reply seriously with more than 20 words, you will get points and prestige points.  Details Published on 2022-5-8 07:55
 
 
 

6818

Posts

11

Resources
3
 

Hello, thank you for watching. I have a suggestion for you. If you reply seriously with more than 20 words, you will get points and prestige points.

This post is from GD32 MCU
 
 
 

79

Posts

0

Resources
4
 

Great! I think adding an EOIC flag is more reasonable, but in fact, the temperature measurement here can already achieve the desired effect!

This post is from GD32 MCU

Comments

I asked GigaDevice, and they said that this temperature can only reflect the temperature inside the chip, and measuring the external temperature has no practical significance.  Details Published on 2022-5-22 20:47
 
 
 

6818

Posts

11

Resources
5
 
javnson posted on 2022-5-22 20:35 Like! I think adding an EOIC flag is more reasonable, but in fact, the temperature measurement here can already achieve the effect!

I asked GigaDevice, and they said that this temperature can only reflect the temperature inside the chip, and measuring the external temperature has no practical significance.

This post is from GD32 MCU

Comments

really  Details Published on 2022-5-24 09:25
 
 
 

79

Posts

0

Resources
6
 
lugl4313820 posted on 2022-5-22 20:47 I asked GigaDevice and they said that this temperature can only reflect the temperature inside the chip, and measuring the temperature outside has no practical significance.

really

This post is from GD32 MCU
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list