cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 internal temp sensor

arganasss
Associate II
Posted on March 07, 2014 at 13:37

The original post was too long to process during our migration. Please click on the attachment to read the original post.
9 REPLIES 9
Posted on March 07, 2014 at 15:57

I'm not going to do the math, is ADC_SampleTime_7Cycles5  >2.2 us?

Also as you're not starting EACH conversion, perhaps you need to use CONTINUOUS mode?

Not sure I'd do the conversion/printf in the USART's RXNE interrupt, do you have a better method for doing this? Does the sampling work if you sit in a loop starting and printing conversion values?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
arganasss
Associate II
Posted on March 07, 2014 at 16:22

1) Yes, ADC_SampleTime_7Cycles5  is > 2.2 us.

2) It doesn't metter where i do the ADC conversion. I just did that in Rx interrupt because i need to transmit converted data via USART. Please, suggest a better way to do this?

3) I caught myself on this one, sitting in a loop and doing conversion doesn't work, because i never got through this flag which is on the main: while(ADC_GetCalibrationStatus(ADC1) != RESET );

If i comment this line, then the code stops at this: while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY));

So the code cant pass through both of these flags.

Do you have any ideas why is that?

Posted on March 07, 2014 at 23:23

// STM32 ADC TEMP STM32F3-Discovery - sourcer32@gmail.com
/**************************************************************************************/
#include ''stm32f3_discovery.h''
#include ''stm32f30x.h''
#include <
stdio.h
>
/**************************************************************************************/
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
volatile int i;
uint16_t CalibrationValue;
/* Configure the ADC clocks */
RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div1);
/* Enable ADC1/2 clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);
/* ADC Calibration procedure */
ADC_VoltageRegulatorCmd(ADC1, ENABLE);
/* Insert delay equal to 10 us */
for(i=0; i<
10000
; i++);
ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1) != RESET);
CalibrationValue
= 
ADC_GetCalibrationValue
(ADC1);
/* ADC configuration */
ADC_CommonInitStructure.ADC_Mode
= 
ADC_Mode_Independent
;
ADC_CommonInitStructure.ADC_Clock
= 
ADC_Clock_AsynClkMode
;
ADC_CommonInitStructure.ADC_DMAAccessMode
= 
ADC_DMAAccessMode_Disabled
; // Not Multi Mode
ADC_CommonInitStructure.ADC_DMAMode
= 
ADC_DMAMode_Circular
;
ADC_CommonInitStructure.ADC_TwoSamplingDelay
= 
ADC_SampleTime_2Cycles5
;
ADC_CommonInit(ADC1, &ADC_CommonInitStructure);
/* */
ADC_InitStructure.ADC_ContinuousConvMode
= 
ADC_ContinuousConvMode_Disable
; // Manual Trigger
ADC_InitStructure.ADC_Resolution
= 
ADC_Resolution_12b
;
ADC_InitStructure.ADC_ExternalTrigEventEdge
= 
ADC_ExternalTrigEventEdge_None
;
ADC_InitStructure.ADC_ExternalTrigConvEvent
= 
ADC_ExternalTrigConvEvent_3
; // Not used here
ADC_InitStructure.ADC_DataAlign
= 
ADC_DataAlign_Right
;
ADC_InitStructure.ADC_OverrunMode
= 
ADC_OverrunMode_Disable
;
ADC_InitStructure.ADC_AutoInjMode
= 
ADC_AutoInjec_Disable
;
ADC_InitStructure.ADC_NbrOfRegChannel
= 
1
;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_TempSensor, 1, ADC_SampleTime_61Cycles5);
/* Enable Temp channel */
ADC_TempSensorCmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* wait for ADC1 ADRDY */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY));
}
/**************************************************************************************/
int main(void)
{
uint16_t ADCConvertedValue;
/* Initialize LEDs available on STM32F3-Discovery board */
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
/* Turn on LD3 */
STM_EVAL_LEDOn(LED3);
STM_EVAL_LEDOn(LED4);
ADC_Configuration();
while(1) // Don't want to exit
{
/* Start ADC1 Software Conversion */
ADC_StartConversion(ADC1);
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
ADCConvertedValue
= 
ADC_GetConversionValue
(ADC1);
printf(''%03
X'', ADCConvertedValue); // 0x6DB on my test
STM_EVAL_LEDToggle(LED3);
}
}
//******************************************************************************
// Rough SWV support in Keil, STM32F3-Discovery, Make SB10 to connect PB3/SWO
//******************************************************************************
#include <rt_misc.h>
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f)
{
ITM_SendChar(ch);
return(ch);
}
int fgetc(FILE *f)
{
return(-1);
}
int ferror(FILE *f)
{
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch)
{
ITM_SendChar(ch);
}
void _sys_exit(int return_code)
{
label: goto label; /* endless loop */
}
//******************************************************************************
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d

'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
//******************************************************************************

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
arganasss
Associate II
Posted on March 10, 2014 at 14:19

Thanks for this example code. Now everything works and i found out my mistakes. I want to ask few questions, so if you could explain it, i would appreciate it a lot. Whats the difference between sampling times in these two commands, and why they are different?

ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_SampleTime_2Cycles5;


ADC_RegularChannelConfig(ADC1, ADC_Channel_TempSensor,

1

, ADC_SampleTime_61Cycles5); Now another question. I need now to connect another, external temperature sensor, and i need these two temperatures. From external temp sensor and from internal. So can i connect that external temp sensor to any ADC channel? And now if i need both these values, should i use DMA? And of course the best place to do all the conversions are in the while loop? And i should use usart irq handler just for sending values to the terminal? Is this correct? I appreciate your help very much.
Posted on March 10, 2014 at 14:56

I believe the two sampling delay impact inter-sampling delays in multi ADC configurations. I don't have the manual to hand. The sample time for the channel itself in the RegularChannelConfig, I pick something I felt was reasonable, you could probably tighten this up.

Yes, so an external source, you have to pick a pin/channel to suit. You'd need to select all your channels, and have them scan. You'd want to use a circular DMA buffer, interrupting on a TC, or HT for a double size buffer, would permit you to examine both results as a combined EOC signal. If you don't need it all the time, I'd probably set up the periodicity with a timer, and have it trigger the ADC, and again just interrupt with the DMA when ready. This would avoid any spinning in loops wait for the ADC to do the conversions. Even if you didn't use the interrupts, the variables would automatically update at the chosen periodicity.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cmessineo1965
Associate
Posted on April 03, 2014 at 20:26

Are these the correct values for V25 and Avg_Slope for the STM32F3 Discovery board:

uint16_t V25 = 1933;// when V25=1.41V at ref 3.3V

float Avg_Slope = 5.33; //when avg_slope=4.3mV/C at ref 3.3V

Posted on April 03, 2014 at 21:09

Doesn't the board run the chip at 3V?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
fjanus
Associate
Posted on July 22, 2014 at 16:07

Hello Colleagues,

where the heck ist the calibration value to be found?

The data sheet states: ''

To improve the accuracy of the temperature sensor measurement,

each device is individually factory-calibrated by ST. The temperature sensor factory calibration data are stored by ST in the system memory area, accessible in read-only mode.''

Can anyone point me to the right loaction?

rgds

Posted on July 22, 2014 at 17:24

http://www.st.com/web/en/resource/technical/document/datasheet/DM00058181.pdf

0690X000006036UQAQ.jpg
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..