在STM3210E-LK_Demo的基础上修改的,原本ADC是连续转换,规则模式,读ADC通道14的值。
我改成了注入模式+扫描,读ADC通道14。使能中断JEOC,注入模式用软件触发(在systick中触发)。
debug时,在ADC1_2_IRQHandler和SysTickHandler各设置一个断点,结果发现每2次跑到ADC1_2_IRQHandler的断点,才会有1次跑到SysTickHandler中的断点。第一次进ADC1_2_IRQHandler的断点时,查看寄存器JEOC位是1,第二次进的时候EOC和JEOC都是0。
请高手指点一下是什么原因,多谢!
代码如下:
ADC初始化代码:
/*******************************************************************************
* Function Name : EK_ADC_Init
* Description : initialize ADC
* Input : None.
* Return : None.
*******************************************************************************/
void EK_ADC_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
/* Configure PC.04 (ADC Channel14) as analog input -------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
ADC_DeInit(ADC1);
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 1, ADC_SampleTime_239Cycles5);
/* ADC1 regular channel14 configuration */
ADC_InjectedSequencerLengthConfig(ADC1, 1);
ADC_InjectedChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_239Cycles5);
ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None);
//ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_239Cycles5);
//ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
ADC_ITConfig(ADC1, 0x80, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
}
ADC的ISR:
void ADC1_2_IRQHandler(void)
{
#ifndef NO_LCD
//ADC_ConvertedValue = ADC_GetConversionValue(ADC1);
ADC_ConvertedValue = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1);
if (!adcflag)
{
adcflag = TRUE;
ADC_ConvertedValue_Bak = ADC_ConvertedValue;
}
//ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
ADC_ClearITPendingBit(ADC1, ADC_IT_JEOC);
#endif
}
void SysTickHandler(void)
{
#ifndef NO_LCD
......
ADC_SoftwareStartInjectedConvCmd(ADC1, ENABLE);
#endif
}
int main(void)
{
#ifdef DEBUG
debug();
#endif
Set_System();
Interrupts_Config();
Led_Config();
#ifndef NO_USB
Set_USBClock();
#endif
#ifndef NO_LCD
Key_Config();
JoyStick_Init();
//Interrupts_Config();
EK_ADC_Init();
SysTick_Init_start();
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
#endif
while (1)
{}
} |