Go Down

Topic: RF24l01 + ENC28J60 doesn't work on SPI! (Read 4441 times) previous topic - next topic

unglaublich

Hi!

I can't get the RF24l01 module working with a Arduino Ethernet Shield v1.1 with ENC28J60 chip. My ethernet connection does work but when this shield is attached, my wireless module doesnt. I've set the RF24l01 CS port to 3 while the ENC28J60 CS is on 10. Do you have some example code availble for using the RF24l01 with an arduino Ethernet Shield v1.1 together?

I use the libraries
ETHER_28J60 (with etherShield)
RF24

Thanks,
Tom

Paulware

I use both of these components individually but have never tried to combine them.  Do you understand the SPI protocol?

   My ENC28J60 uses these pins: D2, D10, D11, D12, D13.

   My nrf24L01 uses these pins: D11 (MOSI), D12 (MISO), D13(SCK)
   I believe those need to be used as they are SPI pins.  (somebody with better SPI knowledge should jump in here).
  CSN and CE can be whatever you like I use D18 (Analog pin A4) for CSN, and D8 for CE.  I have a library that allows you to specify which pins you want for CSN, and CE. 
  NOTE: IRQ does not need to be connected, nor do any resistors as one site led me to believe at first.

  I can provide source code, even a pcb but I haven't tried to combine these 2 and I'm not what would happen although in theory I believe it should be possible (again this is an SPI issue).

  By the way I don't use a nrf24l01 with ENC28J60.  I use a TP-Link 702N which is a router-repeater available for about $23.00 on Ebay.  To give the enc28j60 a mobile capability.
  Here is a video that explains the topic better:
http://youtu.be/frmsmcG04t4

  Let me know if you would like more info
Paul

pylon

The SPI bus can be used by multiple devices as long as each of them has it's own SS (slave select) pin.

Quote
I've set the RF24l01 CS port to 3


I guess you mean the CSN pin of the nRF24L01. Where did you connect the CE pin then?

What Arduino do you use? An UNO?

Please provide links to all devices you're using as well as to all libraries. The names are not enough because sometimes multiple suppliers use the same name for their product although they are different.

Grag38

Why not using ManaicsBug RF24 libraries ?

http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/

There is a simple example with RF24. With the library provided by ManaiacBug you can choose the CE/CS pins witn an fonction/constructor you can put in the setup() part.

May be it can help you and solve the trouble.

best regards

SurferTim

Have you tried the RF24L01 without the ethernet shield? Does it work ok? If so, connect the ethernet shield and use the same code, and add this to the setup function.
Code: [Select]
void setup() {
  // disable the ENC28J60 SPI
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  // rest of your RF24L01 code
}

Does the RF24L01 module work ok like that?

unglaublich

Hi everybody,

I used ManiacBug's RF24 library myself plus the EtherShield library + ENC28J60 library + EtherShield library. Without the ethernetshield RF works, with ethernetshield only Ethernet works. When i plug a jumper wire in the +5V terminal and D10 (Ethernet's SS port if i'm right?) RF does still not work. I read in ManiacBug's blogpost that there is an incompatibility in the SPI parameters of the Ethernet shield and the RF24 wireless module. Does anybody knows what this incompatibility could be?

Thanks,
Tom

SurferTim

#6
Nov 07, 2012, 02:24 pm Last Edit: Nov 07, 2012, 03:17 pm by SurferTim Reason: 1
I don't see a compatibility problem. It appears both devices are SPI mode 0.
SCK LOW with HIGH pulses (CPOL = 0), and propagates on the falling edge (CPHA = 0).
http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

edit: And both are Big Endian. MSB first.
Maybe if you posted your successful RF24L01 code, I could help you.

Do not do this again. You will burn out D10.
Quote
When i plug a jumper wire in the +5V terminal and D10 (Ethernet's SS port if i'm right?) RF does still not work.

If you are using a Mega, you might get away with this. Its default SS pin is 53. On an Uno, the default SS pin is 10. It will be set to OUTPUT to get the SPI bus in master mode. If pin 10 is LOW and you put 5 volts on it from the power supply, goodbye pin 10!

Grag38

May be the trouble with the SPI is the speed used by the RF24 library.

we can read int the RF24.cpp this code :

Code: [Select]

void RF24::csn(int mode)
{
  // Minimum ideal SPI bus speed is 2x data rate
  // If we assume 2Mbs data rate and 16Mhz clock, a
  // divider of 4 is the minimum we want.
  // CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz
#ifdef ARDUINO
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV4);
#endif
  digitalWrite(csn_pin,mode);
}


May be the SPI_CLOCK_DIV4 is the trouble between the 2 devices...

SurferTim

