串口中断异常,一直进中断
-


FCR_IID寄存器的结果是0xCC,有超时中断,但是LSR.LSR.BIT.DR是0,导致进不去读数据的while,但是一直在进中断,能不能帮忙看一下要怎么解决
-
@zxy 把代码发出来看下
-
@zr #include "user_driver_uart.h"
#include "user_config.h"#define UART_DRIVER_TASK_MS (TASK_HIGH_SPEED_MS)
static void usr_uart_get_data(UART_HandleTypeDef *huart);
extern void uart_nvic_enable(UART_UserTypeDef_t handle);
extern struct_UART_t uart_get_reg_addr(UART_UserTypeDef_t *handle);void usr_uart_IRQHandler(UART_UserTypeDef_t user_uart)
{
switch (__UART_INT_GET_ID(user_uart->uart->UARTx))
{
case INT_INDEX_TXE:
{
/ Data transit end /
if (user_uart->uart->u32_TxCount >= user_uart->uart->u32_TxSize)
{
if (__UART_IS_TxFIFO_EMPTY(user_uart->uart->UARTx))
{
GLOBAL_INT_DISABLE();
__UART_INT_TXE_DISABLE(user_uart->uart->UARTx);
GLOBAL_INT_RESTORE();
user_uart->frame->frame_send_flag = true;
}
}
else
{
/ UART_FIFO_ENABLE /
if (__UART_IS_FIFO_Enable(user_uart->uart))
{
/ Until TxFIFO full /
while (!__UART_IS_TxFIFO_FULL(user_uart->uart->UARTx))
{
user_uart->uart->UARTx->DATA_DLL.DATA = user_uart->uart->p_TxData[user_uart->uart->u32_TxCount++];
/ Data transit end */
if (user_uart->uart->u32_TxCount >= user_uart->uart->u32_TxSize)
{
if (__UART_IS_TxFIFO_EMPTY(user_uart->uart->UARTx))
{
GLOBAL_INT_DISABLE();
__UART_INT_TXE_DISABLE(user_uart->uart->UARTx);
GLOBAL_INT_RESTORE();
user_uart->frame->frame_send_flag = true;
}
break;
}
}
}
else
{
user_uart->uart->UARTx->DATA_DLL.DATA = user_uart->uart->p_TxData[user_uart->uart->u32_TxCount++];
}
}
break;
}
case INT_INDEX_RX:
case INT_INDEX_RX_TOUT:
{
user_uart->frame->frame_recv_flag = true;
user_uart->frame->frame_interval_cnt = 0;
usr_uart_get_data(user_uart->uart);
break;
}
default:
{
volatile REG_USR_t usr_status = user_uart->uart->UARTx->USR;
break;
}
}
}void usr_uart_task(UART_UserTypeDef_t *user_uart)
{
if (user_uart->frame->frame_recv_flag == true)
{
user_uart->frame->frame_interval_cnt++;
if (user_uart->frame->frame_interval_cnt >= (user_uart->frame->frame_interval_ms / UART_DRIVER_TASK_MS))
{
user_uart->frame->frame_interval_cnt = 0;
user_uart->frame->frame_recv_flag = false;
usr_uart_get_data(user_uart->uart);
GLOBAL_INT_DISABLE();
__UART_INT_RX_DISABLE(user_uart->uart->UARTx);
GLOBAL_INT_RESTORE();
if (user_uart->uart->RxCpltCallback != NULL)
{
user_uart->uart->RxCpltCallback(user_uart->uart);
}
user_uart->uart->u32_RxCount = 0;
GLOBAL_INT_DISABLE();
__UART_INT_RX_ENABLE(user_uart->uart->UARTx);
GLOBAL_INT_RESTORE();
}
}
if (user_uart->frame->frame_send_flag == true)
{
if (user_uart->uart->TxCpltCallback != NULL)
{
user_uart->uart->TxCpltCallback(user_uart->uart);
}
user_uart->uart->b_TxBusy = false;
user_uart->frame->frame_send_flag = false;
}
}void uart_driver_attr_init(UART_UserTypeDef_t *handle, uint32_t baudRate)
{
handle->uart->UARTx = uart_get_reg_addr(handle);
handle->uart->Init.BaudRate = baudRate;
handle->uart->Init.DataLength = UART_DATA_LENGTH_8BIT;
handle->uart->Init.StopBits = UART_STOPBITS_1;
handle->uart->Init.Parity = UART_PARITY_NONE;
handle->uart->Init.FIFO_Mode = UART_FIFO_ENABLE;
handle->uart->TxCpltCallback = NULL;
handle->uart->RxCpltCallback = NULL;
uart_init(handle->uart);
__UART_RxFIFO_THRESHOLD(handle->uart, 2);
__UART_INT_RX_ENABLE(handle->uart->UARTx);
uart_nvic_enable(handle);
}void uart_driver_start_receive(UART_UserTypeDef_t *handle,
uint8_t *p_data,
uint16_t max_byte_num,
void (*UsrRxCpltCallback)(struct __UART_HandleTypeDef *huart))
{
handle->uart->RxCpltCallback = UsrRxCpltCallback;
uart_receive_IT(handle->uart, p_data, max_byte_num);
}static void usr_uart_get_data(UART_HandleTypeDef *huart)
{
while (huart->UARTx->LSR.LSR_BIT.DR)
{
huart->p_RxData[huart->u32_RxCount++] = huart->UARTx->DATA_DLL.DATA;
}
}现在是反复进入那个超时的case里,寄存器的状态在上面贴出来了