noob confuse with SPI - setSS() missing / RFM70 module

Hello sbright33,

here is the link to the library: skip.co.at/RFM70/RFM70.zip
unpack it to C:\Program Files (x86)\arduino-1.0\libraries\RFM70.

Pinout:
CE Pin 9
CSN Pin 10
SCK Pin 13
MISO Pin 12
MOSI Pin 11
IRQ Pin 8

and don't forget the 3.3 V stepdown converter!

Please ask me if you have any questions!

Example code (not all was tested):

#include "RFM70.h"

RFM70class RFM70;

byte RFM70_buf[MAX_PACKET_LEN];  //RFM70 data buffer
unsigned long RFMSendTime = 0;   //next send time
int RFMSendSpeed=1000;           //send packet every 1000 msec


void setup()
{
    Serial.begin(57600);  
    Serial.println("Arduino Start");    
    RFM70.begin();
    RFM70.Initialize();
    RFMSendTime = millis();
  
} 

void loop()
{
    rfmTask();                                    //check for RFM70 event in polling mode
    if (millis() > RFMSendTime)                   //send packet
    {                                                    
      RFMSendTime = millis() + RFMSendSpeed; 
      RFM70_buf[0]=0X41;      
      RFM70_buf[1]=0X42;
      RFM70_buf[2]=0X43;
      RFM70_buf[3]=0X44;      
      RFM70.Send_Packet(WR_TX_PLOAD,RFM70_buf,4);
      Serial.println("Sending data");       
    }  
}

void rfmTask()                //RFM70 event handler
{
  if (RFM70.RfmInterrupt())
  {
    if (RFM70.TxDataSentInterrupt())
    {
       Serial.println("Data sent OK");
       RFM70.SwitchToRxMode();
    }
    if (RFM70.TxDataSentErrorInterrupt())
    {
       Serial.println("Data sent error");
       RFM70.SwitchToRxMode();
    }
    if (RFM70.RxDataReadyInterrupt())
    {
       Serial.println("Data received: ");
       byte rx_len = RFM70.Receive_Packet(RFM70_buf);
       if (rx_len) 
       {
          for(byte i=1;i<rx_len;i++)
          {
            Serial.print(i);
            Serial.print("->");
            Serial.println(RFM70_buf[i]);
          }         
       }    
     }
  }
}

Thanks will try it later! I feel like I've been paid back for all the hard work I've done on the motor code...

Superfred:
Hello sbright33,

here is the link to the library: skip.co.at/RFM70/RFM70.zip
unpack it to C:\Program Files (x86)\arduino-1.0\libraries\RFM70.

Pinout:
CE Pin 9
CSN Pin 10
SCK Pin 13
MISO Pin 12
MOSI Pin 11
IRQ Pin 8

and don't forget the 3.3 V stepdown converter!

Please ask me if you have any questions!

Example code (not all was tested):

#include "RFM70.h"

RFM70class RFM70;

byte RFM70_buf[MAX_PACKET_LEN];  //RFM70 data buffer
unsigned long RFMSendTime = 0;   //next send time
int RFMSendSpeed=1000;           //send packet every 1000 msec

void setup()
{
    Serial.begin(57600); 
    Serial.println("Arduino Start");   
    RFM70.begin();
    RFM70.Initialize();
    RFMSendTime = millis();
 
}

void loop()
{
    rfmTask();                                    //check for RFM70 event in polling mode
    if (millis() > RFMSendTime)                   //send packet
    {                                                   
      RFMSendTime = millis() + RFMSendSpeed;
      RFM70_buf[0]=0X41;     
      RFM70_buf[1]=0X42;
      RFM70_buf[2]=0X43;
      RFM70_buf[3]=0X44;     
      RFM70.Send_Packet(WR_TX_PLOAD,RFM70_buf,4);
      Serial.println("Sending data");       
    } 
}

void rfmTask()                //RFM70 event handler
{
  if (RFM70.RfmInterrupt())
  {
    if (RFM70.TxDataSentInterrupt())
    {
       Serial.println("Data sent OK");
       RFM70.SwitchToRxMode();
    }
    if (RFM70.TxDataSentErrorInterrupt())
    {
       Serial.println("Data sent error");
       RFM70.SwitchToRxMode();
    }
    if (RFM70.RxDataReadyInterrupt())
    {
       Serial.println("Data received: ");
       byte rx_len = RFM70.Receive_Packet(RFM70_buf);
       if (rx_len)
       {
          for(byte i=1;i<rx_len;i++)
          {
            Serial.print(i);
            Serial.print("->");
            Serial.println(RFM70_buf[i]);
          }         
       }   
     }
  }
}

