cancel
Showing results for 
Search instead for 
Did you mean: 

EOC ADC INTERRUPT

gdiez
Associate II
Posted on August 31, 2010 at 09:51

EOC ADC INTERRUPT

15 REPLIES 15
gdiez
Associate II
Posted on May 17, 2011 at 14:04

I´ve found my error. I´d not configure the nested Interrupt vector hehehe

void NVIC_configuration(void)

{

   NVIC_InitTypeDef NVIC_InitStructure;

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */  

#ifndef  EMB_FLASH

  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);      /* Set the Vector Table base location at 0x20000000 */

#else   

  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);    /* Set the Vector Table base location at 0x08000000 */

#endif

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

 /* Configure and enable ADC interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQChannel;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure); 

}

gdiez
Associate II
Posted on May 17, 2011 at 14:04

Does anyone know why I cant clear EOC flag?

Have i clear another bit, SCAN, CONT or something?

gdiez
Associate II
Posted on May 17, 2011 at 14:04

I suffocate in a water glass.

My program enters in the ADC Interrupt but I can´t reset EOC flag. What is the matter with my code?

void ADC_IRQHandler(void)

{

   IT_tick=1;

   ADC1ConvertedValue = ADC1->DR;   /* Dato convertido */

   ADC1->SR &=~ 0x0000001F;                                       /* DOESN´T WRITES SR */

   /* ADC_ClearITPendingBit(ADC1, ADC_IT_EOC); */ /* DOESN´T WRITES SR EITHER*/

 

}

John F.
Senior
Posted on May 17, 2011 at 14:04

Hi,

You need to read the Manual RM0008.

EOC: End of conversion: This bit is set by hardware at the end of a group channel conversion (regular or injected). It is cleared by software or by reading the ADC_DR.

The EOC bit is of type ''read/clear (rc_w0)''

Software can read as well as clear this bit by writing 0. Writing ‘1’ has no effect on

the bit value.

So you must write a zero directly to the register to clear the bit.

John F.

gdiez
Associate II
Posted on May 17, 2011 at 14:04

Thks for replying. I´d read that but it doesn´t works. My code is the following one:

void ADC_IRQHandler(void)

{

IT_tick=1;

ADC1ConvertedValue = ADC1->DR; /*

READ. IT DOESN´T CLEAR EOC Flag*/

ADC1->SR &=~ 0x00000002; /*

DOESN´T WRITES SR, SO DOESN´T CLEAR EOC Flag */

ADC_ClearITPendingBit(ADC1, ADC_IT_EOC); /*

LIBRARY FUNCTION. DOESN´T WRITES SR EITHER */

}

Must i do anything else to clear this bit?

My programm stays in the ISR ever.

0690X0000060MlNQAU.gif

lipin
Associate II
Posted on May 17, 2011 at 14:04

Did you check if you really entered ISR? 

You maybe using default isr implementation which is loop. In my vector table ADC handler is called:

ADC1_2_IRQHandler or ADC1_IRQHandler depends on target device.

not

ADC_IRQHandler

Regards

Thomas

John F.
Senior
Posted on May 17, 2011 at 14:04

ADC status register (ADC_SR) Bits 31:5 Reserved, must be kept cleared.

ADC1->SR &=~ 0x00000002;

isn't the same as

ADC1->SR = 0x0000001D

... and you should clear the ADC pending bit using ADC_ClearITPendingBit() function in your ADC routine too of course!

John F.

lipin
Associate II
Posted on May 17, 2011 at 14:04

Your code works on my uc and ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);  quits intterupt or by reading DR value as John F. mentioned.

Dunno about your naming aliases but only changes I made are:

NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;

ADC1_2_IRQHandler

and adding GPIO init.

Remeber that you have

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

so it reenters interrupt as soon as next conversion is done. 

Regards

gdiez
Associate II
Posted on May 17, 2011 at 14:04

ISR

void ADC_IRQHandler(void)

{  

    IT_tick=1;

    ADC1ConvertedValue = ADC1->DR; 

    ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);

}

//====================================================

MAIN

while(1){     

        if(IT_tick){

          IT_tick=0;        

         }

       

    } /* END of WHILE */

//====================================================

The programm doesn´t enter never in main if. In debug mode in step by step mode, as soon as the ISR finishes, the program enters again. If it would works ok, it must enter in it.

If i have

ADC_CR2.CONT=0 Continuous mode OFF

The programs enters once in the ISR and stop. It enters with out EOC flag(??)

It works like it must to do. I tried to start ADC conversion on ISR then but i cant.

How could do i that?

ADC_SR.STRT=1 // Regular channel Start Flag

 

ADC_CR1.EOCIE=1 // Interrupt enable for EOC

 

ADC_CR1.SCAN=1 // Scan mode enabled

 

ADC_CR2.ADON=1 // A/D Converter ON

ADC_CR2.EXTSEL=111 // External Event select for regular group = SWSTART

ADC_CR2.EXTRIG=1 // Conversion on external event enabled

In this moment NVIC registers are: See RM0008 (Vector table for connectivity line devices) ADC1_2 is position 18

NVIC_ISR0.SETENA[18] = 1 // Interrupt ADC1_2 enabled

NVIC_ICR0.CLRENA[18] = 1 // Interrupt ADC1_2 enabled.

NVIC_IABR0.ACTIVE[18] = 1 // Interrupt ADC1_2 actived

NVIC_ICPR0.CLRPEND[18] = 0 // Interrupt ADC1_2 no pending

If i have

ADC_CR2.CONT=1 Continuous mode ON

The programs never leaves the ISR (Even step by step in debug mode). It never enters in main If. In normal mode I think it must do it. It enters with EOC flag

ADC_SR.STRT=1 // Regular channel Start Flag

ADC_CR1.EOCIE=1 // Interrupt enable for EOC

 

ADC_CR1.SCAN=1 // Scan mode enabled

 

ADC_CR2.CONT=1 // Continuous mode

 

ADC_CR2.ADON=1 // A/D Converter ON

 

ADC_CR2.EXTSEL=111 // External Event select for regular group = SWSTART

ADC_CR2.EXTRIG=1 // Conversion on external event enabled

NVIC_ISR0.SETENA[18] = 1 // Interrupt ADC1_2 enabled

NVIC_ICR0.CLRENA[18] = 1 // Interrupt ADC1_2 enabled.

NVIC_IABR0.ACTIVE[18] = 1 // Interrupt ADC1_2 actived

NVIC_ICPR0.CLRPEND[18] = 1 // Interrupt ADC1_2 pending

I´ve tried to clear ADC_SR.EOC( I cant). I´ve tried to set NVIC_ICPR[0].CLRPEND[18]=1 to clear the ADC pending bit but I couldn´t.

If i have ADC_CR2.CONT=1:

I cant write on ADC_SR Register in any way of do it.

ADC1->SR = 0x0000001D;

ADC1->SR & = 0x0000001D;

ADC1->SR &=~ 0x00000002;