小弟初学stm32,我用同样的程序,在这个芯片中初始化串口三,发送都没问题,修改时钟和gpio,再用于串口1上就有问题了,这个PA9的端口是没问题的,我不用串口直接置1都是可行的,可为什么串口1不工作我就搞不懂了
int main(void)
{
SystemInit();//ÅäÖÃϵͳʱÖÓΪ 72M
LED_Init();//led³õʼ»¯
LED(ON);
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* ʹÄÜ USART1 ʱÖÓ*/
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* USART1 ʹÓÃIO¶Ë¿ÚÅäÖà */
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);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿ÕÊäÈë
GPIO_Init(GPIOA, &GPIO_InitStructure); //³õʼ»¯GPIOA
/* USART1 ¹¤×÷ģʽÅäÖà */
USART_InitStructure.USART_BaudRate = 115200; //²¨ÌØÂÊÉèÖãº9600
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //Êý¾ÝλÊýÉèÖãº8λ
USART_InitStructure.USART_StopBits = USART_StopBits_1; //ֹͣλÉèÖãº1λ
USART_InitStructure.USART_Parity = USART_Parity_No ; //ÊÇ·ñÆæżУÑ飺ÎÞ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //Ó²¼þÁ÷¿ØÖÆģʽÉèÖãºÃ»ÓÐʹÄÜ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//½ÓÊÕÓë·¢ËͶ¼Ê¹ÄÜ
USART_Init(USART1, &USART_InitStructure); //³õʼ»¯USART1
/*ʹÄÜ´®¿Ú1½ÓÊÕÖжÏ*/
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);// USART3ʹÄÜ
/*·¢ËÍÒ»¸ö×Ö½ÚÊý¾Ý*/
while(1)
{
u8 i=0xFF;
USART_SendData(USART1,i);
}
} |