Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 7 months ago.
DISCO_L476
Hello
I am trying hard to use the internal temperature sensor of the Discovery Board STM32L476.
Unfortuantely the ADC does not start. Are there any examples available?
I read the addresses TS_CAL1 and TS_CAL2.
Thanks Norbert
2 Answers
8 years, 7 months ago.
Here is my code to use the internal temp sensor on a nucleo-L073.
/* Peripheral clock enable */ __ADC1_CLK_ENABLE(); HAL_ADC_DeInit(&hadc); // Configure ADC hadc.Instance = ADC1; hadc.Init.OversamplingMode = DISABLE; hadc.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; hadc.Init.Resolution = ADC_RESOLUTION12b; hadc.Init.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc.Init.ContinuousConvMode = ENABLE; hadc.Init.DiscontinuousConvMode = DISABLE; hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIG_EDGE_NONE; hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIG0_T6_TRGO; // Not used here hadc.Init.DMAContinuousRequests = DISABLE; hadc.Init.EOCSelection = ADC_EOC_SEQ_CONV; hadc.Init.Overrun = OVR_DATA_OVERWRITTEN; hadc.Init.LowPowerAutoWait = ENABLE; hadc.Init.LowPowerFrequencyMode = DISABLE; // To be enabled only if ADC clock < 2.8 MHz hadc.Init.LowPowerAutoPowerOff = DISABLE; if(HAL_ADC_Init(&hadc) != HAL_OK) { error("Cannot initialize ADC"); } // Calibration HAL_ADCEx_Calibration_Start(&hadc, ADC_SINGLE_ENDED); __HAL_ADC_ENABLE(&hadc); //ADC1->CHSELR = 0; ADC_ChannelConfTypeDef sConfig; //TEMPSENSOR sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; if(HAL_ADC_ConfigChannel(&hadc, &sConfig)!=HAL_OK){ error("Cannot configure channel"); } HAL_ADCEx_EnableVREFINTTempSensor(); wait(0.5); HAL_ADC_Start(&hadc);
I use the fonction HAL_ADC_GetValue to read the ADC value. I don't know if it helps.
8 years, 7 months ago.
Here is a repository I posted a few weeks ago. Hopefully with this and Yohann's post above you can get it working. Post back if you're still stuck. https://developer.mbed.org/users/sixBase3/code/Nucleo_read_analog_value_intADCch/
Your code is not working since you didnt "turn on" internal temp sensor. You can measure voltage on it's pin, but it will be constant thrash. There is no problems to read. Problem - wake up sensor. I know how to do this directly, by cmsis, but they are not visible from mbed layer( strange). So question is actual.
posted by 21 Jul 2017