2016-11-16 03:55 AM
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 help2016-11-24 08:20 AM
Hi,
In the interrupt handler, when the ADC is enabled to generate several kinds of interrupts, you should first call ( 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. Usevoid
( 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