This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF51822 to NRF24L01

I have a NRF24L01 board, which acts as a receiver. It listens on RF channel 2 using address pipe 0 address as follows 0xC47B4D0331. I am able to transmit to this NRF24L01 board using another NRF24L01 board which acts as the Tx. This has been tested to work.

I am trying to program a NRF51822 as a Tx to work in ESB mode so that I can communicate to the NRF24L01 board as Rx with address pipe 0 set to 0xC47B4D0331.

The code below doesn't work. Can some one comment whether this is the way to go.

#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_esb.h"

#define PIPE_NUMBER 0 ///pipe 0
#define TX_PAYLOAD_LENGTH 10
static uint8_t my_tx_payload[]= {0,0,0,0,1,0,0,0,0,0};                ///< Payload to send to PRX.
static uint8_t my_rx_payload[10]; ///< Placeholder for received ACK payloads from PRX. 
int main(void)
{
	
	// Setup port directions
	nrf_gpio_port_dir_set(2, NRF_GPIO_PORT_DIR_OUTPUT);

	// Initialise ESB
        nrf_esb_set_crc_length(	NRF_ESB_CRC_LENGTH_2_BYTE));
	
	nrf_esb_init(NRF_ESB_MODE_PTX);
	

	nrf_esb_set_base_address_length(NRF_ESB_BASE_ADDRESS_LENGTH_4B);

	nrf_esb_set_address_prefix_byte(0,0xC4);
	nrf_esb_set_base_address_0(0x7b4d0331);
	nrf_esb_set_channel(2);
	nrf_esb_enable();

	// Add packet into TX queue

	(void)nrf_esb_add_packet_to_tx_fifo(PIPE_NUMBER, my_tx_payload, 10, NRF_ESB_PACKET_USE_ACK);

	while(1)
	{
	
	}
	

}
// If an ACK was received, we send another packet.
void nrf_esb_tx_success(uint32_t tx_pipe, int32_t rssi){
	// Read buttons and load data payload into TX queue
	// my_tx_payload[0] = nrf_gpio_port_read(BUTTONS);
	(void)nrf_esb_add_packet_to_tx_fifo(PIPE_NUMBER, my_tx_payload, TX_PAYLOAD_LENGTH, NRF_ESB_PACKET_USE_ACK);
}


// If the transmission failed, send a new packet.
void nrf_esb_tx_failed(uint32_t tx_pipe){
	(void)nrf_esb_add_packet_to_tx_fifo(PIPE_NUMBER, my_tx_payload, TX_PAYLOAD_LENGTH, NRF_ESB_PACKET_USE_ACK);}


void nrf_esb_rx_data_ready(uint32_t rx_pipe, int32_t rssi){
	uint32_t my_rx_payload_length;
	// Pop packet and write first byte of the payload to the GPIO port.
	(void)nrf_esb_fetch_packet_from_rx_fifo(PIPE_NUMBER, my_rx_payload, &my_rx_payload_length);
	if (my_rx_payload_length > 0)
	{
// light up LED on port 21 if ack received
		nrf_gpio_port_write(2,16);
	}
}

void nrf_esb_disabled(void)
{}
  • Further to my earlier post, I have managed to get the following working

    NRF24L01 as a Tx NRF51822 as a Rx

    The working code using the esb library is as attached.

    However, I am still not able to get the reverse of it, i.e NRF24L01 acting as Rx and NRF51822 as Tx. To change the attached code in to Tx, I have modified

    
    	nrf_esb_init(NRF_ESB_MODE_PRX);
    to
    	nrf_esb_init(NRF_ESB_MODE_PTX);
    
    

    I added a bit of code in the tx_success and tx_failed methods.

    But the tx_success or tx_failed methods do not get executed at all.

    Any thoughts?

    workingesbrxwithlibcallsmain.c

  • I have got the NRF51822 to work as Tx as well. It looks like that the NRF51822 radio switches off if the TX fifo has no more data. Initially my tx fifo was having a single packet and I was adding new packets in the method nrf_esb_tx_success - this resulted in the first packet getting transmitted but the subsequent packets added in the esb_tx_success method were getting ignored.

    I can only infer that the chip checks the FIFO before it calls the esb_tx_success and shuts down the radio if it finds no data in FIFO. I thought adding a packet to FIFO should enable the radio but that doesn't seem the case. May be some one from Nordic can explain.

    I just modified the code to have 2 packets at the start. With this the FIFO is not empty after the first packet tx and when nrf_esb_tx_success is called subsequent packets can be added and this results in a continued broadcast as a Tx.

    Working code attached for reference

    main.c

  • Hi Krishna Kumar, Did you get to fix your problem with the NRF51822 as a Tx and the NRF24L01 as a Rx ? I would be interested if you have any tricks to share ;)

  • The working code for your query is in the attachment main.c of the accepted answer. Please refer to it.

    The two main things to keep in mind are

    1. The address needs to be correctly split as base address and the rest

    2. Initial tx queue needs to have atleast 2 payloads or else the radio seems to switch off after the first payload, if you refer to the code it will make more sense.

  • Thanks a lot for your answer, it helped a lot !!! A 1 byte payload works for me but maybe I have a different hardware version. Thanks again ;D

Related