nrf51802接收串口数据,导致系统重启 5C

用nrf51802作为数据透传模块,当上位MCU发送串口数据,导致nrf51802系统重启

void UART0_IRQHandler(void)
{
// Handle reception
if (NRF_UART0->EVENTS_RXDRDY != 0)
{
uint32_t err_code;

    // Clear UART RX event flag
    NRF_UART0->EVENTS_RXDRDY = 0;

    // Write received byte to FIFO
    err_code = app_fifo_put(&m_rx_fifo, (uint8_t)NRF_UART0->RXD);
    if (err_code != NRF_SUCCESS)
    {
        app_uart_evt_t app_uart_event;
        app_uart_event.evt_type          = APP_UART_FIFO_ERROR;
        app_uart_event.data.error_code   = err_code;
        m_event_handler(&app_uart_event);
    }
    // Notify that new data is available if this was first byte put in the buffer.
    else if (FIFO_LENGTH(m_rx_fifo) == 1)
    {
        app_uart_evt_t app_uart_event;
        app_uart_event.evt_type = APP_UART_DATA_READY;
        m_event_handler(&app_uart_event);
    }
    else
    {
        // Do nothing, only send event if first byte was added or overflow in FIFO occurred.
    }
}

// Handle transmission.
if (NRF_UART0->EVENTS_TXDRDY != 0)
{
    // Clear UART TX event flag.
    NRF_UART0->EVENTS_TXDRDY = 0;
    on_uart_event(ON_TX_READY);
}

// Handle errors.
if (NRF_UART0->EVENTS_ERROR != 0)
{
    uint32_t       error_source;
    app_uart_evt_t app_uart_event;

    // Clear UART ERROR event flag.
    NRF_UART0->EVENTS_ERROR = 0;

    // Clear error source.
    error_source        = NRF_UART0->ERRORSRC;
    NRF_UART0->ERRORSRC = error_source;

    app_uart_event.evt_type                 = APP_UART_COMMUNICATION_ERROR;
    app_uart_event.data.error_communication = error_source;

    m_event_handler(&app_uart_event);
}

}

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