nrf52832串口复用问题

项目中需要 用到两个uart
但主芯片 NRF52832 只有一个串口

尝试过用模拟的方法, 经常丢bit (蓝牙终端导致)

只能使用复用的方法:

开启 ->关闭 --> 再开启(切换IO)–> 在关闭的方法

如何切换参考例程比较容易, 但也有坑
主要是不能用官方的宏定义的串口初始化方法:
APP_UART_FIFO_INIT(&comm_params,
rx_buf,
tx_buf,
uart_event_handle,
APP_IRQ_PRIORITY_LOWEST,
err_code);
这个宏定义会定义一个数组变量, 会泄漏内存或FIFO 异常 造成芯片重启。

// 切换代码
void change_uart_mode(bool mode)
{
if (Work_Mode == mode) return;
Work_Mode = mode;
app_uart_close();
uart_init(mode);
}

/@brief Function for initializing the UART module.
*/
/
@snippet [UART Initialization] */
uint8_t rx_buf[UART_RX_BUF_SIZE];
uint8_t tx_buf[UART_TX_BUF_SIZE];
app_uart_buffers_t Uart_Buffers;

void uart_init(bool mode)
{
uint32_t err_code;

  uint32_t  rx_pin, tx_pin;

  if (mode == GPRS_MODE)
	{
		 rx_pin = RX_PIN_NUMBER;
		 tx_pin = TX_PIN_NUMBER;
	}
	else
	{
		 rx_pin = GPS_RX_PIN_NUMBER;
		 tx_pin = GPS_TX_PIN_NUMBER;
	}

app_uart_comm_params_t const comm_params =
{
    .rx_pin_no    = rx_pin,
    .tx_pin_no    = tx_pin,
    .rts_pin_no   = RTS_PIN_NUMBER,
    .cts_pin_no   = CTS_PIN_NUMBER,
    .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
    .use_parity   = false,

#if defined (UART_PRESENT)
.baud_rate = NRF_UART_BAUDRATE_115200
#else
.baud_rate = NRF_UARTE_BAUDRATE_115200
#endif
};

	Uart_Buffers.rx_buf      = rx_buf;
	Uart_Buffers.rx_buf_size = sizeof (rx_buf);
	Uart_Buffers.tx_buf      = tx_buf;
	Uart_Buffers.tx_buf_size = sizeof (tx_buf);
err_code = app_uart_init(&comm_params,
                   &Uart_Buffers,
                   uart_event_handle,
                   APP_IRQ_PRIORITY_LOWEST);

}

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值