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!

Parents
  • 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);

Reply
  • 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);

Children
  • 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

  • Hi Marte, thanks a lot for your answer!

    I changed the NRF_LOG_BACKEND_UART_TX_PIN to 0 but didn't work :( 

    My main code, the other code is the same as in the examples from Nordic

    int main(void)
    {
        bool erase_bonds;
    
        // Initialize.
        log_init();
        timer_init();
        power_management_init();
        buttons_leds_init(&erase_bonds);
        ble_stack_init();
        gatt_init();
        peer_manager_init();
        db_discovery_init();
        hrs_c_init();
        bas_c_init();
        scan_init();
    
        //uart code
        const app_uart_comm_params_t com_params = {
        
        RX_PIN_NUMBER,
        TX_PIN_NUMBER,
        RTS_PIN_NUMBER,
        CTS_PIN_NUMBER,
        UART_HWFC,
        false,
        NRF_UART_BAUDRATE_115200
      };  
      
        uint32_t err_code;
    
        APP_UART_FIFO_INIT(&com_params, UART_RX_BUFF_SIZE, UART_RX_BUFF_SIZE, uart_err_handler, APP_IRQ_PRIORITY_LOWEST, err_code);
        
        APP_ERROR_CHECK(err_code);
        
        
        //Start execution.
     
      while(true){
        
        uint8_t cr;
    
        while(app_uart_get(&cr) != NRF_SUCCESS){
          
          if(cr == '1'){
            printf("connected");
            scanning_start(&erase_bonds);
    
            for (;;){
            idle_state_handle();
              }
          }
    
          else if(cr == '2'){
            
            bsp_board_leds_off();
            printf("Off");
    
          }
          else if(cr == '3'){
            
            bsp_board_leds_on();
            printf("32");
          }
          else if(cr == '4'){
            
            bsp_board_leds_off();
            printf((uint8_t*)"OTA");
          }
    
          cr = 0;
        }
      }
    
    }

    I tested my uart code both before and after the //initialize. If I use j-link to download the code, it won't work, and if I use debug mode, it prints to the debug console from SES.

    I tend to think is something in the sdk.h, but don't know where to look.

    Thanks a lot for the help!

Related