STM32 ADC使用TIM3 TRGO 转换模式时为什么配置好了定时器和触发通道ADC无法正常启用,在程序中加一个软件触发就可以正常使用(ADC配置为单次转换),关闭定时器后ADC转换无法启用,可以看出触发的来源来自定时器的TRGO ,为什么必须要加一个软件触发 ,麻烦大佬帮忙看下
#include "stm32f10x.h" // Device header
void ADCdma_Init( )
{
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE );
RCC_ADCCLKConfig (RCC_PCLK2_Div6);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 ;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_Period=2-1;
TIM_TimeBaseInitStructure.TIM_Prescaler=72-1;
TIM_TimeBaseInitStructure.TIM_RepetitionCounter=0;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);
TIM_SelectOutputTrigger(TIM3,TIM_TRGOSource_Update);
ADC_RegularChannelConfig(ADC1,ADC_Channel_0,1,ADC_SampleTime_55Cycles5);
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_ContinuousConvMode=DISABLE ;
ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;
ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_T3_TRGO;
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;
ADC_InitStructure.ADC_NbrOfChannel=1;
ADC_InitStructure.ADC_ScanConvMode=DISABLE ;
ADC_Init(ADC1,&ADC_InitStructure);
ADC_Cmd(ADC1,ENABLE );
TIM_Cmd(TIM3,ENABLE );
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1)==SET );
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1)==RESET);
}
#include "stm32f10x.h" // Device header
#include "ADCdma.h"
#include "OLED.h"
int main(void)
{
uint16_t ADC_Date1[4]={0};
OLED_Init();
ADCdma_Init();
ADC_SoftwareStartConvCmd(ADC1,ENABLE );// 必须加这条才可以正常使用
while(1)
{
OLED_ShowNum(1,1,ADC_GetConversionValue(ADC1),5);
}
}
|