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

nRF52840 SDK16 - Print an array of hex values using NRF_LOG_HEXDUMP_INFO

Hi everyone,

I want to serial print an array of bytes in hex format. The array size is 200bytes. I tried to use the NRF_LOG_HEXDUMP_INFO but it doesn't print all the array, it prints just the first 72bytes

The second approach works fine. How I would like to use the  NRF_LOG_HEXDUMP_INFO since it is an out of the box function.

// First approach
  NRF_LOG_HEXDUMP_INFO(read_raw_data,read_payload);

// Second approach
  char changeline = 20;
  for (int i = 0; i < read_payload; i++) {
    NRF_LOG_RAW_INFO("0x%x ", read_raw_data[i]);
    NRF_LOG_FLUSH();
    if (i == changeline-1) {
      NRF_LOG_RAW_INFO("\r\n");
      changeline += 20;
    }
  }

Thanks in advance

Nick

Parents Reply
  • xmm interesting, I miss something because it's still don't work for me. I don't know if this is related, but I read the data from a .hex file and then I fill the read_raw_data buffer. Lastly I print the logs using the  NRF_LOG_HEXDUMP_INFO.

    This is the complete function

    FRESULT ff_result;
    #define read_payload 100
      static char read_raw_data[read_payload] = {0};
      UINT br = 0;
    
      // NA - Open the file to write
      ff_result = f_open(&file, "RAWDATA.hex", FA_READ);
      if (ff_result != FR_OK) {
        NRF_LOG_INFO("Unable to open file: %u", ff_result);
        NRF_LOG_FLUSH();
        return;
      }
    
      ff_result = f_read(&file, read_raw_data, read_payload, &br);
      if (ff_result != FR_OK) {
        NRF_LOG_INFO("\r\nUnable to read the file: %u", ff_result);
        NRF_LOG_FLUSH();
        return;
      }
    
      // NA - Close the file
      ff_result = f_close(&file); // NA - The f_close function closes an open file. Ref: http://elm-chan.org/fsw/ff/doc/close.html
      if (ff_result != FR_OK) {
        NRF_LOG_ERROR("\r\nUnable to close file: %u", ff_result);
        NRF_LOG_FLUSH();
        return;
      }
      NRF_LOG_INFO("Close the file");
    
      // Print the data
      NRF_LOG_HEXDUMP_INFO(read_raw_data,read_payload);
      NRF_LOG_FLUSH();
    
    }

    #define NRF_LOG_BACKEND_RTT_ENABLED 1
    
    #define NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE 64
    
    #define NRF_LOG_BACKEND_UART_ENABLED 0
    
    #define SEGGER_RTT_CONFIG_BUFFER_SIZE_UP 660
    
    #define SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS 14
    
    #define NRF_LOG_MSGPOOL_ELEMENT_SIZE 20
    
    #define NRF_LOG_MSGPOOL_ELEMENT_COUNT 40

    With the current settings I receive the following

    I also tried your example, however with the same results.. So I suppose that the it's not something wrond with my function.

Children
Related