我正在运行 USART3,波特率为 921600,使用 RTS CTS,当我尝试同时执行 RX 和 TX 时,我总是面临系统挂起。我已经粘贴了主代码和 IRQ 代码。IRQ 被设计为在丢弃所有接收到的数据的同时传输一个字符“A”。当我们禁用时会发生挂起USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
UART_配置()...
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(USART3, &USART_ClockInitStructure);
USART_InitStructure.USART_Mode = (USART_Mode_Tx|USART_Mode_Rx);
USART_InitStructure.USART_BaudRate = u32BaudRate;
USART_OverSampling8Cmd(USART3, DISABLE);
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_Init(USART3, &USART_InitStructure);
USART_ITConfig(USART3,USART_IT_TXE, DISABLE);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);
主.c ...
uint8_t UART_TransmitData(void)
{
if(u8IntTxFlag==1)
{
u8IntTxFlag=0;
USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
return TRUE;
}
return FALSE;
}
void USART3_IRQHandler(void)
{
/* Implemented full duplex serial communication */
/* UART RX */
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
USART_ReceiveData(USART3);
}
/* UART TX */
if(USART_GetITStatus(USART3, USART_IT_TXE) != RESET)
{
if(USART_GetFlagStatus(USART3, USART_FLAG_CTS) == RESET)
{
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, 'A');
while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);
USART_ClearFlag(USART3, USART_FLAG_TC);
USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
u8IntTxFlag=1;
}
else
{
USART_ClearFlag(USART3, USART_FLAG_CTS);
}
}
}
int main(void)
{
RCC_ClocksTypeDef RCC_Clocks;
RCC_Configuration();
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000);
NVIC_Configuration();
Init_GPIOs();
SerialUARTConfig(921600, 0, 1, 8, 1);
while(1)
{
UART_TransmitData();
f_SleepMs(5);
}
return 0;
}