2021-09-05 09:42 PM
I am thinking of turning on ADC with DMA when analog watchdog detect certain level of signal. Then I would like to turn on ADC with only watchdog first and when LevelOutOfWindowCallback() is called ADC with DMA starts. I tried code below but it didn't work. It seems that watchdog never started or worked.
Please teach me how to do that.
Thank you.
int main(void){
configurations
HAL_ADC_Start(&hadc1);
ADC1->CR1|=(1<<23);
ADC1->CR1|=(1<<1);
ADC1->SR &= ~(1 << 0);
HAL_TIM_Base_Start(&htim2);
while(1){
}
}
void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc){
HAL_ADC_Start_DMA(&hadc1,(uint32_t*)DMA_buf,sizeof(DMA_buf)/sizeof(DMA_buf[0]));
}
2021-09-05 11:03 PM
If you use hal, use it too for watchdog interrupt too. And if you only need to trigger a range, DMA maybe only needed if you use ADC data as multichannel reading.
2021-09-05 11:56 PM
Thank you.
Just simply writing like below Both DMA and analog watchdog works. This is okay though, my ideal is to use ADC and watchdog separately. So I don't need any data which is out of threshold. So I would like to trigger to start DMA by LevelOutOfWindowCallback() . But when I only write HAL_ADC_Start_IT(&hadc1), LevelOutOfWindowCallback() is not called but when I write both HAL_ADC_Start_IT and HAL_ADC_Start_DMA. Is it possible to use only watchdog first without using DMA ?
HAL_ADC_Start_IT(&hadc1);
HAL_ADC_Start_DMA(&hadc1,(uint32_t*)DMA_buf,sizeof(DMA_buf)/sizeof(DMA_buf[0]));