我需要使用全部4個(gè)串口,串口1,2,3 沒(méi)有問(wèn)題,但是串口4只能發(fā)送,只要一接收到數(shù)據(jù),就馬上死機(jī)。
這是我的串口4配置。
void USART4_Init()
{
? ? GPIO_InitTypeDef? GPIO_InitStructure={0};
? ? USART_InitTypeDef USART_InitStructure={0};
? ? NVIC_InitTypeDef? NVIC_InitStructure={0};
? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
? ? RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
? ?// GPIO_PinRemapConfig(GPIO_PartialRemap_USART4, ENABLE);
? ? GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
? ? GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
? ? GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
? ? GPIO_Init(GPIOB,&GPIO_InitStructure);
? ? GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1;
? ? GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
? ? GPIO_Init(GPIOB,&GPIO_InitStructure);
? ? USART_InitStructure.USART_BaudRate = 115200;
? ? 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);
? ? NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
? ? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
? ? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
? ? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
? ? NVIC_Init(&NVIC_InitStructure);
? ? USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
? ? USART_Cmd(UART4, ENABLE);
}
void UART4_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void UART4_IRQHandler(void)
{
? ? if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET)
? ? {
????????//處理數(shù)據(jù)
? ? }
}
另外,我注意到數(shù)據(jù)手冊(cè)上,這個(gè)芯片的PB0和PB1,既是 USART4_TX 和?UART4_RX ,又是UART4_TX_1和?UART4_RX_1,那我在不使用同步串口功能時(shí),到底該不該重映射呢?已經(jīng)嘗試過(guò)重映射,串口4就完全不工作了。