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(" 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;
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?
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method