我把STM8 固件库中的TIME1触发 ADC2 的列程,翻译成 TIME1触发ADC1,可失败了!请大家帮我找找原因!
void main(void)
{
/* Init GPIO for ADC2 */
GPIO_Init(GPIOB, GPIO_PIN_3, GPIO_MODE_IN_FL_NO_IT);
/* Init GPIO for LED */
GPIO_Init(LEDS_PORT, (LED1_PIN |LED2_PIN |LED3_PIN |LED4_PIN), GPIO_MODE_OUT_PP_LOW_FAST);
GPIO_Init(GPIOG, GPIO_PIN_1, GPIO_MODE_OUT_PP_LOW_FAST);
ADC2_DeInit();
enableInterrupts();
/* Configure the conversion mode and the channel to convert */
ADC2_ConversionConfig(ADC2_CONVERSIONMODE_CONTINUOUS, ADC2_CHANNEL_3, ADC2_ALIGN_RIGHT);
/* Configure the schmitt trigger channel and state */
ADC2_SchmittTriggerConfig(ADC2_SCHMITTTRIG_CHANNEL3, DISABLE);
/* Enable the ADC2 peripheral */
ADC2_Cmd(ENABLE);
/* Enable EOC interrupt */
ADC2_ITConfig(ENABLE);
/* Configure the TIM1 Master/Slave mode */
TIM1_SelectMasterSlaveMode(ENABLE);
/*Configure the ADC2 external trigger */
ADC2_ExternalTriggerConfig(ADC2_EXTTRIG_TIM, ENABLE);
/* Trigger the conversion */
TIM1_SelectOutputTrigger(TIM1_TRGOSOURCE_ENABLE);
TIM1_Cmd(ENABLE);
/* The LEDs are changed in the interrupt routine */
while (1);
}
以上是我copy过来的,用示波器看过,正确的!
以下是我搬过来修改的程序,是主程序中的一段:
ADC1_DeInit();
//////////////////////////////////////
_asm("rim");
////////////////////////////////////
/* Configure the conversion mode and the channel to convert */
ADC1_ConversionConfig(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_4, ADC1_ALIGN_LEFT);
/* Configure the schmitt trigger channel and state */
ADC1_SchmittTriggerConfig(ADC1_SCHMITTTRIG_ALL, DISABLE);
ADC1_ScanModeCmd(ENABLE);
/* Enable the ADC2 peripheral */
ADC1_Cmd(ENABLE);
/* Enable EOC interrupt */
ADC1_ITConfig(ADC1_IT_EOC, ENABLE);
/* Configure the TIM1 Master/Slave mode */
TIM1_SelectMasterSlaveMode(ENABLE);
/*Configure the ADC2 external trigger */
ADC1_ExternalTriggerConfig(ADC1_EXTTRIG_TIM, ENABLE);
/* Trigger the conversion */
TIM1_SelectOutputTrigger(TIM1_TRGOSOURCE_ENABLE);
TIM1_Cmd(ENABLE); |