问题描述
您好,我是北欧的新手。我只能发送和接收字符,但不能发送字符串。
我正在尝试使用 NRF52832 中的 UART 通过 RS232 将字符发送到 tera Term。我已经做了我自己的板。我使用了北欧的 UART 示例,但是,它使用 printf 发送字符。我已经编写了自己的函数来发送字符/字符串。如下:
void uart_putstring(const uint8_t * str)
{
uint32_t err_code;
uint8_t c;
uint8_t len = strlen((char *) str);
for (int i = 0; i < len; i++)
{
c = str[i];
err_code = app_uart_put(c);
APP_ERROR_CHECK(err_code);
nrf_delay_us(1250);
}
}
下面的函数用于初始化UART
void Serial_Ext_Init_Lib(void)
{
uint32_t err_code;
err_code = app_uart_close();
APP_ERROR_CHECK(err_code);
nrf_gpio_cfg_input(UART_RX_Ext_PIN,NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_output(UART_TX_Ext_PIN);
APP_UART_FIFO_INIT2(&comm_params2,RX_BUF_SIZE,TX_BUF_SIZE,Uart_Evt_Callback2,UART_IRQ_PRIORITY,err_code);
APP_ERROR_CHECK(err_code);
}
void Uart_Evt_Callback2(app_uart_evt_t * uart_evt)
{
uint32_t err_code;
static char cr;
switch (uart_evt->evt_type)
{
case APP_UART_DATA:
while(app_uart_get(&cr) != NRF_SUCCESS);
while(app_uart_put(cr) != NRF_SUCCESS);
// uart_putstring(" Cannot print using this function");
printf("Char RX/TX : %c \n",cr);
break;
case APP_UART_DATA_READY:
break;
case APP_UART_TX_EMPTY:
break;
default:
break;
}
}
所以基本上,如果流程是:
MAIN -> Serial_Ext_Init_Lib -> uart_putstring ("我可以在这里打印一个字符串");
就像一个魅力。我可以打印任意数量的字符串,但这是在 for(;;) 或 while(1) 循环之前的主要内容。基本上在调度程序之前。
进入调度器后:
等待 UART 中断 -> 打印一个字符(有效)-> 打印另一个字符或另一个字符串? (不起作用!)
使用 app_uart_put() 产生的错误:NRF_ERROR_BUSY
我怎样才能摆脱这个错误?
///////////////////////////////////////////// ////////
该代码是由我之前的其他人编写的,所以我不确定下面的函数是否是北欧的一部分,但是我正在使用它
uint32_t app_uart_put(uint8_t byte)
{
tx_buffer[0] = byte;
ret_code_t ret = nrf_drv_uart_tx(&app_uart_inst,tx_buffer,1);
if (ret == NRF_ERROR_BUSY)
{
return NRF_ERROR_NO_MEM;
}
else if (ret != NRF_SUCCESS)
{
return NRF_ERROR_INTERNAL;
}
else
{
return NRF_SUCCESS;
}
}
我在北欧论坛上问过这个问题,但我也在这里发布。如果你们都需要更多细节,请告诉我。提前致谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)