Unable to insert breakpoint in timer interrupt handler

Hi, I'm delevoping an appilcation which can generate one sample per 20 us (accomplished with timer0) and transmit one ESB packet when 20 samples are collected. Below is the C code for my applciation (modified from esb_ptx example in nRF5 SDK 16.0):

/**
 * Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
#include <stdbool.h>
#include <stdint.h>
#include <string.h>

#include "sdk_common.h"
#include "nrf.h"
#include "nrf_error.h"
#include "app_util.h"
#include "app_error.h"

#include "nrf_esb.h"
#include "nrf_esb_error_codes.h"
#include "nrf_drv_ppi.h"
#include "nrf_drv_timer.h"
#include "nrf_drv_gpiote.h"
#include "boards.h"

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

//// Pin definitions
#define PIN_CLKS                 11         // Use P0.11 (Arduino D0 on nRF52 DK)
#define PIN_BUT1                 BUTTON_1  
#define PIN_SAMPEN               LED_1  

//// Parameters
#define CLKS_PERIOD              20         // Timer0 interval in microseconds
#define NUM_BYTE_SLAV_PKT_DATA   20
#define NUM_BYTE_SLAV_PKT_ID      2
#define NUM_TX_PKT               10

//// Global Variables
uint8_t   saadc_count = 0; 
uint16_t  pid = 0;
uint16_t  dummy=1;

//// Instance declarations
static nrf_esb_payload_t        slav_tx_payload;
static nrf_esb_payload_t        slav_rx_payload;

static const nrf_drv_timer_t m_timer0 = NRF_DRV_TIMER_INSTANCE(0);

static nrf_ppi_channel_t m_ppi_channel1;
static nrf_ppi_channel_t m_ppi_channel2;
static nrf_ppi_channel_t m_ppi_channel3;
static nrf_ppi_channel_t m_ppi_channel4;

//// Function declarations
void pin_but1_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    nrf_drv_gpiote_out_toggle(PIN_SAMPEN);
}


static void timer0_event_handler(nrf_timer_event_t event_type, void * p_context)
{
    uint16_t pid_tmp;
    uint32_t idx_pid;

    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE0:            
            slav_tx_payload.data[NUM_BYTE_SLAV_PKT_ID+saadc_count] = dummy++;

            if (saadc_count == NUM_BYTE_SLAV_PKT_DATA-1){                
                pid_tmp = pid; 
                for (idx_pid=0; idx_pid<NUM_BYTE_SLAV_PKT_ID; idx_pid++)
                {
                    slav_tx_payload.data[NUM_BYTE_SLAV_PKT_ID-1-idx_pid] = (uint8_t) pid_tmp&0xFF;
                    pid_tmp = pid_tmp>>8;

                }
                saadc_count = 0;
                pid++;
                
                // Send packet
                slav_tx_payload.noack = false;
                nrf_esb_write_payload(&slav_tx_payload);
                NRF_LOG_HEXDUMP_DEBUG(slav_tx_payload.data, NUM_BYTE_SLAV_PKT_ID+NUM_BYTE_SLAV_PKT_DATA);
            }
            else {
                saadc_count++;
            }
            
            if (pid==NUM_TX_PKT) {   // [Note] Timer0 cleared w/ NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK
                NRF_LOG_INFO("Stop timer0");
                nrf_drv_timer_disable(&m_timer0);
                nrf_drv_gpiote_out_toggle(PIN_SAMPEN); 
                pid = 0;
                dummy = 0;
            }
        default:
            //Do nothing.
            break;
    }
}


void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
{
    switch (p_event->evt_id)
    {
        // case NRF_ESB_EVENT_TX_SUCCESS:
        //     NRF_LOG_DEBUG("TX SUCCESS EVENT");
        //     break;
        case NRF_ESB_EVENT_TX_FAILED:
            NRF_LOG_DEBUG("TX FAILED EVENT");
            (void) nrf_esb_flush_tx();
            (void) nrf_esb_start_tx();
            break;
        case NRF_ESB_EVENT_RX_RECEIVED:
            // NRF_LOG_DEBUG("RX RECEIVED EVENT");
            while (nrf_esb_read_rx_payload(&slav_rx_payload) == NRF_SUCCESS)
            {
                if (slav_rx_payload.length > 0)
                {
                    NRF_LOG_DEBUG("RX RECEIVED PAYLOAD");
                }
            }
            break;
    }
}


static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}


void clocks_start( void )
{
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;

    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
}


static void gpio_init(void)
{
    ret_code_t err_code;

    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
    
    // PIN_CLKS setting
    nrf_drv_gpiote_out_config_t pin_clks_config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(false);  // init_high=false

    err_code = nrf_drv_gpiote_out_init(PIN_CLKS, &pin_clks_config);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_out_task_enable(PIN_CLKS);
    
    // PIN_BUT1 setting
    nrf_drv_gpiote_in_config_t pin_but1_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);  // hi_accu=false (no use IN_EVENT)
    pin_but1_config.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(PIN_BUT1, &pin_but1_config, pin_but1_handler);  // IN_EVENT = pin_but1_handler
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(PIN_BUT1, true);

    // PIN_SAMPEN setting
    nrf_drv_gpiote_out_config_t pin_sampen_config = GPIOTE_CONFIG_OUT_SIMPLE(true);  // configuring PIN_SAMPEN as output, where GPIOTE is not used; init_high=true 
    // nrf_drv_gpiote_out_config_t pin_sampen_config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(true);  // init_high=true 

    err_code = nrf_drv_gpiote_out_init(PIN_SAMPEN, &pin_sampen_config);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_out_task_enable(PIN_SAMPEN);

}


static void timer0_init(void)
{
    // Check TIMER0 configuration for details.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_1MHz;
    timer_cfg.mode      = NRF_TIMER_MODE_TIMER;
    timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;

    ret_code_t err_code = nrf_drv_timer_init(&m_timer0, &timer_cfg, timer0_event_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&m_timer0,
                                   NRF_TIMER_CC_CHANNEL0, 
                                   nrf_drv_timer_us_to_ticks(&m_timer0, CLKS_PERIOD),
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   true);  // enable_int = true 

    nrf_drv_timer_compare         (&m_timer0,
                                   NRF_TIMER_CC_CHANNEL1, 
                                   nrf_drv_timer_us_to_ticks(&m_timer0, CLKS_PERIOD>>1),
                                   false); // enable_int = false 
}


static void ppi_init(void)
{
    uint32_t err_code = NRF_SUCCESS;

    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);


    /* Configure & enable available PPI channel to start TIMER0 on SENSE_HITOLO of PIN_BUT1 */
    err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel1);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel1,
                                          nrf_drv_gpiote_in_event_addr_get(PIN_BUT1),
                                          nrf_drv_timer_task_address_get(&m_timer0, NRF_TIMER_TASK_START) );
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_enable(m_ppi_channel1);
    APP_ERROR_CHECK(err_code);

    /* Configure & enable available PPI channel to set PIN_CLKS to high on TIMER0 COMPARE[1] match */
    err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel2);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel2,
                                          nrf_drv_timer_event_address_get(&m_timer0, NRF_TIMER_EVENT_COMPARE1),
                                          nrf_drv_gpiote_set_task_addr_get(PIN_CLKS) );
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_enable(m_ppi_channel2);
    APP_ERROR_CHECK(err_code);

    /* Configure & enable available PPI channel to set PIN_CLKS to low on TIMER0 COMPARE[0] match */
    err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel3);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel3,
                                          nrf_drv_timer_event_address_get(&m_timer0, NRF_TIMER_EVENT_COMPARE0),
                                          nrf_drv_gpiote_clr_task_addr_get(PIN_CLKS) );
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_enable(m_ppi_channel3);
    APP_ERROR_CHECK(err_code);

    // /* Configure & enable 4th available PPI channel to set PIN_SAMPEN to low on SENSE_HITOLO of PIN_BUT1 */
    // err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel4);
    // APP_ERROR_CHECK(err_code);
    // err_code = nrf_drv_ppi_channel_assign(m_ppi_channel4,
    //                                       nrf_drv_gpiote_in_event_addr_get(PIN_BUT1),
    //                                       nrf_drv_gpiote_clr_task_addr_get(PIN_SAMPEN) );
    // APP_ERROR_CHECK(err_code);
    // err_code = nrf_drv_ppi_channel_enable(m_ppi_channel4);
    // APP_ERROR_CHECK(err_code);

}


