cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to use analog watchdog without adc interrupt?

SShir.2
Associate II

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]));

}

2 REPLIES 2
S.Ma
Principal

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.

SShir.2
Associate II

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]));