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

app_uart getting started

I've modified the simple_uart example to use app_uart instead but I cannot get any data transmitting. I know the connections are correct because it works fine under normal simple_uart testing.

Here is my init code which also sends a character and a string. When I debug it always makes it through to NRF_SUCCESS case, but never transmits 'T'

uart_buffers.rx_buf = rx_buffer;
uart_buffers.rx_buf_size = sizeof(rx_buffer);
uart_buffers.tx_buf = tx_buffer;
uart_buffers.tx_buf_size = sizeof(tx_buffer);

comm_params.rx_pin_no = rxd_pin_number;
comm_params.tx_pin_no = txd_pin_number;
comm_params.cts_pin_no = cts_pin_number;
comm_params.rts_pin_no = rts_pin_number;
comm_params.baud_rate = 9600;
comm_params.use_parity = false;
comm_params.flow_control = APP_UART_FLOW_CONTROL_DISABLED;

uint32_t res = app_uart_init(&comm_params, &uart_buffers, &app_uart_handler, APP_IRQ_PRIORITY_HIGH, comm_uuid);

if(res == NRF_SUCCESS)
{
	app_uart_put('T');
	simple_uart_putstring("Test 1\r\n");
	return;
}
  • Having both simple_uart and app_uart in the same example will most likely mess up the actual configuration of the UART peripheral, and should therefore not be done.

    I've attached a quick example I made right now that shows how app_uart can be used.

    app_uart_example.zip

  • Ole, thanks for the response. Your code helped me find my issue - baud rate. There is no explanation in the app_uart SDK documentation about the baud rate, so for 9600 I had 9600 as the baud rate. Seeing your example made me realize I had to go use 0x00275000UL for the baud rate from the simple_uart file.

    Thanks!

  • No problem! We're always happy to get questions cleared up, so I accepted your answer, since it contains the exact problem. You could also have done this yourself. Thanks for letting us know!

  • Has anyone had trouble with app_uart in 5.1.0? My app craps out with the first call to app_uart_put.

    By the way, my favorite Nordic #define is officially UART_BAUDRATE_BAUDRATE_Baud38400

    From the ministry of redundancy ministry... :-)

  • The example I posted above seems to work just as well with SDK 5.1.0 as it did with 4.4.2. I would recommend you to try running the project with a debugger to see where it fails, and then post a new question if you have further problems.

    As for the define, I'd almost say that's my favorite define as well, mostly due to the fact that it shows the consistency of the register defines. All register defines are on the format PERIPHERAL_REGISTER_FIELDNAME_VALUE, which makes it trivial to write code with just the Reference Manual, without even considering what part was left out to please the eye in this register. I'd much rather have it consistent and redundant, than have random parts left out of every other define. All hail the Great Value of Consistency! ;-)

    (One could of course argue that we should name the fields and registers otherwise to avoid things like this, but I really don't see it as that big problem...)

Related