This is code for transmitting? How recive? I have 2 arduino's and 2 rfm70 mnodule.

Hello Fajkowsky,

this code is transmitting and receiving.

Ecery second we are sending one packet:

    if (millis() > RFMSendTime)                   //send packet
    {                                                    
      RFMSendTime = millis() + RFMSendSpeed; 
      RFM70_buf[0]=0X41;      
      RFM70_buf[1]=0X42;
      RFM70_buf[2]=0X43;
      RFM70_buf[3]=0X44;      
      RFM70.Send_Packet(WR_TX_PLOAD,RFM70_buf,4);
      Serial.println("Sending data");       
    }

We are constantly polling the RFM70 status:

rfmTask();

If the data was sent successfully or an error occoured we switch back to RX Mode:

RFM70.SwitchToRxMode();

So this code sends every second one packet, the rest of the time the RFM70 is waiting in receive mode.

If you load this code in two Arduinos with RFM70s, it can work but if both are sending exactly the same time it will not. To overcome this you can have only one sending and one receiving (delete the send code in one) , or you choose different (maybe random) send times (like Ethernet wait a random time if the sending was unsuccessful), or you use a polling mode where the master tells the slave when to send.

Tell me if you have still questions.
Fred

i have done exactly the same setup of yours and i also cared for this following thing:

If you load this code in two Arduinos with RFM70s, it can work but if both are sending exactly the same time it will not. To overcome this you can have only one sending and one receiving (delete the send code in one) , or you choose different (maybe random) send times (like Ethernet wait a random time if the sending was unsuccessful), or you use a polling mode where the master tells the slave when to send.

The its not receiving anything , i have deumilanove on receiver side with atmega8 and the uno on the sender side.

Hi NI$HANT,

do you get any serial info from polling rfmTask() like "Data sent OK" or "Data sent error" on the sender side?
You should get at least "Data sent error" if the Receiver side is off.
If not it seems that you have a hardware problem.

Do you use this pinout?
CE Pin 9
CSN Pin 10
SCK Pin 13
MISO Pin 12
MOSI Pin 11
IRQ Pin 8

and don't forget the 3.3 V stepdown converter!

Fred

do you get any serial info from polling rfmTask() like "Data sent OK" or "Data sent error" on the sender side?

Hi Fred i just get the "Sending data" on serial from the TX and Arduino start on the rx and nothing else and i have tried using the original code of yours at both the tx and rx and also tweaked the code to just BE a tx or a rx so no interference happens, still it works the same NOTHING is there.

Do you use this pinout?
CE   Pin 9
CSN  Pin 10
SCK  Pin 13
MISO Pin 12
MOSI Pin 11
IRQ  Pin 8

Yes, exactly this connectivity.

and don't forget the 3.3 V stepdown converter!

I just powered the modules from 3.3v at other sites the people were doing the same and i read i think that the SPI pins on RFM70 are 5v tolerant.

Hi,

I was using 1K Resistors to seperate the 5V Arduino and the 3.3 V RFM70.
I can't say if the RFM70 is 5V tolerant.

The logic of my code is:
Every second a packet is sent,
and independently RFMTask() is polling the IRQ pin.

This Pin goes low if one of the following events occour:
-Data sent OK (Ack from receiver received)
-Data sent Error (no Ack received)
-Data received

RFM70.TxDataSentInterrupt(), RFM70.TxDataSentErrorInterrupt() and RFM70.RxDataReadyInterrupt() functions checks the RFM70 on SPI level which of the events trigged the IRQ (and clears the IRQ).

If you still have problems you can uncomment the //Serial.print commands (there are many of them) in the RFM70.cpp file (you may have to restart your Arduino IDE to activate the change) to get low level trace printout of the SPI interface data.
You can send me the Trace data for debugging.

My code don't stop if the RFM70 is not present, so you get no error but you will receive no events.

Fred

Hi Fred thank you for the help actually if you see this>> http://www.hoperf.com/upload/rf/RFM70.pdf then you can note on the page 22 that im connecting correctly and i have double checked my connections as such they are fine , im just not having the Decoupling caps in the systems thats just a small difference but i checked the power on the wireless modules its comingin fine to them.

One thing more , Is there a need to set CHANNEL's in both of these modules tx and rx both, However i have tried also with this by setting them to same channel that is 1.

Im now receiving like this: after making some changes and putting a ATmega168 in one of the modules instead of an ATmega8

