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

Correct use of NRF_LOG for display on Termite

#include <stdbool.h>    //Permite usar funciones booleanas de C++
#include <stdint.h>     //Permite usar funciones generales de C++

#include "nrf.h"
#include <stdbool.h>   
#include <stdint.h>   

#include "nrf.h"
#include "nordic_common.h"
#include "boards.h"
#include "nrf_gpio.h"
#include "nrf_delay.h"  
#include "nrf_log.h"   

/**
 * @brief Function for application main entry.
 */
int main(void)
{
   nrf_gpio_cfg_input(26, NRF_GPIO_PIN_PULLDOWN);

    while (true)
    { 
				NRF_LOG_INFO(26);
    }
}
/** @} */

Hello to everyone.

I have a doubt about the function of NRF_LOG library in nRF52 DK.
I´m trying to display the voltaje value from pin P0.26 on Termite, so I saw in this page that NRF_LOG_ENABLED and NRF_LOG_BACKEND_UART_ENABLED must be in 1 on sdk_config.h, so that´s ready.
Then I try to use NRF_LOG_INFO() to display the value but I found that NRF_LOG_INFO() it´s only for char parameters.
My question is, does NRF_LOG library has a function to be used with integer value or there´s a way to convert int values into char? (line 20).
This project is the "ble_app_blinky_pca10040_s132", so contains its sdk_config.h file, but I replaced the .c file with one mine.
I hope you can help me.

Parents
  • Hi,

    If you want to get the state of the pin, you need to read the pin and store its value to a variable. You can then pass the variable to NRF_LOG:

    uint32_t pin_state = nrf_gpio_pin_read(26);
    NRF_LOG_INFO("Pin state: %d", pin_state);

    NRF_LOG use printf format to format the strings.

    Best regards,
    Jørgen

  • I see that you have not initialized the log module in your application. You need to add this header file to the top of main.c:

    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"

    and these lines in start of main-loop:

    uint32_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);
    
    NRF_LOG_DEFAULT_BACKENDS_INIT();

  • int main(void)
    {
        // Initialize.
        log_init();
        leds_init();
        timers_init();
        buttons_init();
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    	
    	nrf_gpio_cfg_input(26, NRF_GPIO_PIN_PULLDOWN);
    	uint32_t pin_state = nrf_gpio_pin_read(26);
    
        // Start execution.
        NRF_LOG_INFO("Blinky example started.");
    	NRF_LOG_INFO("Pin state: %d", pin_state);
        advertising_start();
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }
    I´m actually cheking the code with "ble_app_blinky" example, because all the configurations to use LOG are already set, but I can´t make it work. I adjusted the original code with my own lines (16, 17, 21) and only prints the message "Pin state: 0", no matter if I introduce up to 1V of power.

Reply
  • int main(void)
    {
        // Initialize.
        log_init();
        leds_init();
        timers_init();
        buttons_init();
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    	
    	nrf_gpio_cfg_input(26, NRF_GPIO_PIN_PULLDOWN);
    	uint32_t pin_state = nrf_gpio_pin_read(26);
    
        // Start execution.
        NRF_LOG_INFO("Blinky example started.");
    	NRF_LOG_INFO("Pin state: %d", pin_state);
        advertising_start();
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }
    I´m actually cheking the code with "ble_app_blinky" example, because all the configurations to use LOG are already set, but I can´t make it work. I adjusted the original code with my own lines (16, 17, 21) and only prints the message "Pin state: 0", no matter if I introduce up to 1V of power.

Children
No Data
Related