2022-12-11 09:43 AM
I've been trying to use the ADC of an STM32F7 so that when the level exceeds a certain threshold it start to sample the input continuously. Here is the configuration.
Then I have implemented the code as follows
volatile ITStatus adc1OutOfWindow = RESET;
void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef *hadc)
{
HAL_GPIO_WritePin(LED_BOARD_GREEN_GPIO_Port, LED_BOARD_GREEN_Pin, GPIO_PIN_SET);
if (hadc == &hadc1)
{
if (adc1OutOfWindow == RESET)
{
adc1OutOfWindow = SET;
HAL_ADC_Start_DMA(&hadc1, (uint32_t*) adc1DoubleBuffer, ADC_DOUBLE_BUFFER_SIZE);
}
}
}
// Called when first half of buffer is filled
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef *hadc)
{
if (hadc == &hadc1)
{
osMessageQueuePut(mqAdc1Dma, &adcFirstHalfMsg, 0U, 0U);
}
}
// Called when buffer is completely filled
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
{
if (hadc == &hadc1)
{
osMessageQueuePut(mqAdc1Dma, &adcSecondHalfMsg, 0U, 0U);
}
}
Then the DAM is handle in an RTOS task
void taskADC1(void *args)
{
HAL_ADC_Start_IT(_hadc1);
while (1)
{
if (osMessageQueueGet(mqAdc1Dma, &adcDmaMsg, 0U, 1000) == osOK)
{
/* Som computation */
if (adcMeanValue < 1500)
{
adc1OutOfWindow = RESET;
HAL_ADC_Stop_DMA(_hadc1);
HAL_GPIO_WritePin(LED_BOARD_RED_GPIO_Port, LED_BOARD_RED_Pin, GPIO_PIN_RESET);
}
}
else
{
HAL_GPIO_TogglePin(LED_BOARD_GREEN_GPIO_Port, LED_BOARD_GREEN_Pin);
}
}
}
But the LevelOutOfWindow callback doesn't seem to trigger,
Is there a way use both DMA and the watchdog feature?
2022-12-13 12:55 AM
Hello @JVALL.1,
At the end of data transfer, in conversion complete callback, you should prevent continuous overwriting by using HAL_ADC_Stop_DMA()
You should wait until DMA stops.
You can check this post for a similar application
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.