2018-11-13 03:04 PM
In the while loop I have this:
HAL_ADC_PollForConversion(&hadc1, 1000);
adcValue = HAL_ADC_GetValue(&hadc1);
The ADC works okay until I execute this line, which is inside a function:
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);
HAL_Delay(3000);
command_dutyC = 0.5;
This delay is used just once in the whole program, i .e, when the delay's completed, it won't execute more.
The rest of the program continues working well after the delay, but the ADC gets stuck, it displays the same value all the time, even when the input is changing.
This is my ADC init:
static void MX_ADC1_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
/**Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV16;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.NbrOfDiscConversion = 1;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_247CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
Solved! Go to Solution.
2018-11-14 03:20 PM
Ok, and didn't I say that everything other than SysTick needs a priority >= 1
You're trying to ensure SysTick can interrupt whatever else is running/blocking, this isn't going to happen if everyone is set to zero. You'll spin in a loop and the tick count will never go up.
2018-11-13 04:47 PM
Remember the callbacks occur under interrupt context. You need to make SysTick (or other clocking source) can preempt all other interrupts.
2018-11-13 04:49 PM
How do I do that?
2018-11-13 05:21 PM
I'd supposed you'd make sure TICK_INT_PRIORITY is zero, that others are set higher, and the NVIC mode is set to 4-bit preemption mode.
Grep/Find-in-Files for HAL_NVIC_SetPriority, HAL_NVIC_SetPriorityGrouping in HAL_Init, etc.
2018-11-13 05:37 PM
Look
2018-11-14 10:17 AM
That's my NVIC configuration. I'm still having issues with the ADC after the delay.
2018-11-14 01:08 PM
What status is HAL_ADC_PollForConversion() returning when it fails (edit: change you code so that you DO check the return status, don't assume is works)? If that doesn't clear things up, use your debugger and single-step through the HAL_ADC_PollForConversion() function to see why it is failing.
2018-11-14 03:20 PM
Ok, and didn't I say that everything other than SysTick needs a priority >= 1
You're trying to ensure SysTick can interrupt whatever else is running/blocking, this isn't going to happen if everyone is set to zero. You'll spin in a loop and the tick count will never go up.
2020-01-08 01:08 PM
HAL_Delay() gets stuck because the system tick is not incremented. Simply include this function HAL_IncTick(); in the SysTick_Handler(void);
2020-01-08 01:40 PM
don't forget to start the ADC.