问题是这样的,当我不对rcc初始化,只开启RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);串口能打印,但是我对rcc初始化后,keil上的USART窗口打印什么都没打印。还有另一个问题,打印ABCD。。。的那个循环在串口上只能打印出ACD。。。就是别的都能打印就是第二个字符打印不了
#include "
STM32f10x.h"
#include "stdio.h"
/*************************************************************
¿âº¯Êý°æ
*************************************************************/
void USART_Configura
tion(void);
void GPIO_Configuration(void);
void RCC_Configuration(void);
//½ÓÊÜÊý¾Ý
int fputc(int ch,FILE *f)
{
USART_SendData(USART1,(u8) ch);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
return ch;
}
//·¢ËÍÊý¾Ý
int GetKey(void)
{
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE)==SET);
return ((int) USART_ReceiveData(USART1));
}
int main(void)
{
u8 i,data = 'A';
RCC_Configuration();
USART_Configuration();
GPIO_Configuration();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);
for(i=0; i<20; i++)
{
USART_SendData(USART1,data);
data++;
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
USART_ClearFlag(USART1,USART_FLAG_TC);
}
printf("
hello world!");
//add your code here
return 0;
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_High;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_1Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1,ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //GPIOÔÚ×÷Ϊ¸´Óù¦ÄÜÊä³öʱ£¬Ö»Äܸ´ÓÃÍÆÍìÊä³ö
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //×ö¸´Óù¦ÄÜÊäÈëʱ£¬²»ÄÜΪģÄâÊäÈ룬˫Ïò¸´ÓÃʱֻÄܸ¡¿ÕÊäÈë
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //ÕâÀïÑ¡Ôñ¸¡¿ÕÊäÈë
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
FlagStatus Status;
RCC_DeInit();//ȱʡ
RCC_HSEConfig(RCC_HSE_ON);//Ñ¡ÔñÍⲿ¸ßËÙʱÖÓ
HSEStartUpStatus = RCC_WaitForHSEStartUp();
while(HSEStartUpStatus != SUCCESS);//µÈ´ýHSEÎȶ¨
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);//ÉèÖÃHSE9±¶Æµ
RCC_PLLCmd(ENABLE);//ʹÄÜ¿ªÆôPLL
Status = RCC_GetFlagStatus(RCC_FLAG_PLLRDY);
while(Status == RESET);//µÈ´ýPLL¹¤×÷
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//ÉèÖÃPLLΪϵͳʱÖÓ
while(RCC_GetSYSCLKSource()!=0x80);//ÅжÏPLLÊÇ·ñΪϵͳʱÖÓ
/*******************************/
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PCLK2Config(RCC_HCLK_Div1);
}
一周热门 更多>