1.STM32 There is an internal temperature sensor , It can be used to measure CPU And the surrounding temperature (TA).
2. The temperature sensor is internally and externally mounted ADCx_IN16 The input channels are connected , This channel converts the output voltage of the sensor into a digital value . 3. What is the recommended sampling time for analog input of temperature sensor 17.1μs.
4.STM32 The internal temperature sensor of supports a temperature range of :-40~125 degree . The accuracy is poor , by ±1.5℃ about . The internal temperature sensor is more suitable for detecting the change of temperature , Instead of measuring absolute temperature .
If it is necessary to measure the absolute temperature , An external temperature sensor should be used .

Next, we start to configure the internal temperature of the chip :【 To put it bluntly, the internal temperature sensor still belongs to ADC Part of , therefore , To understand internal sensors, you have to ADC Configuration of 】
void Adc_Temperature_Init(void) { // The first step : open PA Clock and ADC1 Access to 16 My clock . ADC_InitTypeDef
ADC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
RCC_APB2Periph_ADC1,ENABLE); // Step two : reset ADC1, And set ADC1 The frequency division factor of the system , Give Way ADC1 How much do you work in Mhz. //
No more than 14MHz. Then we will 6 frequency division , Let it work in 12Mhz, because ADC Mount on // APB2 Under the bus , It corresponds to PCLK2 My clock ,72/6=12;
RCC_ADCCLKConfig(RCC_PCLK2_Div6);// ADC_DeInit(ADC1);//ADC1 De initialization
// The third step : initialization ADC1 Related parameters of , set up ADC1 The working mode of the rule sequence and the related information of the rule sequence
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; // Working in the first mock exam mode instead of the cycle mode.
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;// Align data right
ADC_InitStructure.ADC_ExternalTrigConv =
ADC_ExternalTrigConv_None;// There is no external starting point for conversion . It is triggered by software conversion ADC_InitStructure.ADC_Mode
= ADC_Mode_Independent; // Independent mode ADC_InitStructure.ADC_NbrOfChannel = 1;
// Rule transformation in order ADC1 Number of channels . There's only one access . ADC_InitStructure.ADC_ScanConvMode = DISABLE;
// Scan mode off . Scan mode is used to scan a group of channels. Here we only use one channel , You don't use scan mode , So it's disabled
ADC_Init(ADC1,&ADC_InitStructure);//ADC1 Initialization of .
ADC_TempSensorVrefintCmd(ENABLE);// This step should not be forgotten .AD The configuration of the channel is almost finished , It's time to turn on the internal temperature sensor .
// Step four : Enable ADC1 And calibration ADC1,【 Do the de calibration before calibration , Wait for the calibration to be completed before calibration 】 ADC_Cmd(ADC1,ENABLE);
ADC_GetResetCalibrationStatus(ADC1);//ADC1 To calibrate
// Wait for the calibration to complete .*// When not playing school, it's time 1, How about death in the loop . Wait for the footnotes to complete ,ADC->CR2 Position in 3 It becomes 0, Just jump out of the loop . ha-ha
ADC_StartCalibration(ADC1);//ADC1 Start calibration
while(ADC_GetCalibrationStatus(ADC1));// Wait for calibration to complete }
ps:【 The part in italics above :while(ADC_GetResetCalibrationStatus(ADC1)); // Wait for the calibration to complete .】
RSTCAL: Reset calibration
This bit is set by software and cleared by hardware . This bit will be cleared after the calibration register is initialized .
0: Calibration register initialized
1: Initialize calibration register
notes : When conversion is in progress , If set RSTCAL, An additional cycle is required to clear the calibration register

// obtain AD Transformation value function
u16 Get_Adc(u8 ch) { // Step five : Configure working channel parameters , Set the specified ADC Number of regular channels , A sequence , Sampling time 239.5 Cycles
ADC_RegularChannelConfig(ADC1,ch,ADC_SampleTime_239Cycles5);//ADC1,ADC passageway 16, A sequence , Sampling time 239.5 Cycles
// Step six : Turn on the software conversion function ADC_SoftwareStartConvCmd(ADC1,ENABLE);// Enable ADC1 Software conversion function of
while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC) != RESET);// Wait for the conversion to complete return
ADC_GetConversionValue(ADC1);// To convert AD Value is returned . }
Got it ADC Sampling value of internal temperature sensor . Value taking 10 Second average , More accurate .
u16 T_Get_Temp(void) { u16 temp_val=0; u8 t; for(t=0;t<10;t++) {
temp_val+=Get_Adc(ADC_Channel_16); //TampSensor delay_ms(5); } return
temp_val/10; }
// Get the channel ch Conversion average of . take times Second, then average .
u16 T_Get_Adc_Average(u8 ch,u8 times) { u32 temp_val=0; u8 t;
for(t=0;t<times;t++) { temp_val+=Get_Adc(ch); delay_ms(5); } return
temp_val/times; }
// Get the temperature value . The temperature value expanded 100 times , Company : centigrade .
short Get_Temprate(void) // Obtain the temperature value of the internal temperature sensor { u32 adcx; short result; double
temperate; adcx=T_Get_Adc_Average(ADC_Channel_16,20); // passageway 16, read 20 second
temperate=(float)adcx*(3.3/4096); // The obtained voltage value .
temperate=(1.43-temperate)/0.0043+25; // Convert to temperature value result=temperate*=100;
// expand 100 times . OK, put it on the table LCD Display on return result; }

©2019-2020 Toolsou All rights reserved,
Huawei 2021 session Hardware Engineer Logical post (FPGA) Super detailed surface !!!Vue-element-admin upgrade ui edition virtual machine VMware Download and install the most detailed tutorial !C++ Move constructor and copy constructor sound of dripping water java Backstage interview pygame Realize full screen mode and adjustable window size mysql Database setting character set configuration modification my.ini file (windows)30 What's the experience of being a junior programmer at the age of 20 C++ Multithreading programming ( Summary of common functions and parameters )python_ cherry tree