Nrf24L01

Hi. I'm using the Nrf24L01 radio transmitter with Arduino. But I'm not receiving data at the other side. How coul I know if I'm transmitting data? Thanks.

I'm using the Nrf24L01 radio transmitter with Arduino. But I'm not receiving data at the other side. How coul I know if I'm transmitting data?

Usually, you know if the transmitter works because the receiver gets some data.

This could be a hardware issue, where the radios are not connected correctly, or a software issue.

Post a schematic at a minimum. A picture might be useful, too. And post the code on both ends.

PaulS:

I'm using the Nrf24L01 radio transmitter with Arduino. But I'm not receiving data at the other side. How coul I know if I'm transmitting data?

Usually, you know if the transmitter works because the receiver gets some data.

This could be a hardware issue, where the radios are not connected correctly, or a software issue.

Post a schematic at a minimum. A picture might be useful, too. And post the code on both ends.

This is what I used as a guide for the conections:

Pins: MISO -> 12 MOSI -> 11 SCK -> 13 Configurable: CE -> 8 CSN -> 7

Taken from: http://www.arduino.cc/playground/InterfacingWithHardware/Nrf24L01

And the datasheet: http://www.nordicsemi.com/eng/content/download/2726/34069/file/nRF24L01P_Product_Specification_1_0.pdf

For the code, I copied some examples from http://arduino-info.wikispaces.com/nRF24L01-Mirf-Examples , using the same channel and name for the transmission. But I have no result. The receiver is waiting and the sender is continuously emitting.

You could try RF24, http://maniacbug.github.com/RF24/ . The pingpair example prints out a ton of debugging information which can be useful in troubleshooting problems.

To get a successful receive everything must be setup the same. channel, datarate, CRC size, packet length, auto-acknowledgement, rx and tx addresses (make them all identical to start with). About the only things that can differ between the two ends is the TX power level.

If using auto-acknowledge the retry delay MUST be long enough to prevent the TX side stomping on the ACK packets.

If you want to know if the transmit side is actually sending an RF signal then measure the supply current - this will increase for the duration of the transmission (use maximum TX power).

