nRF24L01 2.4GHz wireless transceiver with DS3234 Real Time Clock

Hi,

I am trying to use an Arduino uno to operate a nRF24L01 2.4GHz wireless transceiver and DS3234 real time clock module at the same time.

I can operate them separately fine, but when they are wired to the Uno together and within the same program, the nRF24L01 works fine but the DS3234 does not. The below example shows 0's for the date aspect and the time is also not what was initially set in the program.

Example: Sending: 241 0/0/0 8:0:12

The wiring for the pins is as follows: Transceiver: * (1) GND.......GND * (2) VCC.......3.3V * (3) CE........DIO 8 // This was changed to 9 so it would not conflict with the DS3234 ?????? * (4) CSN.......DIO 7 * (5) SCK.......DIO 13 * (6) MOSI......DIO 11 * (7) MISO......DIO 12 * (8) IRQ.......N/A

DS3234: // SS - 8 // MOSI- 11 // MISO- 12 // SCLK- 13 // VCC - 5V // SQW, GND- GND

Does anyone have any suggestions to make this set up work?

Help is greatly appreciated.

and within the same program

..which you omitted

This is the code used.

/* Include the SPI anf Mirf libraries */
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

int uiData = 0;
const int  cs=8; //chip select 

void setup(){
  Serial.begin(9600);

  RTC_init();
  //day(1-31), month(1-12), year(0-99), hour(0-23), minute(0-59), second(0-59)
  SetTimeDate(11,12,13,14,15,16); 
  
  Mirf.cePin = 9;//8
  Mirf.csnPin = 7;
 
  Mirf.spi = &MirfHardwareSpi;
 
  /* Initialise the module */
  Mirf.init();
 
  /* Set the receiving address of this module. This must be a 5 byte
  *  character string */
  Mirf.setRADDR((byte *)"SENS1");
 
  /* Set the payload length to size unsigned int (size of data from
  *  the analogue input A0) */
  Mirf.payload = sizeof(uiData);
  
  /* Set the channel. Channel 90 = 2.490GHz */
  Mirf.channel = 90;
 
  /* Configure the module */
  Mirf.config();
 
  Serial.println("Module initialised");
  
}



/******* Main Program ********/
void loop()
{
  
   Serial.println(ReadTimeDate());
   
  /* Set transmit address to client module 1 */
  Mirf.setTADDR((byte *)"CLI01");
 
  Serial.print("Sending: ");
  Serial.println(uiData);
 
  /* ...and send it to the client */
  Mirf.send((byte *)&uiData);
 
  /* Wait for module to finish sending */
  while(Mirf.isSending());
  
  uiData++;
 
  /* Wait a little */
  delay(1000);
}
  
//=====================================
int RTC_init(){ 
     pinMode(cs,OUTPUT); // chip select
     // start the SPI library:
     SPI.begin();
     SPI.setBitOrder(MSBFIRST); 
     SPI.setDataMode(SPI_MODE1); // both mode 1 & 3 should work 
     //set control register 
     digitalWrite(cs, LOW);  
     SPI.transfer(0x8E);
     SPI.transfer(0x60); //60= disable Osciallator and Battery SQ wave @1hz, temp compensation, Alarms disabled
     digitalWrite(cs, HIGH);
     delay(10);
}
//=====================================
int SetTimeDate(int d, int mo, int y, int h, int mi, int s){ 
   int TimeDate [7]={s,mi,h,0,d,mo,y};
   for(int i=0; i<=6;i++){
      if(i==3)
         i++;
      int b= TimeDate/10;
      int a= TimeDate-b*10;
      if(i==2){
         if (b==2)
            b=B00000010;
         else if (b==1)
            b=B00000001;
      }   
      TimeDate= a+(b<<4);
        
      digitalWrite(cs, LOW);
      SPI.transfer(i+0x80); 
      SPI.transfer(TimeDate);        
      digitalWrite(cs, HIGH);
  }
}
//=====================================
String ReadTimeDate(){
   String temp;
   int TimeDate [7]; //second,minute,hour,null,day,month,year      
   for(int i=0; i<=6;i++){
      if(i==3)
         i++;
      digitalWrite(cs, LOW);
      SPI.transfer(i+0x00); 
      unsigned int n = SPI.transfer(0x00);        
      digitalWrite(cs, HIGH);
      int a=n & B00001111;    
      if(i==2){   
         int b=(n & B00110000)>>4; //24 hour mode
         if(b==B00000010)
            b=20;        
         else if(b==B00000001)
            b=10;
         TimeDate=a+b;
      }
      else if(i==4){
         int b=(n & B00110000)>>4;
         TimeDate=a+b*10;
      }
      else if(i==5){
         int b=(n & B00010000)>>4;
         TimeDate=a+b*10;
      }
      else if(i==6){
         int b=(n & B11110000)>>4;
         TimeDate=a+b*10;
      }
      else{   
         int b=(n & B01110000)>>4;
         TimeDate=a+b*10;   
         }
   }
   temp.concat(TimeDate[4]);
   temp.concat("/") ;
   temp.concat(TimeDate[5]);
   temp.concat("/") ;
   temp.concat(TimeDate[6]);
   temp.concat("     ") ;
   temp.concat(TimeDate[2]);
   temp.concat(":") ;
   temp.concat(TimeDate[1]);
   temp.concat(":") ;
   temp.concat(TimeDate[0]);
  return(temp);
}

You seem to be using two different hardware SPI drivers at the same time. Perhaps you would have more success if you modified your RTC interface to use MirfHardwareSpi.

Perhaps you would have more success if you modified your RTC interface to use MirfHardwareSpi.

I'm not really sure how to go about this. Any additional comments or example code would be great!

Jamal:

Perhaps you would have more success if you modified your RTC interface to use MirfHardwareSpi.

I'm not really sure how to go about this. Any additional comments or example code would be great!

Look at the documentation for the SPI library and understand how the interface works.

Look at the documentation and/or code for the MirfHardwareSpi library and learn how the interface works.

Look at your code and identify the places where you use the SPI interface. From your knowledge and understanding of the SPI interface, work out what the corresponding function would be in the MirfHardwareSpi interface and replace the SPI call with the equivalent MirfHardwareSpi call.

The SPI interface is pretty simple so this should not be a huge exercise.

Hello,

I am trying to use an Arduino uno to operate a nRF24L01 2.4GHz wireless transceiver and DS3234 real time clock module at the same time.

I've got the same problem.

It would be great if someone could please post a solution with the corrected code.

Thanks

Jeffro_Aus: I've got the same problem.

Are you trying to use two different SPI implementations at the same time, too?

Are you trying to use two different SPI implementations at the same time, too?

I am actually using the same components and same setup as Jamal (two different SPI implementations at the same time). I am also using Mirf and cannot figure this one out.

OP, you might check if the last part of this post is applicable to your problem, http://arduino.cc/forum/index.php/topic,164715.msg1230042.html#msg1230042

Jeffro_Aus: cannot figure this one out.

Well, I don't know what's causing the problem but using two different SPI implementations at the same time sounds like asking for trouble and given that it isn't working I would have thought that fixing that was an obvious first thing to try.