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

app_uart_get returns NRF_ERROR_NOT_FOUND, nRF51822 on nRF6310 with RS232

I want to read a line of text from a UART peripheral. I'm using app_uart.c, not the "simple UART" example code.

My main() looks something like this:

uint8_t line[MAX_CHARS];
uint8_t command[] = "ATI\n";
uint32_t err_code;
uint16_t uart_uid;
app_uart_comm_params_t comm_params;

leds_init();

comm_params.rx_pin_no = RX_PIN_NUMBER;
comm_params.tx_pin_no = TX_PIN_NUMBER;
comm_params.rts_pin_no = NULL;
comm_params.cts_pin_no = NULL;
comm_params.flow_control = APP_UART_FLOW_CONTROL_DISABLED;
comm_params.baud_rate = UART_BAUDRATE_BAUDRATE_Baud38400;
		
err_code = app_uart_init(&comm_params, NULL, &uart_event_handler, APP_IRQ_PRIORITY_HIGH, &uart_uid);
APP_ERROR_CHECK(err_code);
		
uart_getline(line);

for (;;)
{
}

and my implementation of uart_getline() is:

static void uart_getline(uint8_t * line)
{
	uint_fast8_t i = 0;
	uint8_t ch;
	uint32_t err_code;

	do {
		err_code = app_uart_get(&ch);
		APP_ERROR_CHECK(err_code);

		line[i++] = ch;
	}
	while (ch != '\n');
}

My uart_event_handler() function does nothing.

I have the peripheral connected to the RS-232 port on the motherboard and the red RS232 switch set to on. My pins P2.0 and P2.1 are connected with jumpers to the TXD and RXD pins on port P15. I haven't connected anything to the RTS and CTS pins (not using hardware flow control).

I can connect to the peripheral from a hyperterminal session and see output. It's a simple GPS eval board. I know it works fine with no flow control, 38400 baud, 8N1.

What I'm seeing is that in app_uart_get...

uint32_t app_uart_get(uint8_t * p_byte)
{
    if (m_rx_byte == BYTE_INVALID)
    {
        return NRF_ERROR_NOT_FOUND;
    }

    *p_byte   = m_rx_byte;
    m_rx_byte = BYTE_INVALID;

    return NRF_SUCCESS;
}

... is that m_rx_byte is always BYTE_INVALID

What could be causing this?

Related