uint32_t esb_init( void )
{
    uint32_t err_code;
    uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
    uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
    uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };

    nrf_esb_config_t nrf_esb_config         = NRF_ESB_DEFAULT_CONFIG;
    nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB_DPL;
    nrf_esb_config.retransmit_delay         = 600;
    nrf_esb_config.bitrate                  = NRF_ESB_BITRATE_2MBPS;
    nrf_esb_config.event_handler            = nrf_esb_event_handler;
    nrf_esb_config.mode                     = NRF_ESB_MODE_PTX;
    nrf_esb_config.selective_auto_ack       = false;

    err_code = nrf_esb_init(&nrf_esb_config);

    VERIFY_SUCCESS(err_code);

    err_code = nrf_esb_set_base_address_0(base_addr_0);
    VERIFY_SUCCESS(err_code);

    err_code = nrf_esb_set_base_address_1(base_addr_1);
    VERIFY_SUCCESS(err_code);

    err_code = nrf_esb_set_prefixes(addr_prefix, NRF_ESB_PIPE_COUNT);
    VERIFY_SUCCESS(err_code);

    return err_code;
}


int main(void)
{
    ret_code_t err_code;

    log_init();
    clocks_start();
    gpio_init();
    timer0_init();
    ppi_init();

    err_code = esb_init();
    APP_ERROR_CHECK(err_code);

    // TX payload init
    slav_tx_payload.pipe   = 0;
    slav_tx_payload.length = NUM_BYTE_SLAV_PKT_ID + NUM_BYTE_SLAV_PKT_DATA;

    NRF_LOG_INFO("ANC raw data transmitter started.");

    while (true)
    {
        __WFE();
    }
}
  

Here're my questions:

1. Why a question mark appears at the breakpoint inserted at the beginning of the following for-loop below? 

2. It seems the program didn't perform the loop operation as expected (i.e., only perform 1 tiem loop rather than that specified by NUM_BYTE_SLAV_PKT_ID). Why? 

                for (idx_pid=0; idx_pid<NUM_BYTE_SLAV_PKT_ID; idx_pid++)
                {
                    slav_tx_payload.data[NUM_BYTE_SLAV_PKT_ID-1-idx_pid] = (uint8_t) pid_tmp&0xFF;
                    pid_tmp = pid_tmp>>8;

                }

 

Thank you in advance for your help.

Best regards,

Johnson

