简体   繁体   中英

Stm32F4 ADC Analog watchdog interrupt doesnt work

Currently I am working on ADC analog watchdog,I want to write a interrupt code for Analog watchdog.I adjusted analog watchdog via reference manual of stm32f4xx and ı started ADC with dma and Analog watchdog timer for interrupt.But when ı run code interrupt doesnt work.What is the problem? My ADC and DMA Configurations

void adc_ayar()
{
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
  
  ADC_InitStruct.ADC_Resolution=ADC_Resolution_12b;
  ADC_InitStruct.ADC_ScanConvMode=ENABLE;
  ADC_InitStruct.ADC_ExternalTrigConvEdge=ADC_ExternalTrigConvEdge_None;
  ADC_InitStruct.ADC_ExternalTrigConv=0;
  ADC_InitStruct.ADC_DataAlign=ADC_DataAlign_Right;
  ADC_InitStruct.ADC_ContinuousConvMode=ENABLE;
  ADC_InitStruct.ADC_NbrOfConversion=bufferlength;
                                       
  ADC_Init(ADC1,&ADC_InitStruct);
  
  ADC_CommonInitStruct.ADC_DMAAccessMode=ADC_DMAAccessMode_Disabled;
  ADC_CommonInitStruct.ADC_Mode=ADC_Mode_Independent;
  ADC_CommonInitStruct.ADC_Prescaler=ADC_Prescaler_Div4;
  ADC_CommonInitStruct.ADC_TwoSamplingDelay=ADC_TwoSamplingDelay_20Cycles;
  
  ADC_CommonInit(&ADC_CommonInitStruct);
  ADC_Init(ADC1,&ADC_InitStruct);
  
  ADC_ITConfig(ADC1,ADC_IT_AWD,ENABLE);
  ADC_Cmd(ADC1,ENABLE);
  
  ADC_DMACmd(ADC1,ENABLE);
  ADC_DMARequestAfterLastTransferCmd(ADC1,ENABLE);
  
  ADC1->CR1|=1<<6|1<<23;
  ADC_AnalogWatchdogSingleChannelConfig(ADC1,ADC_Channel_0);
  ADC_AnalogWatchdogThresholdsConfig(ADC1,2500,300);
  ADC_AnalogWatchdogCmd(ADC1,ADC_AnalogWatchdog_SingleRegEnable);
  
  ADC_RegularChannelConfig(ADC1,ADC_Channel_0,1,ADC_SampleTime_3Cycles);
  
  ADC_ITConfig(ADC1,ADC_IT_AWD,ENABLE);
}
void dma_ayar()
{
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
  DMA_DeInit(DMA2_Stream0);
  
  DMA_InitStruct.DMA_Channel=DMA_Channel_0;
  DMA_InitStruct.DMA_Priority=DMA_Priority_VeryHigh;
  DMA_InitStruct.DMA_DIR=DMA_DIR_PeripheralToMemory;
  DMA_InitStruct.DMA_PeripheralBaseAddr=(uint32_t) & ADC1->DR;
  DMA_InitStruct.DMA_Memory0BaseAddr=(uint32_t) & adc_value;
  DMA_InitStruct.DMA_BufferSize=2;
  DMA_InitStruct.DMA_FIFOMode=DMA_FIFOMode_Enable;
  DMA_InitStruct.DMA_FIFOThreshold=DMA_FIFOThreshold_Full;
  DMA_InitStruct.DMA_MemoryBurst=DMA_MemoryBurst_Single;
  DMA_InitStruct.DMA_PeripheralBurst=DMA_PeripheralBurst_Single;
  DMA_InitStruct.DMA_Mode=DMA_Mode_Circular;
  DMA_InitStruct.DMA_MemoryDataSize=DMA_MemoryDataSize_HalfWord;
  DMA_InitStruct.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord;
  DMA_InitStruct.DMA_MemoryInc=DMA_MemoryInc_Enable;
  DMA_InitStruct.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
  
  DMA_Init(DMA2_Stream0,&DMA_InitStruct);
  
  DMA_Cmd(DMA2_Stream0,ENABLE);
}

ADC interrupt code

void ADC_IRQHandler()
{
  if(ADC_GetITStatus(ADC1,ADC_IT_AWD))
  {
    sayac++;
    GPIO_ToggleBits(GPIOD,GPIO_Pin_12|GPIO_Pin_13);
    
    ADC_ClearITPendingBit(ADC1,ADC_IT_AWD);
  }
}

If I have well understand what you want to do, you should use

void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef *hadc)

instead of

void ADC_IRQHandler()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM