cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Discovery AWD IRQ

markgilson9
Associate II
Posted on November 15, 2011 at 14:41

I have been able to successfully setup the ADC3 to set the SR, AWD flag when an input exceeds my threshold set.  What I am now looking to do is put the processor in sleep mode (via __WFI();) and then have it wake up via the AWD interrupt.  

Here is my ADC setup:

 

/* Configure ADC3 Channel12 pin as analog input ******************************/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

  /* ADC Common Init **********************************************************/

  ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;

  ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;

  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

  ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;

  ADC_CommonInit(&ADC_CommonInitStructure);

  /* ADC3 Init ****************************************************************/

  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

  ADC_InitStructure.ADC_ScanConvMode = DISABLE;

  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  ADC_InitStructure.ADC_NbrOfConversion = 1;

  ADC_Init(ADC3, &ADC_InitStructure);

  /* ADC3 regular channel12 configuration *************************************/

  ADC_RegularChannelConfig(ADC3, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);

 /* Enable DMA request after last transfer (Single-ADC mode) */

  ADC_DMARequestAfterLastTransferCmd(ADC3, ENABLE);

    ADC_AnalogWatchdogThresholdsConfig(ADC3, 0x300, 0x0);

    ADC_AnalogWatchdogSingleChannelConfig(ADC3, ADC_Channel_12);

    ADC_ClearFlag(ADC3, ADC_FLAG_AWD);

    ADC_AnalogWatchdogCmd(ADC3, ADC_AnalogWatchdog_SingleRegEnable);

ADC_ITConfig(ADC3, ADC_IT_AWD, ENABLE); // Enable ADC1 AWD interrupt

I then configure the NVIC register as follows:

  NVIC_InitTypeDef NVIC_InitStructure;

  /* Configure and enable ADC interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

When the AWD threshold is met, the processor never wakes up (regardless of ADC input).  I'm thinking I don't have an IRQ registered correctly, or I need to setup an IRQ Handler, but I'm not sure where to look for this.  Please advise, and thanks.
1 REPLY 1
picguy2
Associate II
Posted on November 18, 2011 at 05:32

WFI is Wait For Interrupt.  Thus you have to interrupt.  If you interrupt and don’t provide an ISR you will go to never land.  I would first put a breakpoint on the trap handler.  If it goes off you have your answer.  If not write a dummy handler, put a breakpoint on it and try to understand why no interrupt.