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?