具体情况:打开ADC时钟时,USART串口打印功能用不了,屏蔽掉ADC时钟时,打印功能又恢复了。到底是咋回事?
代码:
int main(void)
{
uint32_t ad;
SystemInit();
USART_Configuration();
NVIC_Configuration();
ADC_Configuration();
SysTick_Config(72000);
while(1)
{
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));
ad=ADC_GetConversionValue(ADC1);
printf("ADvalue:º%f\r\n",(3.3/4095)*ad);
delayms(1000);
}
}
void USART_Configuration(void) //ÅäÖÃUSART1
{
USART_InitTypeDef USART_InitSturecture;
GPIO_InitTypeDef GPIO_InitStructure;
/*¿ªUSART1ʱÖÓ*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA,ENABLE);
//TXD
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
/*¸´ÓÃÍÆÍìÊä³ö*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
//RXD
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStructure);
//²¨ÌØÂÊ9600
USART_InitSturecture.USART_BaudRate = 9600;
//Êý¾ÝλΪ8λ
USART_InitSturecture.USART_WordLength = USART_WordLength_8b;
//Ò»¸öֹͣλ
USART_InitSturecture.USART_StopBits = USART_StopBits_1;
//ÎÞУÑéģʽ
USART_InitSturecture.USART_Parity = USART_Parity_No;
//ÎÞÓ²¼þÁ÷¿ØÖÆģʽ
USART_InitSturecture.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
//ʹÄÜTX¡¢RX
USART_InitSturecture.USART_Mode = USART_Mode_Tx|USART_Mode_Rx;
USART_Init(USART1,&USART_InitSturecture);
//ʹÄÜUSART1ÖжÏ
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
//´ò¿ªUSART1´®¿Ú
USART_Cmd(USART1,ENABLE);
//USART_ClearFlag(USART1,USART_IT_TC);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/*ÖжϷÖ×é*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
//¿ªADC1ÍâÉèʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1|RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOC,ENABLE);
//ADCÄ£ÄâÁ¿ÊäÈë PC3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;
GPIO_Init(GPIOC,&GPIO_InitStructure);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
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ʱÖÓ·ÖƵ 72/6=12M
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
//ͨµÀ13£¬Ë³ÐòºÍ²ÉÑùÖÜÆÚÉèÖÃ
ADC_RegularChannelConfig(ADC1,ADC_Channel_13,1,ADC_SampleTime_239Cycles5);
//ʹÄÜADC1
ADC_Cmd(ADC1,ENABLE);
//¸´Î»ADC×ÔУ׼
ADC_ResetCalibration(ADC1);
//µÈ´ý¸´Î»Íê³É
while(ADC_GetResetCalibrationStatus(ADC1));
//Æô¶¯×ÔУ׼
ADC_StartCalibration(ADC1);
//µÈ´ý×ÔУ׼Íê³É
while(ADC_GetCalibrationStatus(ADC1));
//Èí¼þÆô¶¯
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
} |