Also make sure the transmit and receive sides are not too close together (I'd say 10cm minimum) to prevent any chance of receiver-overloading.

Sending 1 byte:

#include <SPI.h>
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>



char data[1];

void setup(){
  
  
  Serial.begin(9600);
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  
  Mirf.setTADDR((byte *)"cli1");
  Mirf.setRADDR((byte *)"cli1");
  Mirf.payload = 1;
  Mirf.channel = 1;
  Mirf.config();
  
  Mirf.powerUpTx();
  data[Mirf.payload];
  data[0]='M';
  
  
  byte reg = 0;
  Mirf.readRegister( CONFIG, &reg, sizeof(reg) );
  Serial.print( "CONFIG = " );
  Serial.println(reg,BIN);
  Mirf.readRegister( SETUP_RETR, &reg, sizeof(reg) );
  Serial.print( "SETUP_RETR  = " );
  Serial.println(reg,BIN);
  Mirf.readRegister( SETUP_AW, &reg, sizeof(reg) );
  Serial.print( "SETUP_AW  = " );
  Serial.println(reg,BIN);
  Mirf.readRegister( RF_CH, &reg, sizeof(reg) );
  Serial.print( "RF_CH  = " );
  Serial.println(reg,BIN);
  Mirf.readRegister( RF_SETUP, &reg, sizeof(reg) );
  Serial.print( "RF_SETUP  = " );
  Serial.println(reg,BIN);
  Mirf.readRegister( RX_PW_P0, &reg, sizeof(reg) );
  Serial.print( "RX_PW_P0  = " );
  Serial.println(reg,BIN);
  
  Mirf.readRegister( RX_ADDR_P0, &reg, sizeof(reg) );
  Serial.print( "RX_ADDR_P0  = " );
  Serial.println((byte)reg);
  
  Mirf.readRegister( TX_ADDR, &reg, sizeof(reg) );
  Serial.print( "TX_ADDR  = " );
  Serial.println((byte)reg);
  
}

void loop(){
  
  Mirf.setTADDR((byte *)"cli1");
  Mirf.send((byte *)&data);
  while(Mirf.isSending()){
  }
  Serial.println("1 byte sended");
  delay(1000);

}

You are sending only 4 bytes for the RX and TX addresses perhaps (I’m not sure what the library does with null-terminated strings?). If the chip receives the wrong number of bytes to the RX and TX address registers it doesn’t update the register. Perhaps the library is doing the right thing though, check out the code for setTADDR and setRADDR to be sure. Check the value of the SETUP_AW register.

Also channel 1 spills outside the band - use channel 2 at least to guarantee transmitted energy stays inside the ISM band (channel 4 is the default, probably for this reason).

Not sure you meant the line:

  data[Mirf.payload];

MarkT:
You are sending only 4 bytes for the RX and TX addresses perhaps (I’m not sure what the library does with null-terminated strings?). If the chip receives the wrong number of bytes to the RX and TX address registers it doesn’t update the register. Perhaps the library is doing the right thing though, check out the code for setTADDR and setRADDR to be sure. Check the value of the SETUP_AW register.

Also channel 1 spills outside the band - use channel 2 at least to guarantee transmitted energy stays inside the ISM band (channel 4 is the default, probably for this reason).

Not sure you meant the line:

  data[Mirf.payload];

This is what I get from Serial.print:

CONFIG = 1010
SETUP_RETR = 11
SETUP_AW = 11
RF_CH = 10
RF_SETUP = 1111
RX_PW_P0 = 1
RX_ADDR_P0 = a
TX_ADDR = a
[/table]

Forget data[Mirf.payload]; I remove it from the code.

The SETUP_AW = 11 means its setup for 5 byte addresses - however that debug code reads only one byte from the TX_ADDR and RX_ADDR_P0 registers which won’t work - these registers must be read and written as the correct size (here 5). Until you know these registers are set up correctly matching each other they are suspects!

ok, thanks! I’ve made some changes…

The receiver:

#include <stdlib.h>
#include "mirf.h"
#include "nRF24L01.h"



typedef uint8_t byte;

int main(int argc, int argv[]){

	
	init();  
	byte rx_addr[5] = {0x41, 0x41, 0x41, 0x41, 0x41};
  	setRADDR(rx_addr);
	payload = 1;
	channel = 2;

	config(channel,payload);
        configRegister(RF_SETUP, 0x07); //Air data rate 1Mbit, 0dBm, Setup LNA
  	configRegister(EN_AA, 0x00); //Disable auto-acknowledge

	  

	byte aux;
	readRegister(CONFIG, &aux, 1);
	printf("CONFIG = %x\n\r", aux);
	readRegister(SETUP_RETR, &aux, 1);
	printf("SETUP_RETR = %x\n\r", aux);
	readRegister(SETUP_AW, &aux, 1);
	printf("SETUP_AW = %x\n\r", aux);
	readRegister(RF_CH, &aux, 1);
	printf("RF_CH = %x\n\r", aux);
	readRegister(RF_SETUP, &aux, 1);
	printf("RF_SETUP = %x\n\r", aux);
	readRegister(RX_PW_P0, &aux, 1);
	printf("RX_PW_P0 %x\n\r", aux);
	readRegister( RX_ADDR_P0, &aux, 1);
  	printf("RX_ADDR_P0 %c\n\r", aux);
  	readRegister( TX_ADDR, &aux, 1);
  	printf("TX_ADDR %c\n\r", aux);
	

	byte recibe;

	while(1){
		
		printf("Waiting for packets...\n\r");
		
		if(dataReady()){
    			printf("Got packet\n\r");
			getData((byte *) recibe);
			printf("We have: %i\n\r", recibe);
		}
	}

}

And this is what I get:
CONFIG = 2b
SETUP_RETR = 0
SETUP_AW = 3
RF_CH = 2
RF_SETUP = 7
RX_PW_P0 1
RX_ADDR_P0 A
TX_ADDR A
Waiting for packets…
Waiting for packets…
Waiting for packets…
Waiting for packets…
[/table]

This is the code to send:

#include <Spi.h>
#include <mirf.h>
#include <nRF24L01.h>


void setup(){
  
  Serial.println("Realizando configuracion.");  
  Mirf.csnPin = 7;
  Mirf.cePin = 8;
  Serial.begin(9600);
  Mirf.init();
  byte rx_addr[5] =  {0x41, 0x41, 0x41, 0x41, 0x41};
  Mirf.setTADDR(rx_addr);
  Mirf.configRegister(RF_SETUP, 0x07); //Air data rate 1Mbit, 0dBm, Setup LNA
  Mirf.configRegister(EN_AA, 0x00); //Disable auto-acknowledge
  Mirf.configRegister(SETUP_RETR, 0x00);
  Mirf.configRegister(CONFIG, 0x2A);
  Mirf.payload = 1;
  Mirf.channel = 2;
  Mirf.config();
  Serial.begin(9600);
  
  Serial.println("Configuracion realizada.");  
  
  
  byte reg = 0;
  
  Mirf.readRegister( CONFIG, &reg, sizeof(reg) );
  Serial.print( "CONFIG = " );
  Serial.println(reg,BIN);
  Mirf.readRegister( SETUP_RETR, &reg, sizeof(reg) );
  Serial.print( "SETUP_RETR  = " );
  Serial.println(reg,BIN);
  Mirf.readRegister( SETUP_AW, &reg, sizeof(reg) );
  Serial.print( "SETUP_AW  = " );
  Serial.println(reg,BIN);
  Mirf.readRegister( RF_CH, &reg, sizeof(reg) );
  Serial.print( "RF_CH  = " );
  Serial.println(reg,BIN);
  Mirf.readRegister( RF_SETUP, &reg, sizeof(reg) );
  Serial.print( "RF_SETUP  = " );
  Serial.println(reg,BIN);
  Mirf.readRegister( RX_PW_P0, &reg, sizeof(reg) );
  Serial.print( "RX_PW_P0  = " );
  Serial.println(reg,BIN);
  Mirf.readRegister( TX_ADDR, &reg, sizeof(reg) );
  Serial.print( "TX_ADDR  = " );
  Serial.println((byte)reg);
  
  
}

void loop(){
  
  byte c='M';
  Mirf.send(&c);
  while(Mirf.isSending()){
  }
  Serial.println("Finished sending");
  delay(1000);
}

And this is what I get:

CONFIG = 101010
SETUP_RETR = 11
SETUP_AW = 11
RF_CH = 10
RF_SETUP = 111
RX_PW_P0 = 1
TX_ADDR = A
Finished sending
Finished sending
Finished sending
Finished sending
Finished sending
[/table]

Thanks