UART not working with ble_app_hrs_c

Hello Nordic Team!

I'm working with the ble_app_hrs_c and a UART code I developed following the peripheral/uart example. 

On the peripheral/uart example we have the following includes:

#include "app_uart.h"
#include "app_error.h"
#include "nrf_delay.h"
#include "nrf.h"
#include "bsp.h"

When I "copy/paste" these includes on the ble_app_hrs_c and build it, it says "app_uart.h no such file or directory".

I know this is due to ble_app_hrs_c not using these files, but since I used the peripheral/uart example as base code, I don't know how to add them ;) 

I really appreciate all your help and thanks in advance!

  • Hi,

    You need to add the source files and include directories to your project. How to do this depends on the toolchain you are using.

    Segger Embedded Studio:

    • Source files:
      • In the Project Explorer tab right-click on the folder you want to add the source file under.
      • Select Add Existing File and find the source file to add.
    • Include directories:
      • Right-click on the project (for example Project ble_app_hrs_c_pca10056_s140) > Options > Preprocessor.
      • Make sure you have selected Common as configuration, and not Debug or Release.
      • Go to User Include Directories and add the path to the include directory there. Make sure that the path is correct seen from the project file. You can look at the other user include directories to find what the path should be. For example if the path to button is this:
        ../../../../../../components/libraries/button
        Then the path to app_uart.h should be the following:
        ../../../../../../components/libraries/uart

    GCC:

    If you are using GCC you must make changes in the Makefile.

    • Source files:
      • Add the path of the source files to SRC_FILES:
        $(SDK_ROOT)/components/libraries/uart/uart.c \
    • Include directories:
      • Add the path of the include directories to INC_FOLDERS:
        $(SDK_ROOT)/components/libraries/uart \

    Best regards,

    Marte

  • Hello Marte, thanks a lot for your answer!

    I followed your instructions and after adding the module in the sdk_config.h the compiler was able to find the .h files and it's building ok )

    When debugging it, it triggers the following error: 

    <info> app_timer: RTC: initialized.
    <error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] at C:\Users\Juan\Downloads\nRF5_SDK_17.1.0_ddde560\examples\Te st\ble_app_hrs_c_UART\main.c:1004
    PC at: 0x0002D18B
    <error> app: End of error report

    The error is triggered by the function: APP_UART_FIFO_INIT(&com_params, UART_RX_BUFF_SIZE, UART_RX_BUFF_SIZE, uart_err_handler, APP_IRQ_PRIORITY_LOWEST, err_code);

    I just added basic functions from a working UART example I already have, so I don't know where to look at.

    Thanks again for your patience and all your help

    Edit: the error is coming from: 

    nrf_drv_uart_init(&app_uart_inst, &config, uart_event_handler);

  • Hi,

    Try setting NRF_LOG_BACKEND_UART_ENABLED to 0 in sdk_config.h. The logger module is using the same UARTE instance as the app uart library, so when using app uart you must disable logging over UART.

    Best regards,

    Marte

  • Hi Marte, that worked instantly, thanks a lot!

    I think this will be the last question:

    The UART is working when I transmit from the disco board to the nRF, but when transmitting from the nRF to the disco, I'm seeing the printf in the nRF debug console, instead of my UART communication.

    Could it be possible that is still using the NRG_LOG uart pins or something like that?

    Note: I use a simple printf in the nRF code and it worked perfectly in my other example. 

    Thanks in advance and have a great weekend :) 

  • Hi,

    Juan Gomez said:
    Could it be possible that is still using the NRG_LOG uart pins or something like that?

    Yes, you should also remove NRF_LOG_BACKEND_UART_TX_PIN from sdk_config.h.

    Best regards,

    Marte

Related