cancel
Showing results for 
Search instead for 
Did you mean: 

ADC interrupt in cosmic

navid_nikoonasiri
Associate
Posted on November 16, 2016 at 12:55

Dear all

I tried to read  ADC1 channels in stm8 in cosmic compiler, but still I could not. as far as the main program start to config the ADC1 initialization nothing happen. I do not know what the problem is with interrupts. there is no error in builder. hex files came out.

void ADC_CONFIG(void)

{

    ADC1_DeInit();

    ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_9,ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_GPIO, DISABLE,

    ADC1_ALIGN_RIGHT,

    ADC1_SCHMITTTRIG_CHANNEL9,DISABLE);

    ADC1_Cmd(ENABLE);

    ADC1_ITConfig(ADC1_IT_EOC, ENABLE);

    ADC1_StartConversion();

    enableInterrupts();

}

here is the configuration codes for ADC1. but unfortunately I can not see any result in interrupt function. the program has stopped here,

@interrupt void handleADCInt(void)

{

    GPIO_WriteHigh(GPIOD, GPIO_PIN_0);

    if(ADC1_GetFlagStatus(ADC1_FLAG_EOC) == SET)

    {

        prsc=ADC1_GetConversionValue();

        }

    ADC1_ClearFlag(ADC1_FLAG_EOC);

}

I have defined the interrupt function in vector file.

many thanks for your help
1 REPLY 1
John7
Associate II
Posted on November 24, 2016 at 17:20

Hi,

In the interrupt handler, when the ADC is enabled to generate several kinds of interrupts, you should first call

https://my.st.com/public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Functions.html#ga950279308ea4bca1e2e8e213376f31b9

(

https://my.st.com/public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Types.html#gae9f96f201b80ec24da0d51dbdb1660ee

ITPendingBit) to find the current ADC interrupt source and deal with each separately. If EOC is the only source, you do not need to do this call. You may assume it is EOC.

If the interrupt source is EOC, there is no need to do

if (ADC1_GetFlagStatus(ADC1_FLAG_EOC) == SET)

Because of the ADC interrupt this 'if' is always true.

Just read the ADC value and do stuff.

Then you forgot to Reset the ADC1_IT_EOC flag, the ADC EOC interrupt pending flag.

So after one ADC interrupt, the flag remains set. To the CPU, the interrupt seems not handled, so it will block further ADC EOC interrupts.

After you read the value, you handled the interrupt and just need to tell the CPU.

Use

void

https://my.st.com/public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Functions.html#ga2450f7bbab4cff6a76605b5278741715

(

https://my.st.com/public/STe2ecommunities/mcu/Lists/stm81/group__ADC1__Exported__Types.html#gae9f96f201b80ec24da0d51dbdb1660ee

ITPendingBit )

with parameter ADC1_IT_EOC to reset the ADC EOC interrupt pending flag.

Note

There is a possibility that reading the ADC value resets the ADC1_IT_EOC

flag automaticaly (doubt it). I have not looked for that.

HTH,

John