按着官方给的例子修改过来的!发现如果发送的字节数太多就会出现死机的问题!缓存和队列都是32字节,通过串口发送数据 如下 直接死掉了 手点的发送1S以内!
另外还有个不明白的地方 NRF_SERIAL_QUEUES_DEF(serial0_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE); 这是创建串口队列而在后面又创建串口缓存 NRF_SERIAL_BUFFERS_DEF(serial0_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE); 不是都有队列了吗好像也不需要缓存了!主要函数献上,帮忙分析分析!
static void sleep_handler(void)
{
__WFE();
__SEV();
__WFE();
}
//创建串口配置实例
NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uarte0_drv_config, //名字
RX0_PIN_NUMBER, TX0_PIN_NUMBER, //RX引脚 TX引脚
RTS0_PIN_NUMBER, CTS0_PIN_NUMBER, //流控引脚
NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED, //流控关闭,无奇偶校验
NRF_UART_BAUDRATE_115200, //波特率
UART_DEFAULT_CONFIG_IRQ_PRIORITY); //中断优先级
NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uarte1_drv_config,
RX1_PIN_NUMBER, TX1_PIN_NUMBER,
RTS1_PIN_NUMBER, CTS1_PIN_NUMBER,
NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
NRF_UART_BAUDRATE_115200,
UART_DEFAULT_CONFIG_IRQ_PRIORITY);
#define SERIAL_FIFO_TX_SIZE 32
#define SERIAL_FIFO_RX_SIZE 32
NRF_SERIAL_QUEUES_DEF(serial0_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE); //创建串口队列 0
NRF_SERIAL_QUEUES_DEF(serial1_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE); //创建串口队列 1
#define SERIAL_BUFF_TX_SIZE 32
#define SERIAL_BUFF_RX_SIZE 32
NRF_SERIAL_BUFFERS_DEF(serial0_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE); //创建串口缓存 0
NRF_SERIAL_BUFFERS_DEF(serial1_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE); //创建串口缓存 1
NRF_SERIAL_CONFIG_DEF(serial0_config, NRF_SERIAL_MODE_IRQ, //创建串口0配置
&serial0_queues, &serial0_buffs, NULL, sleep_handler); //
NRF_SERIAL_CONFIG_DEF(serial1_config, NRF_SERIAL_MODE_DMA,
&serial1_queues, &serial1_buffs, NULL, sleep_handler); //
NRF_SERIAL_UART_DEF(serial0_uarte, 0); //创建串行端口0
NRF_SERIAL_UART_DEF(serial1_uarte, 1); //创建串行端口1
static void serial0_handler(struct nrf_serial_s const * p_serial,nrf_serial_event_t event)
{
uint8_t eventdata = 0;
char c;
if(event == NRF_SERIAL_EVENT_RX_DATA){
nrf_serial_read(&serial0_uarte, &c, sizeof(c), NULL, 10);
(void)nrf_serial_write(&serial0_uarte, &c, sizeof(c), NULL, 0);
(void)nrf_serial_flush(&serial0_uarte, 0);
}
}
static void serial1_handler(struct nrf_serial_s const * p_serial,nrf_serial_event_t event)
{
uint8_t eventdata;
eventdata = event;
}
int main(){
ret_code_t ret;
ret = nrf_drv_clock_init();
APP_ERROR_CHECK(ret);
ret = nrf_drv_power_init(NULL);
APP_ERROR_CHECK(ret);
nrf_drv_clock_lfclk_request(NULL);
ret = app_timer_init();
APP_ERROR_CHECK(ret);
ret = nrf_serial_init(&serial0_uarte, &m_uarte0_drv_config, &serial0_config); //串口 0 RX = P0.8 TX = P0.27
APP_ERROR_CHECK(ret);
ret = nrf_serial_init(&serial1_uarte, &m_uarte1_drv_config, &serial1_config); //串口 1 RX = P0.26 TX = P0.6
APP_ERROR_CHECK(ret);
static char message0[] = "Hello nrf_serial_0!\n\r";
static char message1[] = "Hello nrf_serial_1!\n\r";
ret = nrf_serial_write(&serial0_uarte,
message0,
strlen(message0),
NULL,
NRF_SERIAL_MAX_TIMEOUT);
(void)nrf_serial_flush(&serial0_uarte, 0); //刷新串口TX队列
ret = nrf_serial_write(&serial1_uarte,
message1,
strlen(message1),
NULL,
NRF_SERIAL_MAX_TIMEOUT);
(void)nrf_serial_flush(&serial1_uarte, 0);
while(1){
char c;
ret = nrf_serial_read(&serial0_uarte, &c, sizeof(c), NULL, 10);//
if (ret != NRF_SUCCESS)
{
continue;
}
(void)nrf_serial_write(&serial0_uarte, &c, sizeof(c), NULL, 0);
(void)nrf_serial_flush(&serial0_uarte, 0);
ret = nrf_serial_read(&serial1_uarte, &c, sizeof(c), NULL, 10);
if (ret != NRF_SUCCESS)
{
continue;
}
(void)nrf_serial_write(&serial1_uarte, &c, sizeof(c), NULL, 0);
(void)nrf_serial_flush(&serial1_uarte, 0);
}
}