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

NRF24LE1 Communication

Hi all! I am approaching this with pretty much zero experience but what I'm trying to build should be a piece of cake for you so any help, example code, advice will be appreciated.

The idea is to build a simple notification system. The RX is connected to a 3V coin cell through an on/off switch and couple LED's. If switched on, LED blinks once and the RX enters deep sleep mode and wakes up when a signal from a TX is received. When RX wakes up, LED's blink until RX is switched off. If switched off/on, RX resets, enters deep sleep and waits for a signal.

The TX is connected to a 3V power source. As soon as TX switches on, it sends a signal to RX and RX wakes up. The TX repeatedly sends signal to RX for 2 minutes and enters deep sleep if not switched off.

I'm using 2 x NRF24LE1, Q32, Keil software, mpro burner. I have programmed a device to blink a LED (Hello World) and 2 devices to communicate with "enhanced_shockburst" example, but that is as far is I've got. Trying to add deep sleep and wake up on pins resulted in nearly burning the chips.

Maybe someone has done/made something similar and can help even a bit?

Send help to NRF24LE1 street. Thank you in advance!

Parents
  • Hi

    What do you mean about nearly burning the chips? That you were unable to program them again?

    I wrote a small example many years ago, showing how to implement wakeup on pin from deep sleep: Wakeup on pin.zip
    Maybe you could take a look at that and see if you handle power management in the same way?

    Also, please be aware that you can't use the radio in deep sleep mode. If you want to wake up the chip through the radio you have to simulate it by waking up periodically and turning on the RX for a short amount of time to look for packets, and then you can go to sleep in between RX periods. If you want to sleep on a timer then the lowest mode you can use is 'memory retention timers on'.

    Best regards
    Torbjørn

  • // Global variables uint8_t payload[3];

    void main()
    {
    	// Open GPIO latches in case they were previously locked.
      
    OPMCON = 0x00;
    	
    #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
    
    	P0CON = 0x70; // Disable digital input buffer, pin used for 32kHz.
    	P0CON = 0x71; // Disable digital input buffer, pin used for 32kHz.
      //P0CON = 0x76;    // P06 must not be disconnected as it is required to wake up the nRF24LE1 
    
      // Set P0.6 as input for wake up, others as output
      
    P0DIR = 0x40;
    
      // Enable the radio clock
      RFCKEN = 1; 
    
    	hal_rtc_start(false);
    	hal_clklf_set_source(HAL_CLKLF_XOSC32K); 
    	hal_rtc_set_compare_mode(HAL_RTC_COMPARE_MODE_0);
    	hal_rtc_set_compare_value(0x7FFF);
    	hal_rtc_start(true);
    
    	// Wait for the 32kHz to startup (change phase)
    	while((CLKLFCTRL&0x80)==0x80);
    	while((CLKLFCTRL&0x80)!=0x80);
    	
      // Enable RF interrupt
      RF = 1;
      
    // Enable global interrupt
      EA = 1;
    	
    IEN1 = 0x08;
    
      // Configure radio as primary receiver (PRX)
      hal_nrf_set_operation_mode(HAL_NRF_PRX);
    
      // Set payload width to 3 bytes
      hal_nrf_set_rx_payload_width((int)HAL_NRF_PIPE0, 3);
    
      // Power up radio
      hal_nrf_set_power_mode(HAL_NRF_PWR_UP);
    
      // Enable receiver
      CE_HIGH();
    
      for(;;)
    	
    {
    		// Wake up on pin P0.6
    		
    WUOPC0 = 0x40;
    		// Inverse wakeup on pin polarity on selected GPIO's (P06 on 24-pin LE1. P06, P12 and P14 on 32-pin LE1. P22 and P26 on 48-pin LE1).
        
    OPMCON |= 0x04;
    		
    // Lock GPIO latches. 
        
    OPMCON |= 0x02;
    		
    // Register retention mode
    		
    PWRDWN = 0x04;
    		
    // Standby mode (wait for interrupt)
    		
    PWRDWN = 0x07;
    		
    // Clear PWRDWN
    		
    PWRDWN = 0x00;
    		
    // Continue to run code
    		
    P03 = !P03; 
    	};
    }
    
    void wakeup_tick() interrupt INTERRUPT_TICK
    {
    P02 = !P02;
    }
    
    // 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(payload);
        }
    
        
    // Write received payload[0] to port 0
        P0 = payload[0];
      }
    }
    
    /** @} */
    
  • Hello! It's been a while but slow and steady I have almost produced the system I need. 

    But I have encountered a problem I can't overcome. My simple system works just fine as long as I have on pair of nrf24le1's as they use the default address. Problem is, I need several pairs working in close range, therefore I want to set address for each pair of nrf's I need.

    When I use the lines: hal_nrf_set_address(HAL_NRF_TX, tx_address) and hal_nrf_set_address(HAL_NRF_PIPE0, rx_address); in my code, Keil compiler shows: "warning C196: mspace probably invalid" when compiling

    What am I doing wrong? Any suggestions?

Reply
  • Hello! It's been a while but slow and steady I have almost produced the system I need. 

    But I have encountered a problem I can't overcome. My simple system works just fine as long as I have on pair of nrf24le1's as they use the default address. Problem is, I need several pairs working in close range, therefore I want to set address for each pair of nrf's I need.

    When I use the lines: hal_nrf_set_address(HAL_NRF_TX, tx_address) and hal_nrf_set_address(HAL_NRF_PIPE0, rx_address); in my code, Keil compiler shows: "warning C196: mspace probably invalid" when compiling

    What am I doing wrong? Any suggestions?

Children
Related