Data received: 
Sending data
Data sent OK
Data received: 
Data sent OK
Data received: 
->f
->L
->?
->?
->?
->e
a->L
->É
Data sent OK
Data received: 
Data sent error
Data sent OK
Data sent OK
Data sent OK
Data sent error
Data received: 
Data received: 
Data received: 
Data sent OK
Data received: 
Data sent error
Data received: 
Data sent OK
Data sent OK

now again the problem BOTH The modules just keep on sending nothing received.

Hi,

You receive events, so there cant be much wrong anymore.

Start just in the simplest case: one side is only sending, the other side is only receiving.
(comment out all sending code on the receiving side, at least

//RFM70.Send_Packet(WR_TX_PLOAD,RFM70_buf,4);

I inserted a debug line to print out how many bytes are received:

       .....
if (RFM70.RxDataReadyInterrupt())
    {
       Serial.print("Data received, length: ");
       byte rx_len = RFM70.Receive_Packet(RFM70_buf);
       Serial.println(rx_len);
       if (rx_len) 
       {
          for(byte i=1;i<rx_len;i++)
          {
            Serial.print(i);
            Serial.print("->");
            Serial.println(RFM70_buf[i]);
       ......
          }

The number of Bytes sent is the last argument in the RFM70.Send_Packet() command.
The same number of bytes should be received on the receiving end.

ATMEGA8:
My driver uses only GPIO functions, so I don't see any problem to use ATMEGA8, but maybe there is just a Pin numbering problem and SCK, MISO and MOSI uses different Pins compared to ATMEGA168.

I did similar to this yesterday, But im going to again try so that both our time investment is beneficial.

Ok i received this:

ata received: 
Data sent OK
Data received: 
->s
->3
->3
->3
->3
->?
a->?
->?
	->Ì

->Ï
->ÿ
->ÿ

->ÿ
->ÿ
->ÿ
->ÿ
Data sent OK
Data received: 
Data sent OK
Data sent error
Data sent error
Data received: 
Data sent error
Data received: 
Data sent OK
Data sent error
Data received: 
Data sent OK
Data received: 
Data sent error
Data received: 
Data received: 
Data sent OK
Data sent error
Data received: 
Data sent OK
Data received: 
Data sent OK
Data sent error
Data received: 
Data sent error
Data sent error
Data received: 
Data received: 
Data sent error
Data received: 
Data sent error
Data received: 
Data sent OK
Data sent error
Data sent error
Data received: 
Data sent error
Data sent OK
Data sent OK
Data received: 
Data sent error
Data sent OK
Data received: 
Data received: 
Data received: 
Data sent OK
Data sent error
Data sent OK
Data received: 
Data received: 
Data sent OK
Data sent OK
Data received: 
Data received: 
Data received: 
Data sent OK
Data sent OK
Data sent error
Data received: 
Data sent OK
Data sent error
Data received: 
Data sent error
Data received: 
Data sent error
Data received: 
Data sent OK
Data received: 
Data received: 
Data received: 
Data received: 
Data sent OK
Data received: 
Data sent OK
Data sent OK
Data sent error
Data sent OK
Data sent error
Data received: 
Data received: 
Data received: 
Data sent OK
Data received: 
Data received: 
Data sent OK
Data sent error
Data received: 
Data sent OK
Data sent OK
Data sent OK
Data sent error
Data received: 
Data sent OK
Data received: 
Data received: 
Data received: 
Data sent OK
Data sent error
Data received: 
Data received: 
Data sent OK
Data sent error
Data sent OK
Data sent OK
Data sent error
Data sent error
Data received: 
Data received: 
Data sent error
Data received: 
Data sent OK
Data received: 
Data received: 
Data sent error
Data sent OK
Data sent error
Data sent OK
Data sent error
Data sent OK
Data sent error
Data received: 
Data received: 
Data sent OK
Data received: 
Data received:

with this in Tx:

#include "RFM70.h"

RFM70class RFM70;

byte RFM70_buf[MAX_PACKET_LEN];  //RFM70 data buffer
unsigned long RFMSendTime = 0;   //next send time
int RFMSendSpeed=1000;           //send packet every 1000 msec


void setup()
{
    Serial.begin(57600);  
    Serial.println("Arduino Start");    
    RFM70.begin();
    RFM70.Initialize();
    RFMSendTime = millis();
  
} 

void loop()
{
    rfmTask();                                    //check for RFM70 event in polling mode
    if (millis() > RFMSendTime)                   //send packet
    {                                                    
      RFMSendTime = millis() + RFMSendSpeed; 
      RFM70_buf[0]=0X41;      
      RFM70_buf[1]=0X42;
      RFM70_buf[2]=0X43;
      RFM70_buf[3]=0X44;      
      RFM70.Send_Packet(WR_TX_PLOAD,RFM70_buf,4);
      Serial.println("Sending data");       
    }  
}

void rfmTask()                //RFM70 event handler
{
  if (RFM70.RfmInterrupt())
  {
    if (RFM70.TxDataSentInterrupt())
    {
       Serial.println("Data sent OK");
       RFM70.SwitchToRxMode();
    }
    if (RFM70.TxDataSentErrorInterrupt())
    {
       Serial.println("Data sent error");
       RFM70.SwitchToRxMode();
    }
    
  }
}

and this in Rx:

#include "RFM70.h"

RFM70class RFM70;

byte RFM70_buf[MAX_PACKET_LEN];  //RFM70 data buffer
unsigned long RFMSendTime = 0;   //next send time
int RFMSendSpeed=1000;           //send packet every 1000 msec


void setup()
{
    Serial.begin(57600);  
    Serial.println("Arduino Start");    
    RFM70.begin();
    RFM70.Initialize();
    RFMSendTime = millis();
  
} 

void loop()
{
    rfmTask();                                    //check for RFM70 event in polling mode
    if (millis() > RFMSendTime)                   //send packet
    {                                                    
      RFMSendTime = millis() + RFMSendSpeed; 
      RFM70_buf[0]=0X41;      
      RFM70_buf[1]=0X42;
      RFM70_buf[2]=0X43;
      RFM70_buf[3]=0X44;      
     // RFM70.Send_Packet(WR_TX_PLOAD,RFM70_buf,4);
      Serial.println("Sending data");       
    }  
}

void rfmTask()                //RFM70 event handler
{
  if (RFM70.RfmInterrupt())
  {
    if (RFM70.TxDataSentInterrupt())
    {
       Serial.println("Data sent OK");
       RFM70.SwitchToRxMode();
    }
    if (RFM70.TxDataSentErrorInterrupt())
    {
       Serial.println("Data sent error");
       RFM70.SwitchToRxMode();
    }
    if (RFM70.RxDataReadyInterrupt())
    {
       Serial.println("Data received: ");
       byte rx_len = RFM70.Receive_Packet(RFM70_buf);
       if (rx_len) 
       {
          for(byte i=1;i<rx_len;i++)
          {
            Serial.print(i);
            Serial.print("->");
            Serial.println(RFM70_buf[i]);
          }         
       }    
     }
  }
}

Hello,

I am confused about your serial output:
Was this from the TX or RX side?

I am asking because I see Data sent OK and Data received, but if you uncomment the sending on the RX side you should never get Data sent OK bacause you are not sending anything.

My log output is on the TX side:

Arduino Start
Sending data
Data sent OK
Sending data
Data sent OK
Sending data
Data sent OK
Sending data
Data sent OK

And on the RX side:

Data received, length: 4
0->65
1->66
2->67
3->68
Data received, length: 4
0->65
1->66
2->67
3->68

Fred

Hello,

one more question: which Arduino version do you use?
Serial.println(RFM70_buf*); should always give you a number under Version 1.0 and not a character.*
To be sure you can use Serial.println(RFM70_buf*, DEC);*
Fred

HI i have used 0022 IDE

Hi,

I ported my RFM70 Driver from Ver 0.22 to 1.0.1 some month ago, but I never tried if still works under 0.22.
But as you see in my log output, at least with IDE 1.0.1 and Atmega 328P/16MHZ/5V it works over a distance of several meters.
But as I am using only GPIO functions, I don't see any problem to use other ATMEGAs, I used the same driver on an ARM Cortex M3 (also GCC) successfully, changing only the PROGMEM to Constant and and the GPIO Read/Write commands.

Nevertheless, if you still have problems use the low level debug by uncomment the //Serial.print commands in the RFM70.cpp file, this gives you the information what realy happens on the SPI level together with the datasheet. This was very useful for me at the beginning for debugging.

One more info for you:
It is also possible to use W_ACK_PAYLOAD_CMD (RFM70.Send_Packet(W_ACK_PAYLOAD_CMD,tx_buf,len); ) to do a toway communication with only one side transmiting, see the RFM70 datasheet. Use the RFM70.TxEmptyFlag(); function to avoid TX buffer overflow.

Fred