Parents Reply Children
  • Dear Hung Bui,

    Thanks for your replying. Yes now I can add the breakpoint inside the loop and the loop operation works normally now (after setting the [Optimization Level] to "None" as you suggested). 

    I have one more question: I'd like to monitor the element values of slav_tx_payload.data, but why doesn't it show up in both   [Globals] and [Locals] windows?

       

    Thank you again for your help.

    Best regards,

    Johnson

  • Hi Johnson, 
    Could you just right click on the slav_tx_payload.data and select at to watch ? 

  • Dear Hung Bui,

    Thanks for your replying. Now I can monitor the variable slav_tx_payload.data on the watch list.

     

    I have three more questions.

    1. I also made an RX app for my TX with its source code as below, which includes app_uart to output the received packets to the host PC (modified from esb_prx example in nRF5 SDK 16.0).

    /**
     * Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "sdk_common.h"
    #include "nrf.h"
    #include "nrf_esb_error_codes.h"
    #include "nrf_delay.h"
    #include "nrf_esb.h"
    #include "nrf_gpio.h"
    #include "nrf_error.h"
    #include "boards.h"
    
    #include "app_uart.h"
    #if defined (UART_PRESENT)
    #include "nrf_uart.h"
    #endif
    #if defined (UARTE_PRESENT)
    #include "nrf_uarte.h"
    #endif
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    //// Parameters
    #define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE                256                                         /**< UART RX buffer size. */
    #define NUM_BYTE_SLAV_PKT_DATA           20
    #define NUM_BYTE_HOST_CMD                20
    
    
    //// Global Variables
    
    //// Instance declarations
    static nrf_esb_payload_t        tx_payload;
    static nrf_esb_payload_t        rx_payload;
    
    /*lint -save -esym(40, BUTTON_1) -esym(40, BUTTON_2) -esym(40, BUTTON_3) -esym(40, BUTTON_4) -esym(40, LED_1) -esym(40, LED_2) -esym(40, LED_3) -esym(40, LED_4) */
    
    void uart_event_handle(app_uart_evt_t * p_event)
    {
        static uint8_t data_array[NUM_BYTE_HOST_CMD];
        static uint8_t index = 0;
        uint32_t       err_code;
    
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                index++;
    
                if ( (index == NUM_BYTE_HOST_CMD) )
                {
                    if (index > 1)
                    {
                        // NRF_LOG_DEBUG("Ready to send data over BLE NUS");
                        // NRF_LOG_HEXDUMP_DEBUG(data_array, index);
    
                    }
    
                    index = 0;
                }
                break;
    
            case APP_UART_COMMUNICATION_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_communication);
                break;
    
            case APP_UART_FIFO_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_code);
                break;
    
            default:
                break;
        }
    }
    
    
    void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
    {
        uint32_t err_code;
    
        switch (p_event->evt_id)
        {
            case NRF_ESB_EVENT_TX_SUCCESS:
                // NRF_LOG_DEBUG("TX SUCCESS EVENT");
                break;
            case NRF_ESB_EVENT_TX_FAILED:
                // NRF_LOG_DEBUG("TX FAILED EVENT");
                break;
            case NRF_ESB_EVENT_RX_RECEIVED:
                // NRF_LOG_DEBUG("RX RECEIVED EVENT");
                if (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS)
                {
                    nrf_gpio_pin_write(LED_1, 0);
                    NRF_LOG_DEBUG("RX packet pid: %02x", rx_payload.data[0]);
                    // NRF_LOG_HEXDUMP_DEBUG(rx_payload.data, NUM_BYTE_SLAV_PKT_DATA);
                    nrf_gpio_pin_write(LED_1, 1);
    
                    // static uint8_t PID_O, PID_N;  // PID_O: old PID; PID_N: new PID
                    // PID_N = RadioRecvData_A[1];
                    // if ((PID_N == PID_O+1)||((PID_N == 0) &&(PID_O == 0xFF))){
                    //   PID_O = PID_N;
                    // }
                    // else{
                    //   PID_O = PID_N;
                    // }
    
                    for (uint32_t i=0; i<rx_payload.length; i++)
                    {
                        do
                        {
                            err_code = app_uart_put(rx_payload.data[i]);
                            if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                            {
                                NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                                APP_ERROR_CHECK(err_code);
                            }
                        } while (err_code == NRF_ERROR_BUSY);
                    }
                }
                break;
        }
    }
    
    
    static void log_init(void)
    {
        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    }
    
    
    void clocks_start( void )
    {
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_HFCLKSTART = 1;
    
        while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    }
    
    
    void gpio_init( void )
    {
        bsp_board_init(BSP_INIT_LEDS);
    }
    
    
    uint32_t esb_init( void )
    {
        uint32_t err_code;
        uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
        uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
        uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
        nrf_esb_config_t nrf_esb_config         = NRF_ESB_DEFAULT_CONFIG;
        nrf_esb_config.payload_length           = 8;
        nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB_DPL;
        nrf_esb_config.bitrate                  = NRF_ESB_BITRATE_2MBPS;
        nrf_esb_config.mode                     = NRF_ESB_MODE_PRX;
        nrf_esb_config.event_handler            = nrf_esb_event_handler;
        nrf_esb_config.selective_auto_ack       = false;
    
        err_code = nrf_esb_init(&nrf_esb_config);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_0(base_addr_0);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_1(base_addr_1);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_prefixes(addr_prefix, 8);
        VERIFY_SUCCESS(err_code);
    
        return err_code;
    }
    
    
    static void uart_init(void)
    {
        uint32_t                     err_code;
        app_uart_comm_params_t const comm_params =
        {
            .rx_pin_no    = RX_PIN_NUMBER,
            .tx_pin_no    = TX_PIN_NUMBER,
            .rts_pin_no   = RTS_PIN_NUMBER,
            .cts_pin_no   = CTS_PIN_NUMBER,
            .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
            .use_parity   = false,
    #if defined (UART_PRESENT)
            .baud_rate    = NRF_UART_BAUDRATE_115200
    #else
            .baud_rate    = NRF_UARTE_BAUDRATE_115200
    #endif
        };
    
        APP_UART_FIFO_INIT(&comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_event_handle,
                           APP_IRQ_PRIORITY_LOWEST,
                           err_code);
        APP_ERROR_CHECK(err_code);
    }
    
    
    int main(void)
    {
        uint32_t err_code;
    
        uart_init();
        log_init();
        gpio_init();
        clocks_start();
    
        err_code = esb_init();
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_INFO("ANC raw data receiver started.");
    
        err_code = nrf_esb_start_rx();
        APP_ERROR_CHECK(err_code);
    
        while (true)
        {
            if (NRF_LOG_PROCESS() == false)
            {
                __WFE();
            }
        }
    }
    /*lint -restore */
    

    When NUM_TX_PKT in my TX app is set to 10, it works normally (i.e., 10 packets, each containing 22 bytes, are sent to RX after pressing Button 1 on nRF52 DK).

    However, when I set NUM_TX_PKT in my TX app to 20 (the goal is NUM_TX_PKT = 5000), the TX & RX apps fail to work as expected (i.e., it’s supposed to send 20 packets containing 22 bytes each but failed).

    Do you have idea of the possible cause?

    2. I insert the following breakpoints in my TX & RX app as seen below (i.e., TX app stop before nrf_esb_write_payload & RX app stop before app_uart_put). But RX app only stop once after receiving the 1st packet from TX app and then it no longer stops before app_uart_put. In several cases, TX app also fails to stop before nrf_esb_write_payload. Do you have any idea on why this happens?

    3. I already set NRF_LOG_ENABLED to 1 and NRF_LOG_DEFAULT_LEVEL to 3 as seen in my sdk_config.h. Why NRF_LOG in my RX app no longer appears in the debugging window?

    // <e> NRFX_UARTE_ENABLED - nrfx_uarte - UARTE peripheral driver
    //==========================================================
    #ifndef NRFX_UARTE_ENABLED
    #define NRFX_UARTE_ENABLED 1
    #endif
    // <o> NRFX_UARTE0_ENABLED - Enable UARTE0 instance 
    #ifndef NRFX_UARTE0_ENABLED
    #define NRFX_UARTE0_ENABLED 0
    #endif
    
    // <o> NRFX_UARTE_DEFAULT_CONFIG_HWFC  - Hardware Flow Control
     
    // <0=> Disabled 
    // <1=> Enabled 
    
    #ifndef NRFX_UARTE_DEFAULT_CONFIG_HWFC
    #define NRFX_UARTE_DEFAULT_CONFIG_HWFC 0
    #endif
    
    // <o> NRFX_UARTE_DEFAULT_CONFIG_PARITY  - Parity
     
    // <0=> Excluded 
    // <14=> Included 
    
    #ifndef NRFX_UARTE_DEFAULT_CONFIG_PARITY
    #define NRFX_UARTE_DEFAULT_CONFIG_PARITY 0
    #endif
    
    // <o> NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE  - Default Baudrate
     
    // <323584=> 1200 baud 
    // <643072=> 2400 baud 
    // <1290240=> 4800 baud 
    // <2576384=> 9600 baud 
    // <3862528=> 14400 baud 
    // <5152768=> 19200 baud 
    // <7716864=> 28800 baud 
    // <8388608=> 31250 baud 
    // <10289152=> 38400 baud 
    // <15007744=> 56000 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 NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE
    #define NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE 30801920
    #endif
    
    // <o> NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY 6
    #endif
    
    // <e> NRFX_UARTE_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_UARTE_CONFIG_LOG_ENABLED
    #define NRFX_UARTE_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_UARTE_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_UARTE_CONFIG_LOG_LEVEL
    #define NRFX_UARTE_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_UARTE_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_UARTE_CONFIG_INFO_COLOR
    #define NRFX_UARTE_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_UARTE_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_UARTE_CONFIG_DEBUG_COLOR
    #define NRFX_UARTE_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>
    
    // </e>
    
    // <e> NRFX_UART_ENABLED - nrfx_uart - UART peripheral driver
    //==========================================================
    #ifndef NRFX_UART_ENABLED
    #define NRFX_UART_ENABLED 1
    #endif
    // <o> NRFX_UART0_ENABLED - Enable UART0 instance 
    #ifndef NRFX_UART0_ENABLED
    #define NRFX_UART0_ENABLED 0
    #endif
    
    // <o> NRFX_UART_DEFAULT_CONFIG_HWFC  - Hardware Flow Control
     
    // <0=> Disabled 
    // <1=> Enabled 
    
    #ifndef NRFX_UART_DEFAULT_CONFIG_HWFC
    #define NRFX_UART_DEFAULT_CONFIG_HWFC 0
    #endif
    
    // <o> NRFX_UART_DEFAULT_CONFIG_PARITY  - Parity
     
    // <0=> Excluded 
    // <14=> Included 
    
    #ifndef NRFX_UART_DEFAULT_CONFIG_PARITY
    #define NRFX_UART_DEFAULT_CONFIG_PARITY 0
    #endif
    
    // <o> NRFX_UART_DEFAULT_CONFIG_BAUDRATE  - Default Baudrate
     
    // <323584=> 1200 baud 
    // <643072=> 2400 baud 
    // <1290240=> 4800 baud 
    // <2576384=> 9600 baud 
    // <3866624=> 14400 baud 
    // <5152768=> 19200 baud 
    // <7729152=> 28800 baud 
    // <8388608=> 31250 baud 
    // <10309632=> 38400 baud 
    // <15007744=> 56000 baud 
    // <15462400=> 57600 baud 
    // <20615168=> 76800 baud 
    // <30924800=> 115200 baud 
    // <61845504=> 230400 baud 
    // <67108864=> 250000 baud 
    // <123695104=> 460800 baud 
    // <247386112=> 921600 baud 
    // <268435456=> 1000000 baud 
    
    #ifndef NRFX_UART_DEFAULT_CONFIG_BAUDRATE
    #define NRFX_UART_DEFAULT_CONFIG_BAUDRATE 30924800
    #endif
    
    // <o> NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY 6
    #endif
    
    // <e> NRFX_UART_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_UART_CONFIG_LOG_ENABLED
    #define NRFX_UART_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_UART_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_UART_CONFIG_LOG_LEVEL
    #define NRFX_UART_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_UART_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_UART_CONFIG_INFO_COLOR
    #define NRFX_UART_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_UART_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_UART_CONFIG_DEBUG_COLOR
    #define NRFX_UART_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>
    
    // </e>
    
    // <e> UART_ENABLED - nrf_drv_uart - UART/UARTE peripheral driver - legacy layer
    //==========================================================
    #ifndef UART_ENABLED
    #define UART_ENABLED 1
    #endif
    // <o> UART_DEFAULT_CONFIG_HWFC  - Hardware Flow Control
     
    // <0=> Disabled 
    // <1=> Enabled 
    
    #ifndef UART_DEFAULT_CONFIG_HWFC
    #define UART_DEFAULT_CONFIG_HWFC 0
    #endif
    
    // <o> UART_DEFAULT_CONFIG_PARITY  - Parity
     
    // <0=> Excluded 
    // <14=> Included 
    
    #ifndef UART_DEFAULT_CONFIG_PARITY
    #define UART_DEFAULT_CONFIG_PARITY 0
    #endif
    
    // <o> UART_DEFAULT_CONFIG_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 UART_DEFAULT_CONFIG_BAUDRATE
    #define UART_DEFAULT_CONFIG_BAUDRATE 30801920
    #endif
    
    // <o> UART_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    
    // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef UART_DEFAULT_CONFIG_IRQ_PRIORITY
    #define UART_DEFAULT_CONFIG_IRQ_PRIORITY 6
    #endif
    
    // <q> UART_EASY_DMA_SUPPORT  - Driver supporting EasyDMA
     
    
    #ifndef UART_EASY_DMA_SUPPORT
    #define UART_EASY_DMA_SUPPORT 1
    #endif
    
    // <q> UART_LEGACY_SUPPORT  - Driver supporting Legacy mode
     
    
    #ifndef UART_LEGACY_SUPPORT
    #define UART_LEGACY_SUPPORT 1
    #endif
    
    // <e> UART0_ENABLED - Enable UART0 instance
    //==========================================================
    #ifndef UART0_ENABLED
    #define UART0_ENABLED 1
    #endif
    // <q> UART0_CONFIG_USE_EASY_DMA  - Default setting for using EasyDMA
     
    
    #ifndef UART0_CONFIG_USE_EASY_DMA
    #define UART0_CONFIG_USE_EASY_DMA 1
    #endif
    
    // </e>
    
    // </e>
    
    // </h> 
    //==========================================================
    
    // <h> nRF_Libraries 
    
    //==========================================================
    // <q> APP_FIFO_ENABLED  - app_fifo - Software FIFO implementation
     
    
    #ifndef APP_FIFO_ENABLED
    #define APP_FIFO_ENABLED 1
    #endif
    
    // <e> APP_UART_ENABLED - app_uart - UART driver
    //==========================================================
    #ifndef APP_UART_ENABLED
    #define APP_UART_ENABLED 1
    #endif
    // <o> APP_UART_DRIVER_INSTANCE  - UART instance used
     
    // <0=> 0 
    
    #ifndef APP_UART_DRIVER_INSTANCE
    #define APP_UART_DRIVER_INSTANCE 0
    #endif
    
    // </e>
    
    
    
    
    
    // </h> 
    //==========================================================
    
    // </h> 
    //==========================================================
    
    // <h> nRF_Log 
    
    //==========================================================
    // <e> NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend
    //==========================================================
    #ifndef NRF_LOG_BACKEND_RTT_ENABLED
    #define NRF_LOG_BACKEND_RTT_ENABLED 0
    #endif
    // <o> NRF_LOG_BACKEND_RTT_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_RTT_TEMP_BUFFER_SIZE
    #define NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE 64
    #endif
    
    // <o> NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS - Period before retrying writing to RTT 
    #ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS
    #define NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS 1
    #endif
    
    // <o> NRF_LOG_BACKEND_RTT_TX_RETRY_CNT - Writing to RTT retries. 
    // <i> If RTT fails to accept any new data after retries
    // <i> module assumes that host is not active and on next
    // <i> request it will perform only one write attempt.
    // <i> On successful writing, module assumes that host is active
    // <i> and scheme with retry is applied again.
    
    #ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_CNT
    #define NRF_LOG_BACKEND_RTT_TX_RETRY_CNT 3
    #endif
    
    // </e>
    
    // <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 0
    #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>
    
    // <e> NRF_LOG_ENABLED - nrf_log - Logger
    //==========================================================
    #ifndef NRF_LOG_ENABLED
    #define NRF_LOG_ENABLED 1
    #endif
    // <h> Log message pool - Configuration of log message pool
    
    //==========================================================
    // <o> NRF_LOG_MSGPOOL_ELEMENT_SIZE - Size of a single element in the pool of memory objects. 
    // <i> If a small value is set, then performance of logs processing
    // <i> is degraded because data is fragmented. Bigger value impacts
    // <i> RAM memory utilization. The size is set to fit a message with
    // <i> a timestamp and up to 2 arguments in a single memory object.
    
    #ifndef NRF_LOG_MSGPOOL_ELEMENT_SIZE
    #define NRF_LOG_MSGPOOL_ELEMENT_SIZE 20
    #endif
    
    // <o> NRF_LOG_MSGPOOL_ELEMENT_COUNT - Number of elements in the pool of memory objects 
    // <i> If a small value is set, then it may lead to a deadlock
    // <i> in certain cases if backend has high latency and holds
    // <i> multiple messages for long time. Bigger value impacts
    // <i> RAM memory usage.
    
    #ifndef NRF_LOG_MSGPOOL_ELEMENT_COUNT
    #define NRF_LOG_MSGPOOL_ELEMENT_COUNT 8
    #endif
    
    // </h> 
    //==========================================================
    
    // <q> NRF_LOG_ALLOW_OVERFLOW  - Configures behavior when circular buffer is full.
     
    
    // <i> If set then oldest logs are overwritten. Otherwise a 
    // <i> marker is injected informing about overflow.
    
    #ifndef NRF_LOG_ALLOW_OVERFLOW
    #define NRF_LOG_ALLOW_OVERFLOW 1
    #endif
    
    // <o> NRF_LOG_BUFSIZE  - Size of the buffer for storing logs (in bytes).
     
    
    // <i> Must be power of 2 and multiple of 4.
    // <i> If NRF_LOG_DEFERRED = 0 then buffer size can be reduced to minimum.
    // <128=> 128 
    // <256=> 256 
    // <512=> 512 
    // <1024=> 1024 
    // <2048=> 2048 
    // <4096=> 4096 
    // <8192=> 8192 
    // <16384=> 16384 
    
    #ifndef NRF_LOG_BUFSIZE
    #define NRF_LOG_BUFSIZE 1024
    #endif
    
    // <q> NRF_LOG_CLI_CMDS  - Enable CLI commands for the module.
     
    
    #ifndef NRF_LOG_CLI_CMDS
    #define NRF_LOG_CLI_CMDS 0
    #endif
    
    // <o> NRF_LOG_DEFAULT_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRF_LOG_DEFAULT_LEVEL
    #define NRF_LOG_DEFAULT_LEVEL 3
    #endif
    
    // <q> NRF_LOG_DEFERRED  - Enable deffered logger.
     
    
    // <i> Log data is buffered and can be processed in idle.
    
    #ifndef NRF_LOG_DEFERRED
    #define NRF_LOG_DEFERRED 0
    #endif
    
    // <q> NRF_LOG_FILTERS_ENABLED  - Enable dynamic filtering of logs.
     
    
    #ifndef NRF_LOG_FILTERS_ENABLED
    #define NRF_LOG_FILTERS_ENABLED 0
    #endif
    
    // <q> NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED  - Enable use of critical region for non deffered mode when flushing logs.
     
    
    // <i> When enabled NRF_LOG_FLUSH is called from critical section when non deffered mode is used.
    // <i> Log output will never be corrupted as access to the log backend is exclusive
    // <i> but system will spend significant amount of time in critical section
    
    #ifndef NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED
    #define NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED 0
    #endif
    
    // <o> NRF_LOG_STR_PUSH_BUFFER_SIZE  - Size of the buffer dedicated for strings stored using @ref NRF_LOG_PUSH.
     
    // <16=> 16 
    // <32=> 32 
    // <64=> 64 
    // <128=> 128 
    // <256=> 256 
    // <512=> 512 
    // <1024=> 1024 
    
    #ifndef NRF_LOG_STR_PUSH_BUFFER_SIZE
    #define NRF_LOG_STR_PUSH_BUFFER_SIZE 128
    #endif
    
    // <o> NRF_LOG_STR_PUSH_BUFFER_SIZE  - Size of the buffer dedicated for strings stored using @ref NRF_LOG_PUSH.
     
    // <16=> 16 
    // <32=> 32 
    // <64=> 64 
    // <128=> 128 
    // <256=> 256 
    // <512=> 512 
    // <1024=> 1024 
    
    #ifndef NRF_LOG_STR_PUSH_BUFFER_SIZE
    #define NRF_LOG_STR_PUSH_BUFFER_SIZE 128
    #endif
    
    // <e> NRF_LOG_USES_COLORS - If enabled then ANSI escape code for colors is prefixed to every string
    //==========================================================
    #ifndef NRF_LOG_USES_COLORS
    #define NRF_LOG_USES_COLORS 0
    #endif
    // <o> NRF_LOG_COLOR_DEFAULT  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRF_LOG_COLOR_DEFAULT
    #define NRF_LOG_COLOR_DEFAULT 0
    #endif
    
    // <o> NRF_LOG_ERROR_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRF_LOG_ERROR_COLOR
    #define NRF_LOG_ERROR_COLOR 2
    #endif
    
    // <o> NRF_LOG_WARNING_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRF_LOG_WARNING_COLOR
    #define NRF_LOG_WARNING_COLOR 4
    #endif
    
    // </e>
    
    // <e> NRF_LOG_USES_TIMESTAMP - Enable timestamping
    
    // <i> Function for getting the timestamp is provided by the user
    //==========================================================
    #ifndef NRF_LOG_USES_TIMESTAMP
    #define NRF_LOG_USES_TIMESTAMP 0
    #endif
    // <o> NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY - Default frequency of the timestamp (in Hz) or 0 to use app_timer frequency. 
    #ifndef NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY
    #define NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY 0
    #endif
    
    // </e>
    
    // <h> nrf_log module configuration 

    Thank you again for your helps.

    Best regards,

    Johnson

  • Hi Johnson, 
    When you call nrf_esb_write_payload() you need to check for the return value. There are many error codes it may return: 

    /**@brief Function for writing a payload for transmission or acknowledgement.
     *
     * This function writes a payload that is added to the queue. When the module is in PTX mode, the
     * payload is queued for a regular transmission. When the module is in PRX mode, the payload
     * is queued for when a packet is received that requires an acknowledgement with payload.
     *
     * @param[in]   p_payload     Pointer to the structure that contains information and state of the payload.
     *
     * @retval  NRF_SUCCESS                     If the payload was successfully queued for writing.
     * @retval  NRF_ERROR_NULL                  If the required parameter was NULL.
     * @retval  NRF_INVALID_STATE               If the module is not initialized.
     * @retval  NRF_ERROR_NO_MEM                If the TX FIFO is full.
     * @retval  NRF_ERROR_INVALID_LENGTH        If the payload length was invalid (zero or larger than the allowed maximum).
     */
    uint32_t nrf_esb_write_payload(nrf_esb_payload_t const * p_payload);
    There is a chance that the TX FIFO is full, you need to wait for the packets to be sent to continue. 

    Regarding breakpoint in PRX, after you hit the breakpoint, you can't really continue because the timing is wrong or the PTX no longer send the message. You may want to do debugging using UART / RTT log. 

  • Dear Hung Bui,

    Thanks for your replying. Could you help me answer the following questions?

    1. Like I mentioned in my previous article, I set NRF_LOG_ENABLED to 1 and NRF_LOG_DEFAULT_LEVEL to 3 as seen in the sdk_config.h of my RX application (with its C code as below). Why NRF_LOG in my RX app no longer appears in the debugging window?

    // <e> NRFX_UARTE_ENABLED - nrfx_uarte - UARTE peripheral driver
    //==========================================================
    #ifndef NRFX_UARTE_ENABLED
    #define NRFX_UARTE_ENABLED 1
    #endif
    // <o> NRFX_UARTE0_ENABLED - Enable UARTE0 instance 
    #ifndef NRFX_UARTE0_ENABLED
    #define NRFX_UARTE0_ENABLED 0
    #endif
    
    // <o> NRFX_UARTE_DEFAULT_CONFIG_HWFC  - Hardware Flow Control
     
    // <0=> Disabled 
    // <1=> Enabled 
    
    #ifndef NRFX_UARTE_DEFAULT_CONFIG_HWFC
    #define NRFX_UARTE_DEFAULT_CONFIG_HWFC 0
    #endif
    
    // <o> NRFX_UARTE_DEFAULT_CONFIG_PARITY  - Parity
     
    // <0=> Excluded 
    // <14=> Included 
    
    #ifndef NRFX_UARTE_DEFAULT_CONFIG_PARITY
    #define NRFX_UARTE_DEFAULT_CONFIG_PARITY 0
    #endif
    
    // <o> NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE  - Default Baudrate
     
    // <323584=> 1200 baud 
    // <643072=> 2400 baud 
    // <1290240=> 4800 baud 
    // <2576384=> 9600 baud 
    // <3862528=> 14400 baud 
    // <5152768=> 19200 baud 
    // <7716864=> 28800 baud 
    // <8388608=> 31250 baud 
    // <10289152=> 38400 baud 
    // <15007744=> 56000 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 NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE
    #define NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE 30801920
    #endif
    
    // <o> NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY 6
    #endif
    
    // <e> NRFX_UARTE_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_UARTE_CONFIG_LOG_ENABLED
    #define NRFX_UARTE_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_UARTE_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_UARTE_CONFIG_LOG_LEVEL
    #define NRFX_UARTE_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_UARTE_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_UARTE_CONFIG_INFO_COLOR
    #define NRFX_UARTE_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_UARTE_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_UARTE_CONFIG_DEBUG_COLOR
    #define NRFX_UARTE_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>
    
    // </e>
    
    // <e> NRFX_UART_ENABLED - nrfx_uart - UART peripheral driver
    //==========================================================
    #ifndef NRFX_UART_ENABLED
    #define NRFX_UART_ENABLED 1
    #endif
    // <o> NRFX_UART0_ENABLED - Enable UART0 instance 
    #ifndef NRFX_UART0_ENABLED
    #define NRFX_UART0_ENABLED 0
    #endif
    
    // <o> NRFX_UART_DEFAULT_CONFIG_HWFC  - Hardware Flow Control
     
    // <0=> Disabled 
    // <1=> Enabled 
    
    #ifndef NRFX_UART_DEFAULT_CONFIG_HWFC
    #define NRFX_UART_DEFAULT_CONFIG_HWFC 0
    #endif
    
    // <o> NRFX_UART_DEFAULT_CONFIG_PARITY  - Parity
     
    // <0=> Excluded 
    // <14=> Included 
    
    #ifndef NRFX_UART_DEFAULT_CONFIG_PARITY
    #define NRFX_UART_DEFAULT_CONFIG_PARITY 0
    #endif
    
    // <o> NRFX_UART_DEFAULT_CONFIG_BAUDRATE  - Default Baudrate
     
    // <323584=> 1200 baud 
    // <643072=> 2400 baud 
    // <1290240=> 4800 baud 
    // <2576384=> 9600 baud 
    // <3866624=> 14400 baud 
    // <5152768=> 19200 baud 
    // <7729152=> 28800 baud 
    // <8388608=> 31250 baud 
    // <10309632=> 38400 baud 
    // <15007744=> 56000 baud 
    // <15462400=> 57600 baud 
    // <20615168=> 76800 baud 
    // <30924800=> 115200 baud 
    // <61845504=> 230400 baud 
    // <67108864=> 250000 baud 
    // <123695104=> 460800 baud 
    // <247386112=> 921600 baud 
    // <268435456=> 1000000 baud 
    
    #ifndef NRFX_UART_DEFAULT_CONFIG_BAUDRATE
    #define NRFX_UART_DEFAULT_CONFIG_BAUDRATE 30924800
    #endif
    
    // <o> NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY 6
    #endif
    
    // <e> NRFX_UART_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_UART_CONFIG_LOG_ENABLED
    #define NRFX_UART_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_UART_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_UART_CONFIG_LOG_LEVEL
    #define NRFX_UART_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_UART_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_UART_CONFIG_INFO_COLOR
    #define NRFX_UART_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_UART_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_UART_CONFIG_DEBUG_COLOR
    #define NRFX_UART_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>
    
    // </e>
    
    // <e> UART_ENABLED - nrf_drv_uart - UART/UARTE peripheral driver - legacy layer
    //==========================================================
    #ifndef UART_ENABLED
    #define UART_ENABLED 1
    #endif
    // <o> UART_DEFAULT_CONFIG_HWFC  - Hardware Flow Control
     
    // <0=> Disabled 
    // <1=> Enabled 
    
    #ifndef UART_DEFAULT_CONFIG_HWFC
    #define UART_DEFAULT_CONFIG_HWFC 0
    #endif
    
    // <o> UART_DEFAULT_CONFIG_PARITY  - Parity
     
    // <0=> Excluded 
    // <14=> Included 
    
    #ifndef UART_DEFAULT_CONFIG_PARITY
    #define UART_DEFAULT_CONFIG_PARITY 0
    #endif
    
    // <o> UART_DEFAULT_CONFIG_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 UART_DEFAULT_CONFIG_BAUDRATE
    #define UART_DEFAULT_CONFIG_BAUDRATE 30801920
    #endif
    
    // <o> UART_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    
    // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef UART_DEFAULT_CONFIG_IRQ_PRIORITY
    #define UART_DEFAULT_CONFIG_IRQ_PRIORITY 6
    #endif
    
    // <q> UART_EASY_DMA_SUPPORT  - Driver supporting EasyDMA
     
    
    #ifndef UART_EASY_DMA_SUPPORT
    #define UART_EASY_DMA_SUPPORT 1
    #endif
    
    // <q> UART_LEGACY_SUPPORT  - Driver supporting Legacy mode
     
    
    #ifndef UART_LEGACY_SUPPORT
    #define UART_LEGACY_SUPPORT 1
    #endif
    
    // <e> UART0_ENABLED - Enable UART0 instance
    //==========================================================
    #ifndef UART0_ENABLED
    #define UART0_ENABLED 1
    #endif
    // <q> UART0_CONFIG_USE_EASY_DMA  - Default setting for using EasyDMA
     
    
    #ifndef UART0_CONFIG_USE_EASY_DMA
    #define UART0_CONFIG_USE_EASY_DMA 1
    #endif
    
    // </e>
    
    // </e>
    
    // </h> 
    //==========================================================
    
    // <h> nRF_Libraries 
    
    //==========================================================
    // <q> APP_FIFO_ENABLED  - app_fifo - Software FIFO implementation
     
    
    #ifndef APP_FIFO_ENABLED
    #define APP_FIFO_ENABLED 1
    #endif
    
    // <e> APP_UART_ENABLED - app_uart - UART driver
    //==========================================================
    #ifndef APP_UART_ENABLED
    #define APP_UART_ENABLED 1
    #endif
    // <o> APP_UART_DRIVER_INSTANCE  - UART instance used
     
    // <0=> 0 
    
    #ifndef APP_UART_DRIVER_INSTANCE
    #define APP_UART_DRIVER_INSTANCE 0
    #endif
    
    // </e>
    
    
    
    
    
    // </h> 
    //==========================================================
    
    // </h> 
    //==========================================================
    
    // <h> nRF_Log 
    
    //==========================================================
    // <e> NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend
    //==========================================================
    #ifndef NRF_LOG_BACKEND_RTT_ENABLED
    #define NRF_LOG_BACKEND_RTT_ENABLED 0
    #endif
    // <o> NRF_LOG_BACKEND_RTT_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_RTT_TEMP_BUFFER_SIZE
    #define NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE 64
    #endif
    
    // <o> NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS - Period before retrying writing to RTT 
    #ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS
    #define NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS 1
    #endif
    
    // <o> NRF_LOG_BACKEND_RTT_TX_RETRY_CNT - Writing to RTT retries. 
    // <i> If RTT fails to accept any new data after retries
    // <i> module assumes that host is not active and on next
    // <i> request it will perform only one write attempt.
    // <i> On successful writing, module assumes that host is active
    // <i> and scheme with retry is applied again.
    
    #ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_CNT
    #define NRF_LOG_BACKEND_RTT_TX_RETRY_CNT 3
    #endif
    
    // </e>
    
    // <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 0
    #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>
    
    // <e> NRF_LOG_ENABLED - nrf_log - Logger
    //==========================================================
    #ifndef NRF_LOG_ENABLED
    #define NRF_LOG_ENABLED 1
    #endif
    // <h> Log message pool - Configuration of log message pool
    
    //==========================================================
    // <o> NRF_LOG_MSGPOOL_ELEMENT_SIZE - Size of a single element in the pool of memory objects. 
    // <i> If a small value is set, then performance of logs processing
    // <i> is degraded because data is fragmented. Bigger value impacts
    // <i> RAM memory utilization. The size is set to fit a message with
    // <i> a timestamp and up to 2 arguments in a single memory object.
    
    #ifndef NRF_LOG_MSGPOOL_ELEMENT_SIZE
    #define NRF_LOG_MSGPOOL_ELEMENT_SIZE 20
    #endif
    
    // <o> NRF_LOG_MSGPOOL_ELEMENT_COUNT - Number of elements in the pool of memory objects 
    // <i> If a small value is set, then it may lead to a deadlock
    // <i> in certain cases if backend has high latency and holds
    // <i> multiple messages for long time. Bigger value impacts
    // <i> RAM memory usage.
    
    #ifndef NRF_LOG_MSGPOOL_ELEMENT_COUNT
    #define NRF_LOG_MSGPOOL_ELEMENT_COUNT 8
    #endif
    
    // </h> 
    //==========================================================
    
    // <q> NRF_LOG_ALLOW_OVERFLOW  - Configures behavior when circular buffer is full.
     
    
    // <i> If set then oldest logs are overwritten. Otherwise a 
    // <i> marker is injected informing about overflow.
    
    #ifndef NRF_LOG_ALLOW_OVERFLOW
    #define NRF_LOG_ALLOW_OVERFLOW 1
    #endif
    
    // <o> NRF_LOG_BUFSIZE  - Size of the buffer for storing logs (in bytes).
     
    
    // <i> Must be power of 2 and multiple of 4.
    // <i> If NRF_LOG_DEFERRED = 0 then buffer size can be reduced to minimum.
    // <128=> 128 
    // <256=> 256 
    // <512=> 512 
    // <1024=> 1024 
    // <2048=> 2048 
    // <4096=> 4096 
    // <8192=> 8192 
    // <16384=> 16384 
    
    #ifndef NRF_LOG_BUFSIZE
    #define NRF_LOG_BUFSIZE 1024
    #endif
    
    // <q> NRF_LOG_CLI_CMDS  - Enable CLI commands for the module.
     
    
    #ifndef NRF_LOG_CLI_CMDS
    #define NRF_LOG_CLI_CMDS 0
    #endif
    
    // <o> NRF_LOG_DEFAULT_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRF_LOG_DEFAULT_LEVEL
    #define NRF_LOG_DEFAULT_LEVEL 3
    #endif
    
    // <q> NRF_LOG_DEFERRED  - Enable deffered logger.
     
    
    // <i> Log data is buffered and can be processed in idle.
    
    #ifndef NRF_LOG_DEFERRED
    #define NRF_LOG_DEFERRED 0
    #endif
    
    // <q> NRF_LOG_FILTERS_ENABLED  - Enable dynamic filtering of logs.
     
    
    #ifndef NRF_LOG_FILTERS_ENABLED
    #define NRF_LOG_FILTERS_ENABLED 0
    #endif
    
    // <q> NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED  - Enable use of critical region for non deffered mode when flushing logs.
     
    
    // <i> When enabled NRF_LOG_FLUSH is called from critical section when non deffered mode is used.
    // <i> Log output will never be corrupted as access to the log backend is exclusive
    // <i> but system will spend significant amount of time in critical section
    
    #ifndef NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED
    #define NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED 0
    #endif
    
    // <o> NRF_LOG_STR_PUSH_BUFFER_SIZE  - Size of the buffer dedicated for strings stored using @ref NRF_LOG_PUSH.
     
    // <16=> 16 
    // <32=> 32 
    // <64=> 64 
    // <128=> 128 
    // <256=> 256 
    // <512=> 512 
    // <1024=> 1024 
    
    #ifndef NRF_LOG_STR_PUSH_BUFFER_SIZE
    #define NRF_LOG_STR_PUSH_BUFFER_SIZE 128
    #endif
    
    // <o> NRF_LOG_STR_PUSH_BUFFER_SIZE  - Size of the buffer dedicated for strings stored using @ref NRF_LOG_PUSH.
     
    // <16=> 16 
    // <32=> 32 
    // <64=> 64 
    // <128=> 128 
    // <256=> 256 
    // <512=> 512 
    // <1024=> 1024 
    
    #ifndef NRF_LOG_STR_PUSH_BUFFER_SIZE
    #define NRF_LOG_STR_PUSH_BUFFER_SIZE 128
    #endif
    
    // <e> NRF_LOG_USES_COLORS - If enabled then ANSI escape code for colors is prefixed to every string
    //==========================================================
    #ifndef NRF_LOG_USES_COLORS
    #define NRF_LOG_USES_COLORS 0
    #endif
    // <o> NRF_LOG_COLOR_DEFAULT  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRF_LOG_COLOR_DEFAULT
    #define NRF_LOG_COLOR_DEFAULT 0
    #endif
    
    // <o> NRF_LOG_ERROR_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRF_LOG_ERROR_COLOR
    #define NRF_LOG_ERROR_COLOR 2
    #endif
    
    // <o> NRF_LOG_WARNING_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRF_LOG_WARNING_COLOR
    #define NRF_LOG_WARNING_COLOR 4
    #endif
    
    // </e>
    
    // <e> NRF_LOG_USES_TIMESTAMP - Enable timestamping
    
    // <i> Function for getting the timestamp is provided by the user
    //==========================================================
    #ifndef NRF_LOG_USES_TIMESTAMP
    #define NRF_LOG_USES_TIMESTAMP 0
    #endif
    // <o> NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY - Default frequency of the timestamp (in Hz) or 0 to use app_timer frequency. 
    #ifndef NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY
    #define NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY 0
    #endif
    
    // </e>
    
    // <h> nrf_log module configuration 

    /**
     * Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "sdk_common.h"
    #include "nrf.h"
    #include "nrf_esb_error_codes.h"
    #include "nrf_delay.h"
    #include "nrf_esb.h"
    #include "nrf_gpio.h"
    #include "nrf_error.h"
    #include "boards.h"
    
    #include "app_uart.h"
    #if defined (UART_PRESENT)
    #include "nrf_uart.h"
    #endif
    #if defined (UARTE_PRESENT)
    #include "nrf_uarte.h"
    #endif
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    //// Parameters
    #define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE                256                                         /**< UART RX buffer size. */
    #define NUM_BYTE_SLAV_PKT_DATA           20
    #define NUM_BYTE_HOST_CMD                20
    
    
    //// Global Variables
    
    //// Instance declarations
    static nrf_esb_payload_t        tx_payload;
    static nrf_esb_payload_t        rx_payload;
    
    /*lint -save -esym(40, BUTTON_1) -esym(40, BUTTON_2) -esym(40, BUTTON_3) -esym(40, BUTTON_4) -esym(40, LED_1) -esym(40, LED_2) -esym(40, LED_3) -esym(40, LED_4) */
    
    void uart_event_handle(app_uart_evt_t * p_event)
    {
        static uint8_t data_array[NUM_BYTE_HOST_CMD];
        static uint8_t index = 0;
        uint32_t       err_code;
    
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                index++;
    
                if ( (index == NUM_BYTE_HOST_CMD) )
                {
                    if (index > 1)
                    {
                        // NRF_LOG_DEBUG("Ready to send data over BLE NUS");
                        // NRF_LOG_HEXDUMP_DEBUG(data_array, index);
    
                    }
    
                    index = 0;
                }
                break;
    
            case APP_UART_COMMUNICATION_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_communication);
                break;
    
            case APP_UART_FIFO_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_code);
                break;
    
            default:
                break;
        }
    }
    
    
    void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
    {
        uint32_t err_code;
    
        switch (p_event->evt_id)
        {
            case NRF_ESB_EVENT_TX_SUCCESS:
                // NRF_LOG_DEBUG("TX SUCCESS EVENT");
                break;
            case NRF_ESB_EVENT_TX_FAILED:
                // NRF_LOG_DEBUG("TX FAILED EVENT");
                break;
            case NRF_ESB_EVENT_RX_RECEIVED:
                // NRF_LOG_DEBUG("RX RECEIVED EVENT");
                if (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS)
                {
                    nrf_gpio_pin_write(LED_1, 0);
                    NRF_LOG_DEBUG("RX packet pid: %02x", rx_payload.data[0]);
                    // NRF_LOG_HEXDUMP_DEBUG(rx_payload.data, NUM_BYTE_SLAV_PKT_DATA);
                    nrf_gpio_pin_write(LED_1, 1);
    
                    // static uint8_t PID_O, PID_N;  // PID_O: old PID; PID_N: new PID
                    // PID_N = RadioRecvData_A[1];
                    // if ((PID_N == PID_O+1)||((PID_N == 0) &&(PID_O == 0xFF))){
                    //   PID_O = PID_N;
                    // }
                    // else{
                    //   PID_O = PID_N;
                    // }
    
                    for (uint32_t i=0; i<rx_payload.length; i++)
                    {
                        do
                        {
                            err_code = app_uart_put(rx_payload.data[i]);
                            if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                            {
                                NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                                APP_ERROR_CHECK(err_code);
                            }
                        } while (err_code == NRF_ERROR_BUSY);
                    }
                }
                break;
        }
    }
    
    
    static void log_init(void)
    {
        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    }
    
    
    void clocks_start( void )
    {
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_HFCLKSTART = 1;
    
        while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    }
    
    
    void gpio_init( void )
    {
        bsp_board_init(BSP_INIT_LEDS);
    }
    
    
    uint32_t esb_init( void )
    {
        uint32_t err_code;
        uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
        uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
        uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
        nrf_esb_config_t nrf_esb_config         = NRF_ESB_DEFAULT_CONFIG;
        nrf_esb_config.payload_length           = 8;
        nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB_DPL;
        nrf_esb_config.bitrate                  = NRF_ESB_BITRATE_2MBPS;
        nrf_esb_config.mode                     = NRF_ESB_MODE_PRX;
        nrf_esb_config.event_handler            = nrf_esb_event_handler;
        nrf_esb_config.selective_auto_ack       = false;
    
        err_code = nrf_esb_init(&nrf_esb_config);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_0(base_addr_0);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_1(base_addr_1);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_prefixes(addr_prefix, 8);
        VERIFY_SUCCESS(err_code);
    
        return err_code;
    }
    
    
    static void uart_init(void)
    {
        uint32_t                     err_code;
        app_uart_comm_params_t const comm_params =
        {
            .rx_pin_no    = RX_PIN_NUMBER,
            .tx_pin_no    = TX_PIN_NUMBER,
            .rts_pin_no   = RTS_PIN_NUMBER,
            .cts_pin_no   = CTS_PIN_NUMBER,
            .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
            .use_parity   = false,
    #if defined (UART_PRESENT)
            .baud_rate    = NRF_UART_BAUDRATE_115200
    #else
            .baud_rate    = NRF_UARTE_BAUDRATE_115200
    #endif
        };
    
        APP_UART_FIFO_INIT(&comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_event_handle,
                           APP_IRQ_PRIORITY_LOWEST,
                           err_code);
        APP_ERROR_CHECK(err_code);
    }
    
    
    int main(void)
    {
        uint32_t err_code;
    
        uart_init();
        log_init();
        gpio_init();
        clocks_start();
    
        err_code = esb_init();
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_INFO("ANC raw data receiver started.");
    
        err_code = nrf_esb_start_rx();
        APP_ERROR_CHECK(err_code);
    
        while (true)
        {
            if (NRF_LOG_PROCESS() == false)
            {
                __WFE();
            }
        }
    }
    /*lint -restore */

    2. Currently both in my TX & RX applications the NRF_ESB_MAX_PAYLOAD_LENGTH is set to 32 as seen in their nrf_esb.h. If I’d like to use the maximum 252-byte payload, do I just need to redefine NRF_ESB_MAX_PAYLOAD_LENGTH as 252 in both my TX & RX applications?

    Thank you again for your helps.

    Best regards,

    Johnson

Related