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

esb nRF24LU and nRF51822

I am trying to get enhanced shockburst working with the nRF24LU and the nRF5188. I am using the nRF5188 as the transmitter and the nRF24LU as the receiver. I am using the nRF51 sdk version 6. The example that I am using for the nRF51822 is the esb_ptx_ack_payload. Everything in this example has been left in its default state. The nRF24LU is using the enhanced_shockburst_prx_nrf24lu1p example found in the nrfgo_sdk. I read the user guide which said that I have to add the following code to the nRF24LU in order to make it compatible with the nRF51822:

hal_nrf_setup_dynamic_payload(0xFF);
hal_nrf_enable_dynamic_payload(true);
hal_nrf_enable_ack_payload(true);
hal_nrf_set_rf_channel(10);

For some reason its still not working. The odd thing is that when I run the nRF24LU code on one computer and the nRF51822 code on another computer, I can actually send ACKs from the nRF24LU to the nRF5188, but only if I use break points. If I let the code run without breakpoints, no data is transmitted. Also, the data being sent from the nRF51822 never reaches the nRF24LU. Here is the code for the nRF24LU:

#ifdef MCU_NRF24LU1P
#include "nrf24lu1p.h"
#endif

#include <stdint.h>
#include "hal_nrf.h"

// Global variables
uint8_t tx_payload[1];
uint8_t rx_payload[1];

void main()
{
#ifdef MCU_NRF24LE1
	while(hal_clk_get_16m_source() != HAL_CLK_XOSC16M)
	{
		// Wait until 16 MHz crystal oscillator is running
	}
#endif
	
	#ifdef MCU_NRF24LU1P
	// Enable radio SPI
	RFCTL = 0x10;
	#endif

	// Set P0 as output
	P0DIR = 0;

	// Enable the radio clock
	RFCKEN = 1;

	// Enable RF interrupt
	RF = 1;
	// Enable global interrupt
	EA = 1;
	
	hal_nrf_setup_dynamic_payload(0xFF);
	hal_nrf_enable_dynamic_payload(true);
	hal_nrf_enable_ack_payload(true);
	hal_nrf_set_rf_channel(10);
	
	// Configure radio as primary receiver (PTX)
	hal_nrf_set_operation_mode(HAL_NRF_PRX);
	
	// Set payload width to 1 byte
	hal_nrf_set_rx_payload_width((int)HAL_NRF_PIPE0, 1);
	
	// Power up radio
	hal_nrf_set_power_mode(HAL_NRF_PWR_UP);

	// Enable receiver
	CE_HIGH();
}

// Radio interrupt
NRF_ISR()
{
	uint8_t irq_flags;

	// Read and clear IRQ flags from radio
	irq_flags = hal_nrf_get_clear_irq_flags();

	// If data received
	if((irq_flags & (1<<(uint8_t)HAL_NRF_RX_DR)) > 0)
	{
		// Read payload
		while(!hal_nrf_rx_fifo_empty())
		{
			hal_nrf_read_rx_payload(rx_payload);
		}

		// Write received payload[0] to port 0
		P0 = rx_payload[0];
		
		//Write ACK
		tx_payload[0] = 0x88;
		hal_nrf_write_ack_payload(HAL_NRF_PIPE0,tx_payload,1);
	}
}

Any ideas? I think that since I can receive ACKs while debugging, it sounds like a synchronization problem. The only difference between using break points and not using them is that the code is slowed down. So, if I slow the code down I can receive ACKs, but what about the data being sent from the nRF51822? How come I don't receive that?

Parents
  • Hakon

    Thanks for the help, I did miss the fact that my program exits. I must have accidentally deleted the for(;;) loop that was at the end of main(). So I added the for(;;) after CE_HIGH() and I still can't get the 2 micro-controllers to communicate with each other.

    I added the code for the nRF51822 in case you want to look at it. Maybe I missed something else. Also, it might be good for others to see what's going on in case they ever want to do the same thing.

     #include "nrf_esb.h"
     #include "nrf_gpio.h"
    
    /*****************************************************************************/
    /** @name Configuration */
    /*****************************************************************************/
    
    // Define pipe
    #define PIPE_NUMBER 0 ///< We use pipe 0 in this example
    
    // Define payload length
    #define TX_PAYLOAD_LENGTH 1 ///< We use 1 byte payload length when transmitting
    
    // Data and acknowledgement payloads
    static uint8_t my_tx_payload[TX_PAYLOAD_LENGTH];                ///< Payload to send to PRX. 
    static uint8_t my_rx_payload[NRF_ESB_CONST_MAX_PAYLOAD_LENGTH]; ///< Placeholder for received ACK payloads from PRX.
    
    /** @} */
    
    
     /*****************************************************************************/
     /** 
      * @brief Main function. 
      * 
      * @return ANSI required int return type.
      */
     /*****************************************************************************/
     int main()
     {
    uint32_t i;
    // Setup port directions
    nrf_gpio_cfg_input(19,GPIO_PIN_CNF_PULL_Pullup);
    nrf_gpio_cfg_output(16);
    
    // Initialize ESB
    (void)nrf_esb_init(NRF_ESB_MODE_PTX);
    
    (void)nrf_esb_enable();  
    
    // Add packet into TX queue
    my_tx_payload[0] = (~nrf_gpio_pin_read(19)) | 0x80;
    (void)nrf_esb_add_packet_to_tx_fifo(PIPE_NUMBER, my_tx_payload, TX_PAYLOAD_LENGTH, NRF_ESB_PACKET_USE_ACK);
    
       while(1)
       {
        // Optionally set the CPU to sleep while waiting for a callback.
    		// __WFI();
    	for(i=0; i<1000000; i++){}
    		
    	nrf_gpio_pin_toggle(16);	
         }
      }
    
    
      /*****************************************************************************/
      /** @name ESB callback function definitions  */
      /*****************************************************************************/
    
    
      // 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_pin_read(19)) | 0x80;  
    (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)
    {
    	 nrf_gpio_pin_set(16); // Button press is active low.
    }
    else
    {
    	nrf_gpio_pin_clear(16);
    }
     }
    
     // Callbacks not needed in this example.
     void nrf_esb_disabled(void)
     {}
    
  • This is not an answer. Edit your question to include the information.

Reply Children
No Data
Related