问题:
1、串口引脚的切换的,一组引脚(A)切换到另一组引脚(B)上,开始发送数据时发现有部分数据仍然发送到了A组引脚上
2、串口发送大量数据(500字节以上),连续发送,通过串口工具检测发现没有完全发送出去,如何判断每次数据发送完毕
谢谢大家抽空看看源码
#include "uart.h"
#include "nrf_uart.h"
#include "app_uart.h"
#include "nrf_drv_uart.h"
#include "nrf_error.h"
u8 UART_RX_BUF[UART_REC_LEN]; //接收缓冲,最大UART_REC_LEN个字节
u16 UART_RX_LEN = 0; //接收数据长度
void UartEventHandler(app_uart_evt_t * p_event)
{
UBaseType_t uxSavedInterruptStatus;
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
switch (p_event->evt_type)
{
case APP_UART_DATA_READY:
UNUSED_VARIABLE(app_uart_get(&UART_RX_BUF[UART_RX_LEN]));
UART_RX_LEN++;
if(UART_RX_LEN >=UART_REC_LEN )UART_RX_LEN = 0;
break;
default:
break;
}
taskEXIT_CRITICAL_FROM_ISR(uxSavedInterruptStatus);
}
void UART0_Deinit(void)
{
app_uart_close();
memset((u8*)UART_RX_BUF,0,sizeof(UART_RX_BUF));
UART_RX_LEN=0;
}
void UART0_Init(uint8_t UART_PIN)
{
uint32_t err_code;
uint8_t uart_tx_pin_num = 0;
uint8_t uart_rx_pin_num = 0;
UART0_Deinit();
switch(UART_PIN)
{
case 0:
uart_tx_pin_num = 11;
uart_rx_pin_num = 12;
break;
case 1:
uart_tx_pin_num = 22;
uart_rx_pin_num = 23;
break;
case 2:
uart_tx_pin_num = 29;
uart_rx_pin_num = 30;
break;
}
const app_uart_comm_params_t comm_params =
{
.rx_pin_no = uart_rx_pin_num, //设置接收引脚
.tx_pin_no = uart_tx_pin_num, //设置发送引脚
.rts_pin_no = NRF_UART_PSEL_DISCONNECTED,
.cts_pin_no = NRF_UART_PSEL_DISCONNECTED,
.flow_control = APP_UART_FLOW_CONTROL_DISABLED,
.use_parity = false,
.baud_rate = NRF_UART_BAUDRATE_115200
};
APP_UART_FIFO_INIT(&comm_params
, 1024
, 1024
, UartEventHandler
, APP_IRQ_PRIORITY_HIGHEST//APP_IRQ_PRIORITY_LOWEST
, err_code
);
APP_ERROR_CHECK(err_code);
}
void UART_SendData(uint8_t *data, uint16_t size)
{
taskENTER_CRITICAL();
for(uint16_t i = 0; i < size; i++)
{
UNUSED_VARIABLE(app_uart_put((uint8_t)data));//串口发送数据
}
taskEXIT_CRITICAL();
}