Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Combining UART and MPU6050

Hello,

I was able to build the example project MPU6050 from Github with SDK 16. However, I used Putty to connect to the board (PCA10056) with baudrate of 115200 on COM3 (the COM Port it is connected to) but I didn't get any debug string. The sdk_config.h file I took directly from the example.

I used GPIO to turn on a LED when a value from the MPU changed, and the LED changed, verifying that the MPU is not faulty, and I setup the read data from the MPU right, just the UART part is incorrect.

May I get some help getting UART running? What to include in sdk_config.h? What function, c source file, header, do I need?

Thank you very much.

Parents Reply Children
  • Hi, 

    The example you taken was from SDK 14.2. And there were some changes to logging since then.

    There are two approaches you can take:

    1. Update based on your current sdk_config
    2. Port your project based on SDK 16 examples

    Regarding to option 1, basically you need to set the following defines to get the uart logging

    • Set NRF_LOG_ENABLED = 1 in sdk_config.h
    • Copy in the NRF_LOG_BACKEND configuration from an example using UART backend, such as examples/ble_peripheral/ble_app_hrs
    • // <e> NRF_LOG_BACKEND_UART_ENABLED - nrf_log_backend_uart - Log UART backend
      //==========================================================
      #ifndef NRF_LOG_BACKEND_UART_ENABLED
      #define NRF_LOG_BACKEND_UART_ENABLED 1
      #endif
      // <o> NRF_LOG_BACKEND_UART_TX_PIN - UART TX pin 
      #ifndef NRF_LOG_BACKEND_UART_TX_PIN
      #define NRF_LOG_BACKEND_UART_TX_PIN 6
      #endif
      
      // <o> NRF_LOG_BACKEND_UART_BAUDRATE  - Default Baudrate
       
      // <323584=> 1200 baud 
      // <643072=> 2400 baud 
      // <1290240=> 4800 baud 
      // <2576384=> 9600 baud 
      // <3862528=> 14400 baud 
      // <5152768=> 19200 baud 
      // <7716864=> 28800 baud 
      // <10289152=> 38400 baud 
      // <15400960=> 57600 baud 
      // <20615168=> 76800 baud 
      // <30801920=> 115200 baud 
      // <61865984=> 230400 baud 
      // <67108864=> 250000 baud 
      // <121634816=> 460800 baud 
      // <251658240=> 921600 baud 
      // <268435456=> 1000000 baud 
      
      #ifndef NRF_LOG_BACKEND_UART_BAUDRATE
      #define NRF_LOG_BACKEND_UART_BAUDRATE 30801920
      #endif
      
      // <o> NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings. 
      // <i> Size of the buffer is a trade-off between RAM usage and processing.
      // <i> if buffer is smaller then strings will often be fragmented.
      // <i> It is recommended to use size which will fit typical log and only the
      // <i> longer one will be fragmented.
      
      #ifndef NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE
      #define NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE 64
      #endif
      
      // </e>
    • Optionally, change NRF_LOG_DEFERRED to 0 if you don't need deferred logging (when using deferred logging you need to run NRF_LOG_FLUSH() in the main loop to get any log output). 
    • Use NRF_LOG_XXX for logging purpose.

     I am able to get logging work with above changes. 

  • Just a quick question. I would like to: On first power on, wait for a button push. Then after it is pushed, go to a "calibration" period and then go to main loop. Also if the button is pushed again, the system goes to "calibration" period and then back to main loop. How can I structure that?

  • Hi, 

    I recommend you open another ticket for this question, to keep this ticket specific for logging related discussions and easy for others to follow as well.

Related