nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs

nrf52840 esb send and receive bidirectional with nrf24l01 on other end

Hello

I'm using an nrf52840 (PCA10059) together with an nrf24l01 (ESP32, MIRF Library).

My goal is to send a data packet from the nrf52840 which the nrf24l01 can receive, The nrf24l01 should then send a data packet back to the nrf52840.

This seems to be pretty straight forward in the MIRF Library:

	while(1) {
		//When the program is received, the received data is output from the serial port
		if (Nrf24_dataReady(&dev)) {
			Nrf24_getData(&dev, mydata.value);
			ESP_LOGI(pcTaskGetTaskName(0), "Got data:%lu", mydata.now_time);
			
			vTaskDelay(1);
			Nrf24_send(&dev, mydata.value);
			vTaskDelay(1);
			ESP_LOGI(pcTaskGetTaskName(0), "Wait for sending.....");
			if (Nrf24_isSend(&dev)) {
				ESP_LOGI(pcTaskGetTaskName(0),"Send success:%lu", mydata.now_time);
			} else {
				ESP_LOGW(pcTaskGetTaskName(0),"Send fail:");
			}
		}
		vTaskDelay(1);
	}

But I'm not sure how to implement this on the nrf52840. This is my current implementation. How can I send back in this implementation? I'm confused as there is just NRF_ESB_MODE_PTX and NRF_ESB_MODE_PRX but not both:

uint32_t esb_init(void)
{
    nrf_gpio_cfg_output(6);
    nrf_gpio_pin_set(6);

    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_LEGACY_CONFIG;

    nrf_esb_config.retransmit_count = 6;
    nrf_esb_config.selective_auto_ack = false;
    nrf_esb_config.protocol = NRF_ESB_PROTOCOL_ESB;
    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.payload_length = 4;

    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);

    nrf_esb_set_rf_channel(90);

    tx_payload.length = 4;
    tx_payload.pipe = 0;

    tx_payload.data[0] = 0;
    tx_payload.data[1] = 0;
    tx_payload.data[2] = 0;
    tx_payload.data[3] = 0;

    nrf_gpio_pin_clear(6);

    return NRF_SUCCESS;
}

int main(void)
{
    esb_init();

    while (1)
    {
        tx_payload.noack = false;
        nrf_esb_write_payload(&tx_payload);
        
        nrf_delay_ms(10);
    }
}

Parents Reply Children
Related