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

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

Children
No Data
Related