My previous post and the response I got was hugely helpful to my understanding ESB on the nRF52. Now that I grasp the basics, I felt it was appropriate to create a new post for additional questions.
I continue to struggle to replace my PIC & ESP32/nRF24 combination with a nRF52. I have a rudimentary grasp of how ESB should work on the nRF52. However, I am not having any success implementing it.
For my setup I have two ESP32/nRF24 combinations. A dedicated Transmitter and a dedicated Receiver successfully communicating. Therefore, I can confirm my Transmitter Setup and that I understand the addressing and setup requirements. I am using the proven/dedicated ESP32 Transmitter to send.
I programmed the nRF52 (using the nRF5 because that’s the setup information I have, and I don’t want to introduce additional variables).
I have tried to leave the prx code unedited as much as possible except to make the appropriate configuration changes and disable "NRF_LOG_DEFERRED 0". Most of the changes are to esb_init().
I believe I have set the nRF52 setup correctly to be the Receiver, however __WFE() never seems to fire, so no Event is triggered.
I would love for someone to point out where I am making my mistake(s). Otherwise, I am at a dead end. I have included source code for the nRF52 and ESP32.
Here is the output/settings for my ESP32/nRF24 Transmitter:
17:16:53.958 -> SPI Frequency = 10 Mhz
17:16:53.958 -> Channel = 40 (~ 2440 MHz)
17:16:53.958 -> RF Data Rate = 1 MBPS
17:16:53.958 -> RF Power Amplifier = PA_MAX
17:16:53.958 -> RF Low Noise Amplifier = Enabled
17:16:53.992 -> CRC Length = 8 bits
17:16:53.992 -> Address Length = 5 bytes
17:16:53.992 -> Static Payload Length = 32 bytes
17:16:53.992 -> Auto Retry Delay = 1500 microseconds
17:16:53.992 -> Auto Retry Attempts = 15 maximum
17:16:53.992 -> Packets lost on
17:16:53.992 -> current channel = 0
17:16:53.992 -> Retry attempts made for
17:16:53.992 -> last transmission = 0
17:16:53.992 -> Multicast = Disabled
17:16:53.992 -> Custom ACK Payload = Disabled
17:16:53.992 -> Dynamic Payloads = Disabled
17:16:53.992 -> Auto Acknowledgment = Disabled
17:16:53.992 -> Primary Mode = TX
17:16:54.026 -> TX address = 0xc2c2c2c2c2
17:16:54.026 -> pipe 0 ( open ) bound = 0xc2c2c2c2c2
17:16:54.026 -> pipe 1 ( open ) bound = 0xe7e7e7e7e7
17:16:54.026 -> pipe 2 (closed) bound = 0xc3
17:16:54.026 -> pipe 3 (closed) bound = 0xc4
17:16:54.026 -> pipe 4 (closed) bound = 0xc5
17:16:54.026 -> pipe 5 (closed) bound = 0xc6
#include "nrf_esb.h" #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_gpio.h" #include "nrf_error.h" #include "boards.h" #include "nrf_log.h" #include "nrf_log_ctrl.h" #include "nrf_log_default_backends.h" uint8_t led_nr; 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 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"); break; case NRF_ESB_EVENT_RX_RECEIVED: NRF_LOG_DEBUG("RX RECEIVED EVENT"); if (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS) { // Set LEDs identical to the ones on the PTX. nrf_gpio_pin_write(LED_1, !(rx_payload.data[1]%8>0 && rx_payload.data[1]%8<=4)); nrf_gpio_pin_write(LED_2, !(rx_payload.data[1]%8>1 && rx_payload.data[1]%8<=5)); nrf_gpio_pin_write(LED_3, !(rx_payload.data[1]%8>2 && rx_payload.data[1]%8<=6)); nrf_gpio_pin_write(LED_4, !(rx_payload.data[1]%8>3)); NRF_LOG_DEBUG("Receiving packet: %02x", rx_payload.data[1]); } break; } } 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; // OVERWRITE NRF_ESB_DEFAULT_CONFIG nrf_esb_config_t nrf_esb_config = NRF_ESB_DEFAULT_CONFIG; nrf_esb_config.protocol = NRF_ESB_PROTOCOL_ESB; nrf_esb_config.mode = NRF_ESB_MODE_PRX; nrf_esb_config.event_handler = nrf_esb_event_handler; nrf_esb_config.bitrate = NRF_ESB_BITRATE_1MBPS; nrf_esb_config.crc = NRF_ESB_CRC_8BIT; nrf_esb_config.tx_output_power = NRF_ESB_TX_POWER_4DBM; nrf_esb_config.payload_length = 32; nrf_esb_config.selective_auto_ack = false; //err_code = nrf_esb_set_address_length(5); // causes: HardFault_Handler err_code = nrf_esb_set_rf_channel(40); // overwrite default 2 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; } int main(void) { uint32_t err_code; /* Configure board. */ gpio_init(); err_code = NRF_LOG_INIT(NULL); APP_ERROR_CHECK(err_code); NRF_LOG_DEFAULT_BACKENDS_INIT(); int counter = 0; NRF_LOG_INFO("NRF INFO"); clocks_start(); err_code = esb_init(); APP_ERROR_CHECK(err_code); NRF_LOG_INFO("Enhanced ShockBurst Receiver Example started."); err_code = nrf_esb_start_rx(); APP_ERROR_CHECK(err_code); while (true) { bsp_board_led_invert(LED_3); // THIS DOES NOT WORK!? bsp_board_led_invert(2); // THIS WORKS. if (NRF_LOG_PROCESS() == false) { bsp_board_led_invert(3); //LED flashes __WFE(); // WAIT FOR EVENT, NEVER FIRES. SYSTEM STOPS HERE. } //nrf_delay_ms(500); // FOR TESTING LEDS ONLY! } } /*lint -restore */