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)
{}
Parents
  • 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.

Reply
  • 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.

Children
Related