ethermega with nrf24l01+ modules

Combining the power of the ATmega2560 MCU with onboard Ethernet, a microSD card slot, an efficient switchmode power supply, and a small prototyping area. [Product page]
Post Reply
zerros
Posts: 5
Joined: Tue Mar 05, 2013 8:18 am

ethermega with nrf24l01+ modules

Post by zerros » Tue Mar 05, 2013 8:23 am

Hi,

Forgive me for my bad english, I'm a french people.

I'm trying to get functionnal my nrf24l01+ modules on ethermega I've just bought.
Actually these modules function on two arduino uno boards.

Is there an incompatibylity with these module and the ethernet chip ?

Thanks in advance for your helps.

zerros
Posts: 5
Joined: Tue Mar 05, 2013 8:18 am

Re: ethermega with nrf24l01+ modules

Post by zerros » Wed Mar 06, 2013 9:02 am

Hi,

I'm using exacttly the pins mentionned in examples:

Code: Select all

* Pins:
 * Hardware SPI:
 * MISO -> 12
 * MOSI -> 11
 * SCK -> 13
 *
 * Configurable:
 * CE -> 8
 * CSN -> 7
Any idea ?

zerros
Posts: 5
Joined: Tue Mar 05, 2013 8:18 am

Re: ethermega with nrf24l01+ modules

Post by zerros » Wed Mar 06, 2013 4:23 pm

Hi,

I've found the spi pins numbers for this mega:

* MISO -> 50, * MOSI -> 51
* SCK -> 52

* Configurable:
* CE -> 8
* CSN -> 7

It works now.

zerros
Posts: 5
Joined: Tue Mar 05, 2013 8:18 am

Re: ethermega with nrf24l01+ modules

Post by zerros » Sat Mar 09, 2013 6:08 pm

Hi,

There is a big problem with this card using ethernet and nrf24l01+ at the same time !!!

I can send to remote module without any problem, but the response never arrive.
If I disable all ethernet features, it works well.

my code:

Code: Select all

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

/* ethernet */
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 7, 177);
unsigned int localPort = 8888;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
//char ReplyBuffer[] = "acknowledged"; // a string to send back
EthernetUDP Udp;

/* radio */
int cmd;
//int led = 4;

void setup(){
  Serial.begin(9600);
  
  Mirf.cePin = 8;
  Mirf.csnPin = 7;
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.configRegister(RF_SETUP, 0x26);
  
  // ethernet
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);
  
  /*byte rf_setup = 0;
  Mirf.readRegister( RF_SETUP, &rf_setup, sizeof(rf_setup) );
  Serial.print( "rf_setup = " );
  Serial.println( rf_setup, BIN );*/
   
  Mirf.setRADDR((byte *)"clie1");
  Mirf.payload = sizeof(1);
  
  Mirf.channel = 0;
   
  Mirf.config();
  
  //Serial.println("Server listening on : 192.168.7.177:8888");
  Serial.println("Radio ok, starting ...");
}

void loop() {
  // Vérifie la trame UDP
  int packetSize = Udp.parsePacket();
  
  // Si un contenu est détecté dans la trame
  if(packetSize) {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    Serial.print(Udp.remoteIP());
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // vide le buffer
    for(int i=0;i<UDP_TX_PACKET_MAX_SIZE;i++) packetBuffer[i] = 0;
    // récupère le contenu
    Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
    
    // affiche le contenu
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    unsigned long time = millis();
    
    // prépare l'envoi de la donnée
    Mirf.setTADDR((byte *)"serv1");
    // converti le char en int
    cmd = packetBuffer[0] - '0';
    Mirf.send((byte *) &cmd);
    
    Serial.println("Sending command");
    
    // envoi la donnée
    while(Mirf.isSending()){
    }
    
    Serial.println("Finished sending");
    delay(10);
    
    // On attend une réponse pendant 1000ms
    while(!Mirf.dataReady()){
      Serial.println("Waiting");
      if ( ( millis() - time ) > 1000 ) {
        Serial.println("Timeout on response from server!");
        // envoi une réponse sur la socket ouverte
        Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
        Udp.write("timeout");
        // ferme la socket
        Udp.endPacket();
        return;
      }
    }
    
    // récupération de la réponse
    int res;
    Mirf.getData((byte *) &res);
    // on affiche la réponse
    Serial.print("Res: ");
    Serial.println(res);

    // envoi de la réponse sur la socket ouverte
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(res);
    // ferme la socket
    Udp.endPacket();
  }
  delay(10);
}
is there a patch to get it functionnal with this card. This card is marked as 100% compatible with mega, but it seems that it's not complettly true if we use a hardware that use SPI ?

Can you help me ?

zerros
Posts: 5
Joined: Tue Mar 05, 2013 8:18 am

Re: ethermega with nrf24l01+ modules

Post by zerros » Fri Mar 15, 2013 2:10 pm

i've finally resolved the problem by changing the order of the includes:

before:

Code: Select all

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
after:

Code: Select all

#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

Post Reply