STM32F103RC的串口4和5,进不了中断。
我是通过软件调试的??
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
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(USART2, &USART_InitStructure);
/* Configure USART3 */
// USART_Init(USART3, &USART_InitStructure);
/* Configure UART4 */
USART_Init(UART4, &USART_InitStructure);
/* Configure UART5 */
USART_Init(UART5, &USART_InitStructure);
/* Enable the USART Transmoit interrupt: this interrupt is generated when the
USART1 transmit data register is empty */
//USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
// USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
USART_ITConfig(UART4, USART_IT_TXE, ENABLE);
/* Enable the USART Receive interrupt: this interrupt is generated when the
USART1 receive data register is not empty */
// USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
// USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
// USART_Cmd(USART2, ENABLE);
// USART_Cmd(USART3, ENABLE);
USART_Cmd(UART4, ENABLE);
USART_Cmd(UART5, ENABLE);
}
中断
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB1Periph_USART3|
RCC_APB1Periph_UART4|RCC_APB1Periph_UART5, ENABLE);
void UART4_IRQHandler(void)
{
uart4();
}
void UART5_IRQHandler(void)
{
uart5();
}
BSP_IntVectSet(BSP_INT_ID_UART4, UART4_IRQHandler);
BSP_IntVectSet(BSP_INT_ID_UART5, UART5_IRQHandler);
版主复习考研去了…这种情况一般是gqio没有设置.或者rcc.nvic没设置