Rodkin 2019-04-06 23:32 采纳率: 0%
浏览 812
已结题

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

用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条回答 默认 最新

  • devmiao 2019-04-06 23:55
    关注
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!