一个串口接收中断程序,运行后还没发送数据就一直不停的进入中断,主程序和中断服务程序如下..
//*****************************************************************************
//
// UART1 Interrupt Service Routine
//
//*****************************************************************************
void
am_uart1_isr(void)
{
uint32_t status;
uint32_t rxSize, txSize;
status = am_hal_uart_int_status_get(1, false);
am_hal_uart_int_clear(1, status);
if (status & (AM_HAL_UART_INT_RX_TMOUT | AM_HAL_UART_INT_TX | AM_HAL_UART_INT_RX))
{
am_hal_uart_service_buffered_timeout_save(1, status);
}
if (status & (AM_HAL_UART_INT_RX_TMOUT))
{
g_ui8RxTimeoutFlag = 1;
am_util_stdio_printf("\nTMOUT, ");
}
am_hal_uart_get_status_buffered(1, &rxSize, &txSize);
if (status & (AM_HAL_UART_INT_RX))
{
am_util_stdio_printf(", RX ");
}
if (status & (AM_HAL_UART_INT_TXCMP))
{
am_util_stdio_printf(", TXCMP");
}
am_hal_uart_get_status_buffered(1, &rxSize, &txSize);
if (rxSize >= UART_BUFFER_SIZE / 2)
{
g_ui8BufferFullFlag = 1;
am_util_stdio_printf(", RXF");
}
}
//*****************************************************************************
//
// Main function.
//
//*****************************************************************************
int
main(void)
{
uint32_t ui32Module = AM_BSP_UART_PRINT_INST;
char pcTempBuf[UART_BUFFER_SIZE + 1];
uint32_t ui32Length;
//
// Set the clock frequency.
//
am_hal_clkgen_sysclk_select(AM_HAL_CLKGEN_SYSCLK_MAX);
//
// Set the default cache configuration
//
am_hal_cachectrl_enable(&am_hal_cachectrl_defaults);
//
// Configure the board for low power operation.
//
am_bsp_low_power_init();
// //
// // Initialize the printf interface for UART output.
// //
am_util_stdio_printf_init((am_util_stdio_print_char_t) am_bsp_itm_string_print);
am_bsp_pin_enable(ITM_SWO);
am_bsp_debug_printf_enable();
am_hal_itm_enable();
am_util_stdio_printf_init((am_util_stdio_print_char_t)am_bsp_uart_string_print);
//
// Initialize and Enable the UART.
//
uart_init(ui32Module);
uart_enable(ui32Module);
am_hal_interrupt_master_enable();
//
// Print the banner.
//
am_util_stdio_printf("UART FIFO Example\n");
am_util_stdio_printf("Note - the UART terminal operates at 115,200 BAUD, 8 bit, no parity.\n");
uart_transmit_delay(ui32Module);
am_util_stdio_printf("\n\tEcho back the UART received data.\n");
uart_transmit_delay(ui32Module);
am_util_stdio_printf("\t");
uart_transmit_delay(ui32Module);
//
// Loop forever writing chars to the stimulus register.
//
while (1)
{
//
// Need to retrieve and echo received date for loopback
// if either all the data has been received, or if we are in danger
// of overflowing the receive buffer
//
if (g_ui8RxTimeoutFlag || g_ui8BufferFullFlag)
{
g_ui8RxTimeoutFlag = 0;
g_ui8BufferFullFlag = 0;
memset(pcTempBuf, 0x00, sizeof(pcTempBuf));
ui32Length = am_hal_uart_char_receive_buffered(ui32Module, pcTempBuf, UART_BUFFER_SIZE);
if (ui32Length)
{
if ( pcTempBuf[0] == '\n' )
{
am_util_stdio_printf("START_TX (char='\\n')");
}
else
{
am_util_stdio_printf("START_TX (char='%c')", pcTempBuf[0]);
}
//
// We have overallocated the pcTempBuf, to make sure ui32Length==UART_BUFFER_SIZE is ok
//
pcTempBuf[ui32Length] = 0;
am_hal_uart_string_transmit_buffered(ui32Module, pcTempBuf);
}
}
}
} |