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

nrf52 DK: UART problems

Hello,

I integrated the relevant code from the "uart" example into the "ble_app_uart" example(this is all the code in the main routine):

uint8_t cr;        
uart_init();
	printf("\r\nUART Start!\r\n");

  while (true){
		        
    while (app_uart_get(&cr) != NRF_SUCCESS);
    while (app_uart_put(cr) != NRF_SUCCESS);

    if (cr == 'q' || cr == 'Q')
    {
        printf(" \r\nExit!\r\n");

        while (true)
        {
            // Do nothing.
        }
    }
}

Now have the problem that the program is stuck in this line:

while (app_uart_get(&cr) != NRF_SUCCESS);

The return value of the function is not "NRF_SUCCESS".

The echo function in the "uart" example was working fine.

The only difference between the uart_inits of both is uart_error_handle and uart_event_handle and the Flow Control. But even if I set this to enable it won't work:

UART: UART example

BLE_APP_UART: BLE_APP_UART example

Also if I flash the code, I can't download the softdevice to the board. Maybe there are conflicts but I have no clue.

Thanks in advance Hannes

  • The DK received the bytes from the script using the uart example but not in the ble-example.

    Yes, the ble_app_uart example worked fine. Only after I got that running I started with this UART experiment.

    Update: The Characters appear inside the "m_rx_fifo" struct so the RX is setup correctly and also after each received character the "err_code" is 0x00, but after leaving "app_uart_get" the program doesn't jump back into your routine but inside the routine "uart_event_handle" which is part of the "main.c" which is weird.

    Btw. Thank you for your intensive help on this problem! That's highly appreciated.

  • FormerMember
    0 FormerMember

    The uart_event_handle is provided upon UART initialization, and since there will be a UART interrupt upon a reception over UART, it is normal that the uart_event_handle will be called. In the small example I uploaded, the softdevice is not enabled, no BLE link, etc., so the firmware should go to the error handler after calling ble_nus_string_send() (I believe)).

    The priority of uart_event_handle is APP_IRQ_PRIORITY_LOWEST, which is higher than the main loop. Therefore, if characters are sent continuously over UART, there will always be a UART interrupt, and it will not be possible to return to the main thread.

  • First: I can't upload my project files to this answer (see the Top in Capital letters). Why?

    Second: In your python script RTSCTS Flow Control was set to 1 while in the main.c the Flow Control was disabled. That's why I had strange behavior. And Flow Control HAS to be enabled. Program gets stuck if it's disabled. But the errorcode is still 0x05. So please check out my project file, if I can upload it.

  • FormerMember
    0 FormerMember in reply to H4NNE5

    Did you upload your project file?

  • FormerMember
    0 FormerMember in reply to H4NNE5

    After testing your example, and comparing it with the "bare" uart example in the SDK, I realized why app_uart_get() always returns NRF_ERROR_NOT_FOUND (0x05): The mechanism in the "bare" uart example and ble_app_uart is different. The bare UART example uses polling/pulling to check if characters have been transmitted over UART, while ble_app_uart is event driven. The difference between the two examples lies in uart_error_handle (uart) and uart_event_handle (ble_app_uart).

    In the bare uart example, uart_error_handle does only check for communication errors, and does not handle incoming data.

    In ble_app_uart, uart_event_handle will handle the event for incoming data (APP_UART_DATA_READY). Since UART is running on higher priority than main(), uart_event_handle --> APP_UART_DATA_READY --> app_uart_get() will always the data before app_uart_get() in main. app_uart_get() in main will return NRF_ERROR_NOT_FOUND because all incoming characters have already been read.

Related