2018-02-03 07:11 AM
Hi all,
i'm working with a STM32L053 processor and I'm having some trouble managing the ADC.
My ADC is setup to work in discontinuous mode, so i set the channel to convert by using the
following function:
void systemConfig_SetupTemperatureChannel(void)
{ ADC_ChannelConfTypeDef sConfig;/**Configure for the selected ADC regular channel to be converted.
*/ sConfig.Channel = ADC_CHANNEL_4; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }}void systemConfig_ResetTemperatureChannel(void)
{ ADC_ChannelConfTypeDef sConfig;/**Configure for the selected ADC regular channel to be converted.
*/ sConfig.Channel = ADC_CHANNEL_4; sConfig.Rank = ADC_RANK_NONE; if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }}void systemConfig_SetupReferenceVoltageChannel(void)
{ ADC_ChannelConfTypeDef sConfig;/**Configure for the selected ADC regular channel to be converted.
*/ sConfig.Channel = ADC_CHANNEL_5; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }}void systemConfig_ResetReferenceVoltageChannel(void)
{ ADC_ChannelConfTypeDef sConfig;/**Configure for the selected ADC regular channel to be converted.
*/ sConfig.Channel = ADC_CHANNEL_5; sConfig.Rank =ADC_RANK_NONE
; if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }}The function are called in the main loop like there:
main()
{
systemConfig_SetupTemperatureChannel();
.
.
/* Get value */
HAL_ADC_Start_DMA(&hadc, vectorPointerA, sampleNumber);
HAL_Delay(1000);
/* Reset Temp Channell */
systemConfig_
Reset
TemperatureChannel();
/* Set Voltage Ref Channell*/
systemConfig_SetupReferenceVoltageChannel();
/* Get value */
HAL_ADC_Start_DMA(&hadc, vectorPointerB, sampleNumber);
/*Reset Reference Channel*/
systemConfig_
Reset
ReferenceVoltageChannel();
HAL_Delay(1000);
}
Now if i debug step by step all the conversion are made perfectly in the correct channell.
Istead if the program run, the channell 5 is not set correctly and set to 0. I test that with abreakpoin to the row :
HAL_ADC_Start_DMA(&hadc, vectorPointerB, sampleNumber);
and loocking the recister of the channell selection that is set to 0.
Can anyone help?