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

Issue w/ nRF24L01 Tx

I am having an interesting issue trying to send packets. Only a very small number are being received (~1 per second even when transmitting one after another), and they are only partially correct (receiving 0x9DAFAAAA when transmitting 0xAAAAAAAA).

Additionally, if I try and change the payload being set (e.g. from 0xAAAAAAAA to 0xBBBBBBBB) nothing happens unless the nRF24L01 is restarted.

Is there something obvious I could be missing to cause this behavior? The Rx and Tx addresses appear to get set correctly (w/ Rx_P0 set to the same address as Tx)and the payload size is being set to 4 bytes.

Has anyone else had behavior like this?

(Using an Arduino for Rx and an STM32F4 Discovery board for Tx - I have no issues using the Arduino for Tx and the STM32 for Rx)

Parents
  • Here is the code being used on the Arduino side:

    
    #include <SPI.h>
    #include <Mirf.h>
    #include <nRF24L01.h>
    #include <MirfHardwareSpiDriver.h>
    
    void setup(){
      Serial.begin(9600);
      Mirf.spi = &MirfHardwareSpi;
      Mirf.init();
      Mirf.setRADDR((byte *)"clie1");
      Mirf.payload = sizeof(unsigned long);  // 4 bytes
      Mirf.config();
      Serial.println("Beginning ... "); 
    }
    
    unsigned long data;
    
    void loop(){ 
      while(!Mirf.dataReady());
      
      Mirf.getData((byte *) &data);
       
      Serial.println(data, HEX); 
    }
    

    (the Mirf library being used has been attached as well)

    On the STM32 side I have the following:

    #include "stm32f4_discovery.h"
    #include <stdio.h>
    #include "nRF24L01P.h"
    
    #define ADR_WIDTH 5
    #define RX_PLOAD_WIDTH 4
    #define TX_PLOAD_WIDTH 4
    
    unsigned char Tx_Buf[4] = {0xAA,0xAA,0xAA,0xAA};
    unsigned char Tx_Buf2[4] = {0xBB,0xBB,0xBB,0xBB};
    
    int state = 0;
    
    int main (void) {
    	nRF24L01_HW_Init();
    	RX_Mode();
    	Delay(10000);
    
    	while (1) {
    		
    		if (i % 100000 == 0) {
    		  state = !state;
    		}
    		
    		if (state) {
    	                nRF24L01_TxPacket(Tx_Buf);
    		} else {
    			nRF24L01_TxPacket(Tx_Buf2);
    		}
    		RX_Mode();
    		Delay(1000);
    		}
    	}
    }
    
    void nRF24L01_TxPacket(unsigned char * tx_buf) {
            nRF24L01_CE_L();
    	 	
    	SPI_WR_Reg(WRITE_nRF_REG + NRFRegSTATUS, 0x30);
    	nRF24L01_Delay_us(20);
    	SPI_WR_Reg(WRITE_nRF_REG + CONFIG, 0x3A);
    	nRF24L01_Delay_us(20);
    	nRF24L01_SPI_NSS_L();  
    	nRF24L01_SPI_Send_Byte(FLUSH_TX);
    	nRF24L01_SPI_NSS_H();  
    	nRF24L01_Delay_us(20);
    	SPI_Write_Buf(WR_TX_PLOAD, tx_buf, TX_PLOAD_WIDTH);
    	nRF24L01_Delay_us(20);
            
            nRF24L01_CE_H();
    	nRF24L01_Delay_us(20);
            nRF24L01_CE_L();
    }
    
    void RX_Mode(void) {
            nRF24L01_CE_L();
    	SPI_WR_Reg(WRITE_nRF_REG + CONFIG, 0x39);
    	nRF24L01_Delay_us(20);
    	
    	SPI_WR_Reg(WRITE_nRF_REG + RF_CH,0x01);
    	nRF24L01_Delay_us(20);
    	SPI_WR_Reg(WRITE_nRF_REG + RX_PW_P0,4);
    	nRF24L01_Delay_us(20);
    	SPI_WR_Reg(WRITE_nRF_REG + RX_PW_P1,4);
    	nRF24L01_Delay_us(20);
    	SPI_WR_Reg(WRITE_nRF_REG + EN_RXADDR, 0x03);
    	nRF24L01_Delay_us(20);
    	SPI_Write_Buf(WRITE_nRF_REG + TX_ADDR, TX_ADDRESS, ADR_WIDTH);
    	nRF24L01_Delay_us(20);
    	SPI_Write_Buf(WRITE_nRF_REG + RX_ADDR_P0, TX_ADDRESS, ADR_WIDTH); 
    	nRF24L01_Delay_us(20);
    	SPI_Write_Buf(WRITE_nRF_REG + RX_ADDR_P1, RX_ADDRESS, ADR_WIDTH); 
    	nRF24L01_Delay_us(20);
    	
    	SPI_WR_Reg(WRITE_nRF_REG + CONFIG, 0x33);
    	nRF24L01_Delay_us(20);
            nRF24L01_CE_H();
    	nRF24L01_Delay_us(2000);
    }
    

    I appreciate the help (and apologize the code is a bit sloppy)

    • Bryan

    Mirf.zip

