AnsweredAssumed Answered

Problem with ADC interruptsin continuous mode

Question asked by elshenawy.mohamed on Nov 30, 2014
Latest reply on Dec 2, 2014 by elshenawy.mohamed
Hi , I have a problem in the program after enabling the ADC interrupt , The processor doesn't do anything after starting ADC_READ
Here is a simple program which reads data from ADC in continuous mode and when the conversion ends it calls the ADC interrupt handler to send these data to USART and be displayed on the terminal  and All of this works fine and the data are displayed continuously.

When I tried to add lines of code after the function TM_ADC_Read ,These lines are not executed  (for example in this example I am setting pin A6 and Pin A4 , but they are not set!)

void EnableADCInterrupts(void )
   NVIC_InitTypeDef nvicStructure;
    nvicStructure.NVIC_IRQChannel = ADC_IRQn ;
    nvicStructure.NVIC_IRQChannelPreemptionPriority = 2;
    nvicStructure.NVIC_IRQChannelSubPriority = 2;
/*There are no other interrupts enabled in my code , However I gave*/ /*those the value 2 and I tried to give them all value to 15 and the problem exists*/
   nvicStructure.NVIC_IRQChannelCmd = ENABLE;
int main(void) {
    /* Initialize system */
    /* Initialize Delay library */
     /* Initialize USART1, 115200baud, TX: PB6 */
    TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
    EnableADCInterrupts(); /*After calling this function problems happened, see downwards*/
    /* Initialize ADC1 on channel 5, this is pin PA5 */
   TM_ADC_Init(ADC1, ADC_Channel_5);
    TM_USART_Puts(USART1 , "USART IS OKAY  \n \r");
        sprintf(str, "%4d: \n\r", TM_ADC_Read(ADC1, ADC_Channel_5));
  /* Put to USART *
        TM_USART_Puts(USART1, str);
/**These two functions don't execute after I called EnableAdcInterrupts**/
        GPIO_WriteBit(GPIOD , GPIO_Pin_5 , Bit_SET);
     GPIO_WriteBit(GPIOD , GPIO_Pin_4 , Bit_SET);
    /* Little delay */
while (1);
void ADC_IRQHandler (void)
    if (ADC_GetITStatus( ADC1,ADC_IT_EOC) != RESET)
        /* Send reading to USART6*/
    sprintf(str, "%4d: \n\r", TM_ADC_Read(ADC1, ADC_Channel_5));
        /* Put to USART */
        TM_USART_Puts(USART1, str);
ADC_ClearITPendingBit( ADC1, ADC_IT_EOC);

void InitializeGP(void)
     GPIO_InitTypeDef gpioStructureD,gpioStructureA,gpioStructureB;
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
     gpioStructureD.GPIO_Pin=0x0030;  // GPIO_Pin_5|GPIO_Pin_4;
     gpioStructureD.GPIO_Mode = GPIO_Mode_OUT;
     GPIO_Init(GPIOD, &gpioStructureD);

The PA6 and PA4 pins are not set , however when I disable the interrupt through the function EnableAdcInterrupt , they work fine .

would Any one tell me why this problem happens?