本帖最后由 yzzly 于 2011-3-21 12:12 编辑
本人用同样的初始化方式,USART1、USART2、USART3都能够正常工作,但是UART4和UART5则不能工作,都是在初始化的最后三个函数给卡住了。
USART_DeInit(UART4);
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); //使能端口C时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure); //PC11-RXD4
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure); //PC10-TXD4为推挽复用输出
Txd4_Cnt=Txd4_len=Txd4_timer=0;
Rxd4_Cnt=Rxd4_len=Rxd4_timer=Flags1.Rxd4Over=0;
USART_InitStructure.USART_BaudRate = UART4_BaudRate;
if(UART4_WordLen==8)
{
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
}
else
{
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
}
if(UART4_StopBit==1)
{
USART_InitStructure.USART_StopBits = USART_StopBits_1;
}
else if(UART4_StopBit==2)
{
USART_InitStructure.USART_StopBits = USART_StopBits_0_5;
}
else if(UART4_StopBit==3)
{
USART_InitStructure.USART_StopBits = USART_StopBits_2;
}
else if(UART4_StopBit==4)
{
USART_InitStructure.USART_StopBits = USART_StopBits_1_5;
}
if(UART4_Parity==0)
{
USART_InitStructure.USART_Parity = USART_Parity_No;
}
else if(UART4_Parity==1)
{
USART_InitStructure.USART_Parity = USART_Parity_Odd;
}
else if(UART4_Parity==2)
{
USART_InitStructure.USART_Parity = USART_Parity_Even;
}
USART_InitStructure.USART_Mode = (UART4_RxEn<<2) | (UART4_TxEn<<3);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE); //使能UART4时钟
USART_Init(UART4, &USART_InitStructure);
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
USART_ITConfig(UART4, USART_IT_TXE, ENABLE);
USART_Cmd(UART4, ENABLE); |