原来用的F105,UART4用的没问题,现在改成F205了,USART1、2、3都调出来了,唯独UART4调了几天就是不可用,中断void UART4_IRQnHandler(void)始终是不可打断点的状态。C口时钟打开了:RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
UART4时钟打开了:RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE);
GPIO配置成串口了:
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //UART4_TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; // UART4_RX
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure);
中断配置了:NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
UART4波特率配置了:
void UART4_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);
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_Rx | USART_Mode_Tx;
USART_Init(UART4, &USART_InitStructure);
USART_ITConfig(UART4, USART_IT_IDLE, ENABLE); // 使能空闲中断
USART_Cmd(UART4, ENABLE);
USART_ClearFlag(UART4, USART_FLAG_TC);
}
哪里错了呢?
|