Reply
  • Here is the code being used on the Arduino side:

    
    #include <SPI.h>
    #include <Mirf.h>
    #include <nRF24L01.h>
    #include <MirfHardwareSpiDriver.h>
    
    void setup(){
      Serial.begin(9600);
      Mirf.spi = &MirfHardwareSpi;
      Mirf.init();
      Mirf.setRADDR((byte *)"clie1");
      Mirf.payload = sizeof(unsigned long);  // 4 bytes
      Mirf.config();
      Serial.println("Beginning ... "); 
    }
    
    unsigned long data;
    
    void loop(){ 
      while(!Mirf.dataReady());
      
      Mirf.getData((byte *) &data);
       
      Serial.println(data, HEX); 
    }
    

    (the Mirf library being used has been attached as well)

    On the STM32 side I have the following:

    #include "stm32f4_discovery.h"
    #include <stdio.h>
    #include "nRF24L01P.h"
    
    #define ADR_WIDTH 5
    #define RX_PLOAD_WIDTH 4
    #define TX_PLOAD_WIDTH 4
    
    unsigned char Tx_Buf[4] = {0xAA,0xAA,0xAA,0xAA};
    unsigned char Tx_Buf2[4] = {0xBB,0xBB,0xBB,0xBB};
    
    int state = 0;
    
    int main (void) {
    	nRF24L01_HW_Init();
    	RX_Mode();
    	Delay(10000);
    
    	while (1) {
    		
    		if (i % 100000 == 0) {
    		  state = !state;
    		}
    		
    		if (state) {
    	                nRF24L01_TxPacket(Tx_Buf);
    		} else {
    			nRF24L01_TxPacket(Tx_Buf2);
    		}
    		RX_Mode();
    		Delay(1000);
    		}
    	}
    }
    
    void nRF24L01_TxPacket(unsigned char * tx_buf) {
            nRF24L01_CE_L();
    	 	
    	SPI_WR_Reg(WRITE_nRF_REG + NRFRegSTATUS, 0x30);
    	nRF24L01_Delay_us(20);
    	SPI_WR_Reg(WRITE_nRF_REG + CONFIG, 0x3A);
    	nRF24L01_Delay_us(20);
    	nRF24L01_SPI_NSS_L();  
    	nRF24L01_SPI_Send_Byte(FLUSH_TX);
    	nRF24L01_SPI_NSS_H();  
    	nRF24L01_Delay_us(20);
    	SPI_Write_Buf(WR_TX_PLOAD, tx_buf, TX_PLOAD_WIDTH);
    	nRF24L01_Delay_us(20);
            
            nRF24L01_CE_H();
    	nRF24L01_Delay_us(20);
            nRF24L01_CE_L();
    }
    
    void RX_Mode(void) {
            nRF24L01_CE_L();
    	SPI_WR_Reg(WRITE_nRF_REG + CONFIG, 0x39);
    	nRF24L01_Delay_us(20);
    	
    	SPI_WR_Reg(WRITE_nRF_REG + RF_CH,0x01);
    	nRF24L01_Delay_us(20);
    	SPI_WR_Reg(WRITE_nRF_REG + RX_PW_P0,4);
    	nRF24L01_Delay_us(20);
    	SPI_WR_Reg(WRITE_nRF_REG + RX_PW_P1,4);
    	nRF24L01_Delay_us(20);
    	SPI_WR_Reg(WRITE_nRF_REG + EN_RXADDR, 0x03);
    	nRF24L01_Delay_us(20);
    	SPI_Write_Buf(WRITE_nRF_REG + TX_ADDR, TX_ADDRESS, ADR_WIDTH);
    	nRF24L01_Delay_us(20);
    	SPI_Write_Buf(WRITE_nRF_REG + RX_ADDR_P0, TX_ADDRESS, ADR_WIDTH); 
    	nRF24L01_Delay_us(20);
    	SPI_Write_Buf(WRITE_nRF_REG + RX_ADDR_P1, RX_ADDRESS, ADR_WIDTH); 
    	nRF24L01_Delay_us(20);
    	
    	SPI_WR_Reg(WRITE_nRF_REG + CONFIG, 0x33);
    	nRF24L01_Delay_us(20);
            nRF24L01_CE_H();
    	nRF24L01_Delay_us(2000);
    }
    

    I appreciate the help (and apologize the code is a bit sloppy)

    • Bryan

    Mirf.zip

Children
No Data
Related