NRF528xx 芯片外设常用函数与事件速查(四)-----APP_UART/
一、APP_UART
-
APP_UART_FIFO_INIT宏定义配置
作用: 初始化uart/uarte结构体并用app_uart_init()函数初始化
示例: const app_uart_comm_params_t comm_params =
---------{
-----------uart接收引脚,
-----------uart发送引脚,
-----------uart RTS引脚,
-----------uart CTS引脚,
-----------APP_UART_FLOW_CONTROL_DISABLED,//关闭uart硬件控制流
-----------false,//禁止奇偶校验
-----------NRF_UART_BAUDRATE_115200//波特率
---------};
---------APP_UART_FIFO_INIT(&comm_params,
---------------------------UART_RX_BUF_SIZE,//接收缓存大小
---------------------------UART_TX_BUF_SIZE,//发送数据大小
---------------------------uart_error_handle,//串口事件处理回调函数
---------------------------APP_IRQ_PRIORITY_LOWEST,//中断优先级
---------------------------err_code);
---------void uart_error_handle(app_uart_evt_t * p_event) -
uint32_t app_uart_get(uint8_t * p_byte)
作用:获取数据
示例:app_uart_get(&byte); -
uint32_t app_uart_put(uint8_t byte)
作用:发送数据
示例:app_uart_put(data); -
uint32_t app_uart_close(void)
作用:关闭串口
EVENT
APP_UART_DATA_READY----------------------数据在FIFO中接收到了
APP_UART_FIFO_ERROR----------------------FIFO模块发生错误
APP_UART_COMMUNICATION_ERROR-------------接收过程中发生通信错误
APP_UART_TX_EMPTY------------------------FIFO模块中数据已发送完
APP_UART_DATA----------------------------数据已接收,FIFO模块未启用
二、UART/UARTE
-
void nrf_uart_enable(NRF_UART_Type * p_reg);
---void nrf_uarte_enable(NRF_UARTE_Type * p_reg);
作用:使能串口
示例:static const nrf_drv_uart_t m_uart = NRF_DRV_UART_INSTANCE(0);
--------NRF_DRV_UART_INSTANCE//宏定义
--------nrf_uart_enable(&m_uart.p_reg); -
void nrf_uart_disable(NRF_UART_Type * p_reg);
---void nrf_uarte_disable(NRF_UARTE_Type * p_reg);
作用:禁止串口
示例:nrf_uart_disable(&m_uart.p_reg); -
void nrf_uart_txrx_pins_disconnect(NRF_UART_Type * p_reg);
---void nrf_uarte_txrx_pins_disconnect(NRF_UARTE_Type * p_reg);
作用:解绑TX,RX引脚
示例:nrf_uart_txrx_pins_disconnect(&m_uart.p_reg); -
void nrf_uart_txrx_pins_set(NRF_UART_Type * p_reg, uint32_t pseltxd, uint32_t pselrxd);
---nrf_uarte_txrx_pins_set(NRF_UARTE_Type * p_reg,uint32_t pseltxd,uint32_t pselrxd);
作用:设置TX,RX 引脚
示例:nrf_uart_txrx_pins_set(&m_uart.p_reg,3,5); -
void nrf_uart_task_trigger(NRF_UART_Type * p_reg, nrf_uart_task_t task);
---void nrf_uarte_task_trigger(NRF_UARTE_Type * p_reg, nrf_uarte_task_t task);
作用:开始串口任务
示例:nrf_uart_task_trigger(&m_uart.p_reg,NRF_UARTE_TASK_STARTRX); -
uint32_t nrf_uart_task_address_get(NRF_UART_Type * p_reg, nrf_uart_task_t task);
---uint32_t nrf_uarte_task_address_get(NRF_UARTE_Type * p_reg, nrf_uarte_task_t task);
作用:获取相关任务寄存器地址
示例:nrf_uart_task_address_get(&m_uart.p_reg,NRF_UARTE_TASK_STARTRX); -
uint32_t nrf_uart_event_address_get(NRF_UARTE_Type * p_reg,nrf_uarte_event_t event)
---uint32_t nrf_uarte_event_address_get(NRF_UARTE_Type * p_reg,nrf_uarte_event_t event)
作用:获取相关事件寄存器地址
示例:nrf_uart_event_address_get(&m_uart.p_reg,NRF_UARTE_EVENT_RXDRDY);
EVENT
NRF_UARTE_EVENT_RXDRDY//硬件接收到一个字节
NRF_UARTE_EVENT_ENDRX //接收缓冲区接收满了
主要思想就是不使用APP UART这个库,要自己写串口DMA的程序,在中断里对NRF_UARTE_EVENT_RXDRDY进行处理,用定时器监视串口接收