I am new to ARM world and using STM32F103C8T6 ARM microcontroller. In order to know more about microcontroller, I've googled nicrocontroller applications and its working principle, and I found an article from the first page named kynix semiconductor electronic blog. I want to get micro's internal temperature sensor working. I am able to get some data from it but I'm not sure how to convert these numbers into temperature. I looked it up on and I found that there is two read-only addresses in memory that hold factory calibration numbers at 30 and 110 degrees.
The problem is there is nothing about it in either datasheet or Reference Manual. There is only some minimums and maximums for parameters. I believe using average of these values may affect accuracy. So I'm confused. How should I do this conversion? Do I even need these factory calibration data? Do I have to self calibrate the ADC in this case?
Here is the code I used so far:
Thanks in advance!
The problem is there is nothing about it in either datasheet or Reference Manual. There is only some minimums and maximums for parameters. I believe using average of these values may affect accuracy. So I'm confused. How should I do this conversion? Do I even need these factory calibration data? Do I have to self calibrate the ADC in this case?
Here is the code I used so far:
Code:
#include "stm32f103xb.h"
int main(void)
{
// Select a clock source for ADC
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; // Enable ADC1 to use APB2 BUS
RCC->CR |= RCC_CR_HSION; // set the internal clock on (8MHz)
while((RCC->CR & RCC_CR_HSIRDY) == 0){} // wait until HSI is ready
RCC->CFGR &= ~(RCC_CFGR_HPRE); // set AHB prescaler to 1
RCC->CFGR &= ~(RCC_CFGR_PPRE2); // set APB2 prescaler to 1 (PCLK2)
RCC->CFGR |= RCC_CFGR_ADCPRE; // use ADC prescaler
// Select a Sampling rate
ADC1->SMPR1 |= ADC_SMPR1_SMP16;
ADC1->SQR3 |= ADC_SQR3_SQ1_4; //set to convert the channel 16 fitst
// enable temperature sensor
ADC1->CR2 |= ADC_CR2_TSVREFE;
// ADC Calibration
// Power up the ADC and then Calibrate it
ADC1->CR2 |= ADC_CR2_ADON | ADC_CR2_CAL | ADC_CR2_CONT;
// wait until the calibration is completed and reseted
while((ADC1->CR2 & ADC_CR2_CAL) == 1){}
while(1)
{
// Start
ADC1->CR2 |= ADC_CR2_ADON;
while((ADC1->SR & ADC_SR_EOC) == 0){} // wait for end of conversion
// Print the results on LCD
LCDSendInstruction(LCD_CLEAR);
LCDSendInteger(ADC1->DR,8);
}
}
Thanks in advance!