This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF UART driver initialization

Hello, i'm trying to use nRF UART driver (nrf_drv_uart) to implement a high level UART manager. I followed indications on SDK documentation but it doesn't work and i think that is a problem of initialization.

Configuration: nRF52832 - SDK 12.2.0

That's my code:

void SerialManager::initUART()
{
uint32_t err_code;
//_instance = NRF_DRV_UART_INSTANCE(0);
_instance.drv_inst_idx = CONCAT_3(UART, 0, _INSTANCE_INDEX);

nrf_drv_uart_config_t 	uart_cfg  =  NRF_DRV_UART_DEFAULT_CONFIG;
uart_cfg.pseltxd = 	_tx;
uart_cfg.pselrxd = 	_rx;
uart_cfg.hwfc    = 	NRF_UART_HWFC_DISABLED;
uart_cfg.parity	 = 	NRF_UART_PARITY_EXCLUDED;
uart_cfg.baudrate =	_baudrate;
uart_cfg.p_context = this;
uart_cfg.interrupt_priority = APP_IRQ_PRIORITY_LOW;

err_code = nrf_drv_uart_init(&_instance, &uart_cfg, &(this->eventHandler));
if(err_code == NRF_SUCCESS)
{
	nrf_drv_uart_rx_enable(&_instance);
    //Trying to write something
	uint8_t msg[] = "A";
	uint32_t err = nrf_drv_uart_tx(&_instance, msg, 1);
	assert(err == 0);
}
}

I'm using C++ (g++) and i tried to do all of workarounds proposed in other questions on DevZone.

Can someone help me? What i'm doing wrong?

UPDATE:

It was an instantiation issue. Seems that SDK is not directly suitable for C++ (i got some compilation issues) so i made a workaround to initialize the nrf_drv_uart_t instance.

nrf_drv_uart_t _instance;
_instance.drv_inst_idx = CONCAT_3(UART, 0, _INSTANCE_INDEX);
_instance.reg.p_uart = (NRF_UART_Type *) NRF_UART0_BASE;

And now a little hint for Nordic dev team...I think that is a good thing to avoid some C language tricks when you write a public SDK...

Related