[BSP layer][nrf52832][nrf52840][nrf52810][nrf52820][ESB(2.4G)] ESB(2.4G) User Manual

Publisher:YudieLatest update time:2022-08-19 Source: csdnKeywords:nrf52832  nrf52840  nrf52810 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

insert image description here

This guide describes what is ESB (Enhanced ShockBurst) and how to use ESB in nRF5 series.


ESB supports two-way data packet communication, including basic protocols for data packet buffering, data packet confirmation, and automatic retransmission of lost data packets. ESB provides low-power radio frequency transmission capabilities


ESB supports basic protocols for bidirectional packet communication including packet buffering, packet acknowledgment, and automatic retransmission of lost packets. The implementation code is small and easy to use.


The ESB protocol is embedded in the hardware of the traditional nRF24L series, while the Enhanced ShockBurst Module (ESB) enables nRF5 series devices to communicate with nRF5 or nRF24L series devices using the ESB protocol.


ESB features automatic packet transaction processing, making it easy to implement reliable bidirectional data links, where a transaction is a packet exchange between two transceivers, one as the primary receiver (PRX) and one as the primary transmitter (PTX).


ESB features:


A star network topology is supported, typically with one master receive and up to eight master transmits.

Supports dynamic payloads (data transfer width) from 1 to 32 bytes in traditional mode

NRF5 series supports static payload (data transmission width) of 1-252 bytes

Each PTX and PRX node supports duplex data transmission and reception

Packet confirmation and automatic packet retransmission function

Each pipe has independent transmit and receive FIFOs

Enhanced ESB that is backward compatible with NRF2401.

resource:


An ESB uses a fixed set of resources and requires exclusive access to them to ensure correct operation.


Radio Frequency (NRF_RADIO)

Timer: NRF_TIMER2, NRF_TIMER3:

PPI (Programmable Peripheral Interconnect) channels 7, 8, 9, 10, 11, 12, 13

Software Interrupt 0

NOTE: No MPU enforces this exclusive access, so manipulating these resources produces undefined behavior. (i.e. it is best to avoid manipulating these resources)


In addition: RF and timer interrupt processing runs at priority 0 (i.e. the highest priority), and ESB callback functions run at priority 1. Therefore, other interrupts used in the application should run at priority 2-7 to ensure correct operation.


/********************************************************************************

* @file    biz_esb.c

* @author jianqiang.xue

* @version V1.0.0

* @date    2021-07-06

* @brief [Business]2.4G management information reference: https://blog.csdn.net/Behold1942/article/details/88236910

********************************************************************************/


/* Includes ------------------------------------------------------------------*/

#include

#include

#include "nrf.h"

#include "nrf_esb.h"

#include "nrf_error.h"

#include "nrf_esb_error_codes.h"

#include "sdk_macros.h"

#include "queue.h"

/* Private Includes ----------------------------------------------------------*/

#include "business_function.h"

#include "business_gpio.h"

#include "log.h"

#include "app_main.h"

#include "biz_esb.h"

#include "os_api.h"

#include "bsp_rng.h"

#include "biz_fds.h"

/* Private Define ------------------------------------------------------------*/

/* External Variables --------------------------------------------------------*/

/* Private Variables ---------------------------------------------------------*/

static nrf_esb_payload_t tx_payload = NRF_ESB_CREATE_PAYLOAD(0, 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00);

static nrf_esb_payload_t rx_payload = {0};


#pragma pack(4)

__attribute__((aligned(4))) uint8_t rf_freq_table[RF_FREQ_MAX_VAL] = {0x20, 0x21, 0x22, 0x23, 0x24};

__attribute__((aligned(4))) uint8_t rf_mac_addr[RF_MAC_MAX_VAL]    = {0x55, 0x56, 0x57, 0x58, 0x59};

#pragma pack()


bool g_esb_init_flag = false;

bool g_flash_write_24g_mac_flag = 0;

bool g_flash_write_24g_freq_flag = 0;


static uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};

static uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};

static uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8};


//Sender

uint8_t rf_tx_freq_index = 0; // Current RF channel number

bool rf_tx_connect_status = false; // false--Not connected true--Connected

uint8_t rf_tx_heart_tick = 0; // Current heartbeat count

uint8_t rf_tx_connect_time = 0; // Current connection duration


// Receiving end

uint8_t rf_rx_freq_index = 0; // Current RF channel number

bool rf_rx_connect_status = false; // false--Not connected true--Connected

uint8_t rf_rx_heart_time = 0; // Current connection duration


// Register the receiving callback function for external use

typedef void(*esb_rx_event_callback)(uint8_t *data, uint16_t len);

static esb_rx_event_callback g_rx_dispose_callback;


// message queue

#define RF_TX_Q_ITEM_CNT                             30

#define RF_TX_Q_ITEM_SIZE                            (12)

/***************Message queue definition**************/

 // Total buffer area for rf_tx message queue

static uint8_t m_rf_tx_q_buff[RF_TX_Q_ITEM_CNT * RF_TX_Q_ITEM_SIZE] = {0};

queue_t m_rf_tx_q =

{

    .pbuff     = m_rf_tx_q_buff,

    .front     = 0,

    .rear      = 0,

    .item_cnt  = RF_TX_Q_ITEM_CNT,

    .item_size = RF_TX_Q_ITEM_SIZE

};

uint8_t g_rf_tx_data[RF_TX_Q_ITEM_SIZE] = {0}; // Temporary buffer for RF messages

/* Private Function Prototypes -----------------------------------------------*/