I don't think 4MHz should be a problem with that IC either.
http://ww1.microchip.com/downloads/en/devicedoc/39662b.pdf
Quote
Communication with the host controller is implemented via an interrupt pin and the SPI, with clock rates of up to 20 MHz.


unglaublich

Thank you for al your info.

My working RF code:
Code: [Select]

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

int send_value[1];
RF24 radio(2,3);

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

void setup(void)
{
  RF24 setRF(RF24 NRF24DataRate250kbps, RF24 NRF24TransmitPower0dBm);
  radio.begin();
  radio.setRetries(15,15);
  radio.openWritingPipe(pipes[1]);
}

void loop(void)
{

  send_value[0] = 1;
  radio.write( send_value, sizeof(send_value) );
  delay(100);

  send_value[0] = 0;
  radio.write( send_value, sizeof(send_value) );
  delay(100);

}



SurferTim

Do not use digital pin 2 for anything. I think the ENC28J60 uses that for an interrupt output. If those are the digital pins in the "RF24 radio(2,3);", move those up to 3 and 4. I normally would not use pin 4, but that shield does not have an SD slot. Right?

Then connect both devices. Don't add anything else. Does this run?
Code: [Select]
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

int send_value[1];

// if these are the SS and interrupt pins, move off pin 2. It is taken.
RF24 radio(2,3);

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

void setup(void)
{
  // disable ENC28J60
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  // rest is unchanged
  RF24 setRF(RF24 NRF24DataRate250kbps, RF24 NRF24TransmitPower0dBm);
  radio.begin();
  radio.setRetries(15,15);
  radio.openWritingPipe(pipes[1]);
}

void loop(void)
{

  send_value[0] = 1;
  radio.write( send_value, sizeof(send_value) );
  delay(100);

  send_value[0] = 0;
  radio.write( send_value, sizeof(send_value) );
  delay(100);

}

How does that do?

Frédéric_Plante

#11
Jul 27, 2013, 02:00 am Last Edit: Jul 29, 2013, 05:03 am by Frederic_Plante Reason: 1
Hello Mister Unglaublich

I've also note that the Module NRF and ENC don't work together, and that is true when you use the Ethercard and the NRF24 libraries together.

As mention before by Grag38, it is cause by a different clock divider. Ethercard use a 2x while NRF24 is 4x. You can overcome this difficulty simply by using MIRF, that also use a 2x divider, or find a libraries for you ENC module that use a 4x divider. How ever I know only the Ethercard library that work with this module, so go with MIRF, to keep it simple.

The main problem that I've noted, when the 2 modules are connected in the same time on the Arduino, is that the NRF24 libraries perceive that a lot of "space" is send while it's not the case in reality.

How ever since I've worked with the MIRF librarie, this problem has not repeated, and data can be send normally between the 2 NRF modules.

I'm about to implement the Ethercard libraries in my code, so ill let you know if every thing still work after. How ever the NRF module work, while the ENC module is hook in the same time on the SPI port, very encouraging.

By the way, I am using pin 9 and 10, on Arduino, for the NRF device And pin 8, on Arduino, for the ENC device. For now I'm not using any of bolt interrupt on NRF NOr ENC, but I might do in the future, so pin 2 and 3 are free for now on the Arduino.

So I hope that help a little, there is hope.
As we fight our way northward into the great unknown, only that one thing remains certain...

Frédéric_Plante

#12
Jul 27, 2013, 02:29 am Last Edit: Jul 27, 2013, 05:09 am by Frederic_Plante Reason: 1
So confirmation, this will start bolt NRF and ENC module:

Code: [Select]
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#include <EtherCard.h>
#include <IPAddress.h>

#define STATIC 0

uint8_t buf[32];
static byte mymac[] = { 0x70,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500];



void setup(){

 Serial.begin(9600);

 Mirf.cePin = 10;
 Mirf.csnPin = 9;
 Mirf.spi = &MirfHardwareSpi;
 Mirf.init();
 Mirf.setRADDR((byte *)"aurx0");
 Mirf.payload = 32;
 Mirf.channel = 50;
 Mirf.config();
 
 Serial.println("NRF libraries initialised ... ");

 ether.begin(sizeof Ethernet::buffer, mymac);
 ether.dhcpSetup();
 ether.printIp("IP:  ", ether.myip);
 ether.printIp("GW:  ", ether.gwip);
 ether.printIp("DNS: ", ether.dnsip);
 ether.udpServerListenOnPort(&udpSerialPrint, 1337);
 ether.udpServerListenOnPort(&udpSerialPrint, 42);

 Serial.println("ENC libraries initialised ... ");

}


Now it's up to you to make something great and mind blasting with the info.
As we fight our way northward into the great unknown, only that one thing remains certain...

Go Up