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

Why does nrf_serial_read return NRF_ERROR_INVALID_STATE?

I'm starting initial development on a new project using the nRF52832. I've been able to transmit successfully using nrf_serial_write but nrf_serial_read always returns NRF_ERROR_INVALID_STATE.

Stepping through nrf_serial.c, it appears that this error should be returned if the RX pin is unconfigured. However, in my UART configuration, I believe both pins are configured:

ret_code_t UartInit(void) {
ret_code_t ret;

Uart0HwConfig.pseltxd = MODBUS_RS485_TX; ///< TXD pin number.
Uart0HwConfig.pselrxd = MODBUS_RS485_RX; ///< RXD pin number.
// Uart0HwConfig.pselcts; ///< CTS pin number.
// Uart0HwConfig.pselrts; ///< RTS pin number.
Uart0HwConfig.p_context = NULL; ///< Context passed to interrupt handler.
Uart0HwConfig.hwfc = NRF_UART_HWFC_DISABLED; ///< Flow control configuration.
Uart0HwConfig.parity = NRF_UART_PARITY_EXCLUDED; ///< Parity configuration.
Uart0HwConfig.baudrate = NRF_UART_BAUDRATE_115200; ///< Baudrate.
Uart0HwConfig.interrupt_priority = APP_IRQ_PRIORITY_LOWEST; ///< Interrupt priority.
Uart0HwConfig.use_easy_dma = false;

ret = nrf_serial_init(&Uart0, &Uart0HwConfig, &Rs485Config);

return ret;
}

It looks like this might have something to do with the  p_ctx variable being NULL; I see that the function nrf_serial_read is hitting this case:

if (!(p_serial->p_ctx->flags & NRF_SERIAL_RX_ENABLED_FLAG))
{
return NRF_ERROR_INVALID_STATE;
}

So, my question is: do I need to do populate Uart0HwConfig.p_context with something other than NULL? Can someone provide a complete example of UART reception with nrf_serial.c?

Parents Reply
  • I just tried compiling with libuarte and got several compiler errors:

    'TIMERNRF_LIBUARTE_ASYNC_CONFIG_TIMER_USED' undeclared here

    'TIMERNRF_LIBUARTE_ASYNC_CONFIG_TIMER_USED_INST_IDX' undeclared here

    etc.

    It's not obvious to me where this is coming from; I followed the example in the SDK which is pretty straightforward and doesn't seem to involve any timers. The location where this error happens during compiling is in a compiler macro in nrfx_timer.h; the macro seems to be defining a timer. 

    Is the nrf_serial library not expected to work without HW flow-control? The configuration structure provides a flag for this (NRF_UART_HWFC_DISABLED), so I would expect that the driver could function in this situation.

Children
Related