/*------------------------------------------------【Public function】------------------------------------------------*/

/**

 * @brief [ESB operation] ESB deinitialization

 */

void esb_deinit(void)

{

    if (!g_esb_init_flag)

    {

        return;

    }

    g_esb_init_flag = false;

    nrf_esb_disable();

}


/**

 * @brief [ESB callback event] Receive notification and send and receive events, and process the events

 * @param *p_event: esb event type

 */

void nrf_esb_event_handler(nrf_esb_evt_t const *p_event)

{

    switch (p_event->evt_id)

    {

        case NRF_ESB_EVENT_TX_SUCCESS:

            //LOG_D("---------------NRF_ESB_EVENT_TX_SUCCESS---------------");

            if (get_comm_connect_state() == SYS_CONNECT_TYPE_RF)

            {

                esb_clean_tx_heart_time();

                // If the last time was not connected, clear the running time record

                if (esb_get_tx_connect_state() == false)

                {

                    esb_set_tx_connect_state(true);

                    main_send_signal(SIGNAL_REFRESH_RF_INDICATOR_LIGHT);

                }

            }

            break;


        case NRF_ESB_EVENT_TX_FAILED:

            // Sending failed, switch channel to continue sending

            rf_tx_freq_index++;

            if (rf_tx_freq_index >= RF_FREQ_MAX_VAL)

            {

                // LOG_D("NRF_ESB_EVENT_TX_FAILED");

                rf_tx_freq_index = 0;

            }

            nrf_esb_set_rf_channel(rf_freq_table[rf_tx_freq_index]);

            nrf_esb_start_tx();

            break;


        case NRF_ESB_EVENT_RX_RECEIVED:

            if (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS)

            {

                if (get_comm_connect_state() == SYS_CONNECT_TYPE_RF)

                {

                    esb_clean_rx_heart_time();

                    esb_set_rx_connect_state(true);

                    // LOG_D("data:%02x,%02x,%02x,%02x,%02x|%02x", rx_payload.data[0], rx_payload.data[1],

                    //        rx_payload.data[2], rx_payload.data[3], rx_payload.data[4], rx_payload.length);

                    // Jump to business processing function

                    if (g_rx_dispose_callback)

                    {

                        g_rx_dispose_callback(rx_payload.data, rx_payload.length);

                    }

                }

            }

            break;

    }

}


/**

 * @brief [ESB operation] [get pointer] RF channel array

 * @retval returns the RF channel array pointer, the length is determined by RF_FREQ_MAX_VAL

 */

uint8_t *esb_get_rf_freq_table(void)

{

    return rf_freq_table;

}


/**

 * @brief [ESB operation] [get pointer] Get the new MAC address array

 * @retval returns the pointer to the MAC address array, the length is determined by RF_MAC_MAX_VAL

 */

uint8_t *esb_get_new_rf_mac_addr(void)

{

    random_vector_generate(rf_mac_addr, RF_MAC_MAX_VAL);

    return rf_mac_addr;

}


/**

 * @brief [ESB operation] [get pointer] MAC address array

 * @retval returns the pointer to the MAC address array, the length is determined by RF_MAC_MAX_VAL

 */

uint8_t *esb_get_rf_mac_addr(void)

{

    return rf_mac_addr;

}


/**

 * @brief [ESB operation] MAC reset, get a random value

 */

void esb_rf_mac_init(void)

{

    uint8_t *mac_addr_temp = esb_get_rf_mac_addr();

    if (mac_addr_temp[0] == 0x55 &&

        mac_addr_temp[1] == 0x56 &&

        mac_addr_temp[2] == 0x57 &&

        mac_addr_temp[3] == 0x58 &&

        mac_addr_temp[4] == 0x59)

    {

        random_vector_generate(mac_addr_temp, RF_MAC_MAX_VAL);

        g_flash_write_24g_mac_flag = true;

        LOG_D(" NEW_MAC:%02x %02x %02x %02x %02xrn", esb_get_rf_mac_addr()[0], esb_get_rf_mac_addr()[1],

              esb_get_rf_mac_addr()[2], esb_get_rf_mac_addr()[3], esb_get_rf_mac_addr()[4]);

    }

}


/*------------------------------------------------【Sending end】------------------------------------------------*/

/**

 * @brief [ESB operation] [sender] ESB initialization

 * @retval status

 */

uint32_t esb_tx_init(void)

{

    if (g_esb_init_flag)

    {

        return 0;

    }

    g_esb_init_flag = true;

    uint32_t err_code;


    addr_prefix[2] = rf_mac_addr[0];

    base_addr_1[0] = rf_mac_addr[1];

    base_addr_1[1] = rf_mac_addr[2];

    base_addr_1[2] = rf_mac_addr[3];

    base_addr_1[3] = rf_mac_addr[4];


    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   = 250;

    nrf_esb_config.retransmit_count   = 3;

    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;

    nrf_esb_config.crc                = NRF_ESB_CRC_16BIT;

    nrf_esb_config.tx_output_power    = NRF_ESB_TX_POWER_4DBM;

[1] [2]
Keywords:nrf52832  nrf52840  nrf52810 Reference address:[BSP layer][nrf52832][nrf52840][nrf52810][nrf52820][ESB(2.4G)] ESB(2.4G) User Manual

Previous article:[nrf52][SDK17] Understanding FDS
Next article:[nrf51][nrf52][SDK17] How to achieve low power operation in NRF series? Can it be accessed with freertos?

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components
Guess you like

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号