大家好、当我使用 tm4c123ghpm 测试 UART 功能时、
当我测试它时、我发现如果 Rx 长度大于10字节、它会变为硬故障、但少于8是可以的。
如果我将 Rx 计数设置为零、它将正确损坏。
代码如下:
//UART
#define DEBUG_UART UART4_base
#define DEBUT_UART_PERIPh SYSCTL_PERIPH_UART4
#define DEBUG_UART_PORT SYSCTL_PERIPH_GPIOC
#define DEBUG_UART_RX GPIO_PC4_U4RX
#define DEBUG_UART_TX GPIO_PC5_U4TX
#define DEBUG_UART_PORT_base GPIO_PORTC_BASE
#define DEBUG_UART_RX_PIN GPIO_PIN_4
#define DEBUG_UART_TX_PIN GPIO_PIN_5
uint8_t Uart4Rx[64]={0};
uint8_t Uart4Tx[64]={1、2、3、4、5、6};
UARTRX_STRUCTGData;
空 UART4IntHandler (空);
空 PrintUsartInit (uint32_t 波特)
{
GPIOPinConfigure (DEBUG_UART_RX);
GPIOPinConfigure (DEBUG_UART_TX);
GPIOPinTypeUART (DEBUG_UART_PORT_base、DEBUT_UART_RX_PIN|DEBUT_UART_TX_PIN);
UARTConfigSetExpClk (DEBUG_UART、SysCtlClockGet ()、BAUD、
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
// IntMasterEnable();
UARTEnable (DEBUG_UART);
// UARTFIFOEnable (DEBUG_UART);
// UARTFIFOLevelSet (DEBUG_UART、UART_FIFO_TX4_8、UART_FIFO_RX4_8);
UARTIntEnable (DEBUG_UART、UART_INT_RX | UART_INT_RT);
UARTIntRegister (DEBUG_UART、UART4IntHandler);
IntEnable (INT_UART4);
}
空 UART4IntHandler (空)
{
uint32_t ui32Status;
uint32_t tempData;
uint32_t rxCount = 0;
//获取中断状态。
ui32Status = UARTIntStatus (DEBUG_UART、TRUE);
//清除已发出的中断。
UARTIntClear (DEBUG_UART、ui32Status);
//在接收 FIFO 中有字符时循环。
while (UARTCharsAvail (debug_UART))
{
Uart4Rx [rxCount++]= UARTCharGetNonBlocking (debug_UART);
}
DebugData.rxFlag = true;
// rxCount = 0;
}