0

nRF UART driver initialization

f.salvatore gravatar image

asked 2017-03-17 16:51:45 +0100

updated 2017-03-20 18:02:03 +0100

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...

edit retag flag offensive close delete report spam

1 answer

Sort by ยป oldest newest most voted
0
Kristin gravatar image

answered 2017-03-20 14:14:48 +0100

updated 2017-03-20 14:14:59 +0100

Which error code does nrf_drv_uart_tx() return?

edit flag offensive delete publish link more

Comments

1

I've posted an update. I did a workaround to get directly the address of UART register.

f.salvatore ( 2017-03-20 18:03:25 +0100 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

User menu

    or sign up

Recent questions

Question Tools

1 follower

Stats

Asked: 2017-03-17 16:51:45 +0100

Seen: 30 times

Last updated: Mar 20