RFM22B

Tests with HOPE RFM22B (V2.0) Transceiver Module

and Porting arduino-Software for the following communication-methods:

  • RF22: unaddressed, unreliable messages
  • RF22Datagram: addressed, unreliable messages
  • RF22ReliableDatagram: addressed, reliable, retransmitted, acknowledged messages.
  • RF22Router: multi hop delivery from source node to destination node via 0 or more intermediate nodes
  • RF22Mesh: multi hop delivery with automatic route discovery and rediscovery.

Info

See http://www.hoperf.com

Images

RFM22-Module:

/media/uploads/charly/_scaled_rfm22.jpg

RFM22 with mbed:

/media/uploads/charly/_scaled_rfm22_with_mbed.jpg

RFM22 with LPCmini:

/media/uploads/charly/_scaled_rfm22_with_lpcmini.jpg

Features (from HopeRF-Homepage)

  • Frequency Range: 433/868/915MHz ISM bands
  • Sensitivity = –121 dBm
  • Output power range:+20 dBm Max
  • Low Power Consumption
  • Data Rate = 0.123 to 256 kbps
  • FSK, GFSK, and OOK modulation
  • Power Supply = 1.8 to 3.6 V
  • Ultra low power shutdown mode
  • Digital RSSI
  • Wake-up timer
  • Auto-frequency calibration (AFC)
  • Power-on-reset (POR)
  • Antenna diversity and TR switch control
  • Configurable packet handler
  • Preamble detector
  • TX and RX 64 byte FIFOs
  • Low battery detector
  • Temperature sensor and 8-bit ADC
  • –40 to +85 °C temperature range
  • Integrated voltage regulators
  • Frequency hopping capability
  • On-chip crystal tuning
  • 14-PIN DIP & 16-PIN SMD package
  • Low cost

Available at Sparkfun and many others: http://www.sparkfun.com/products/10153

Problems

There are two Versions of the Module

  • RFM22B-S1
  • RFM22B-S2

They have different oscilators and they seem to have different frequency-errors. I combined a -S1 and a -S2 and used 869.50 Hz on one module. I had to adjust the frequency on the other to 869.49 Hz to get a working communication! Maybe the AFC could solve this, but I didn't test this yet.

By activating AFC, both modules can use the same frequency as expected!-> Added activation of AFC to library.

Now it works perfect

Connecting

FRM22-PINConnect to
ANTa simple 8cm (868MHz) wire for testing
RX_ANTGPIO1
TX_ANTGPIO0
VCCVout(3.3V)
GNDGND
GPIO0TX_ANT
GPIO1RX_ANT
GPIO2
SDNGND
NIRQInterrupt (p15)
NSELChip-Select (p14)
SCKSPI-SCK (p13)
SDISPI-MOSI(p11)
SDOSPI-MISO(p12)

Software

  • Original Software for arduino (c) by Mike McCauley
  • Port to mbed by Karl Zweimueller
  • Library:

Import libraryRF22

Library for HopeRF RFM22 / RFM22B transceiver module ported to mbed. Original Software from Mike McCauley (mikem@open.com.au) . See http://www.open.com.au/mikem/arduino/RF22/

Test program for ReliableDatagram Receive

main.c

#include "mbed.h"
#include <RF22.h>
#include <RF22ReliableDatagram.h>

// Sample programm for ReliableDatagramm Receiving
// Uses address 2 and receives from Sender
// See notebook http://mbed.org/users/charly/notebook/rfm22/ for connecting RFM22 to mbed

Serial pc(USBTX, USBRX);

//RF22ReliableDatagram (uint8_t thisAddress, PinName slaveSelectPin, PinName mosi, PinName miso, PinName sclk, PinName interrupt)
RF22ReliableDatagram rf22(0,p14,p11,p12,p13,p15);


float frequency = 869.50;           // frequency 

const uint8_t sender_adress = 1;        // address of sender
const uint8_t receiver_adress =2;       // address of receiver

void receive_loop() {
    while (1) {
        uint8_t buf[RF22_MAX_MESSAGE_LEN];
        uint8_t len = sizeof(buf);

        //boolean recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* from = NULL, uint8_t* to = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);
        if (rf22.recvfromAck(buf, &len)) {
            pc.printf("got message: >%s<\n\r",(char*)buf);
        }
    }
}

int main() {

    pc.baud(115200);
    pc.printf("\n\rConnected to mbed\n\r");

    pc.printf ("RF22-Test-Reliable-Receive V1.0\n\r");

    // initialize the device
    if (!rf22.init())
        pc.printf("RF22 init failed\n\r");

    // set to 19.2 KB
    if (!rf22.setModemConfig(RF22::GFSK_Rb19_2Fd9_6))
        pc.printf("setModemConfig failed");


    if (!rf22.setFrequency(frequency))
        pc.printf("setFrequency failed");

    // Code for receiving
    pc.printf("I am receiving with address %i ...\n\r",receiver_adress);
    rf22.setThisAddress(receiver_adress);     // receiver-adress

    receive_loop();             // start receiving
}


Test program for ReliableDatagram Send

main.c

#include "mbed.h"
#include <RF22.h>
#include <RF22ReliableDatagram.h>

// Sample programm for ReliableDatagramm Sending
// Uses address 1 and sends to RF22 with address 2
// See notebook http://mbed.org/users/charly/notebook/rfm22/ for connecting RFM22 to mbed

Serial pc(USBTX, USBRX);

//RF22ReliableDatagram (uint8_t thisAddress, PinName slaveSelectPin, PinName mosi, PinName miso, PinName sclk, PinName interrupt)
RF22ReliableDatagram rf22(0,p14,p11,p12,p13,p15);

float frequency = 869.50;           // frequency 

const uint8_t sender_adress = 1;        // address of sender
const uint8_t receiver_adress =2;       // address of receiver

int   counter = 0;                      // messagecounter

// send messages forever
void send_loop() {
    uint8_t data[32] = "";

    while (1) {

        sprintf((char*)data,"Message-Nr:     %d",counter++);
        //sendtoWait(uint8_t* buf, uint8_t len, uint8_t address);
        pc.printf("\n\rStart sending ... ");
        if (rf22.sendtoWait(data, sizeof(data), receiver_adress)) {
            pc.printf("Send to %i ACK: >>%s<< ", receiver_adress,(char*)data);
        } else {
            pc.printf("Send to %i NOTACK: >>%s<< ", receiver_adress,(char*)data);
        }
        pc.printf("sleeping 2 seconds...  ");
        wait(2);  // Wait 2 Seconds
    }
}

int main() {

    pc.baud(115200);
    pc.printf("\n\rConnected to mbed\n\r");

    pc.printf ("RF22-Test-Reliable-Send V1.0\n\r");

    // initialize the device
    if (!rf22.init())
        pc.printf("RF22 init failed\n\r");

    // set to 19.2 KB
    if (!rf22.setModemConfig(RF22::GFSK_Rb19_2Fd9_6))
        pc.printf("setModemConfig failed");

    if (!rf22.setFrequency(frequency))
        pc.printf("setFrequency failed");

    // Code for sending
    pc.printf("I am sending with address %i to adress %i ...\n\r",sender_adress,receiver_adress  );
    rf22.setThisAddress(sender_adress);     // sender-adress

    send_loop();                // start sending
}



...

History

16.1.2012: Got first version of software working. Communication with RF22-Class on a mbed and a LPCmini with two RFM22B-modules works!

13.2.2012 Ported RF22Datagramm and RF22ReliableDatagramm classes for point to point communication - Quick and dirty! Works between mbed and LPCmini

21.2.2012 Got AFC working (Module RFM22B-S1 and -S2 can communicate without the need to adjust frequency)

13.3.2013 Updated Library to latest version of original Code of Mike

TODO: ... Beautify Ported Code


14 comments on RFM22B:

21 Feb 2012

Sparkfun also has a handy breakout board for the RFM22B-S2 that would be a bit easier to solder pins on for use in a breadboard.

RFm22

06 May 2012

ever get the other classes ported? Would it be difficult?

08 May 2012

steve childress wrote:

ever get the other classes ported? Would it be difficult?

Hi Steve!

Which other classes? The Library RF22 contains all classes from the original Package from Mike McCauley:

Import libraryRF22

Library for HopeRF RFM22 / RFM22B transceiver module ported to mbed. Original Software from Mike McCauley (mikem@open.com.au) . See http://www.open.com.au/mikem/arduino/RF22/

I've only worked with

  • RF22: unaddressed, unreliable messages
  • RF22Datagram: addressed, unreliable messages
  • RF22ReliableDatagram: addressed, reliable, retransmitted, acknowledged messages

They work fine!

Charly

09 Oct 2012

Hi Karl

Have you work with RF22mesh yet? With this library(RF22mesh) , what is max number of nodes we can inplement to create an ad-hoc network

10 Oct 2012

Hi tran nghia!

Tran Nghia wrote:

Hi Karl

Have you work with RF22mesh yet? With this library(RF22mesh) , what is max number of nodes we can inplement to create an ad-hoc network

No, I didn't test with RF22Mesh, only RF22Datagram and RF22ReliableDatagram, which work without problems here.

I had a quick look on the code and found no explicit limit for the number of nodes in the code. So the limit may be the maximum number of nodes to a target, as the route is sent across the mesh in one message. But I didn't cross-check this.

Regards Charly

11 Oct 2012

Thanks Karl

We have project associating this library, we must work with RF22Mesh and I recommended my senior to use this library but he didn't believe RF22Mesh and RF22Router. He said that RF22Mesh is proper with a few nodes but a lot of nodes

To implement a test with RF22Mesh is quite expensive, hence i want to persuade myseft and my senior of RF22Mesh

So that you know any proof or information to prove the right of RF22Mesh, don't you?

Thanks again

22 May 2013

Just wanted to say a quick thanks for this port of the RFM22b code to mbed. I've just purchased a couple of RFM22B breakout boards http://modtronicsaustralia.com/shop/rfm22b-s2-rf-transceiver-breakout-board-v2/ and had them communicating in no time.

Keep up the good work - very much appreciated!!

03 Oct 2013

Hi Karl, what is the distance one can transmit using this tranceiver? 400M >?

03 Oct 2013

Hi Ray!

I didn't do special distance tests, but I use the RFM22 inside my house from the basement up to the 2nd floor. And I have concrete floors and brick-walls and closed doors. No problem. I receive all messages. Outside they should do much higher distances. With more power (setTxPower up to 20dBm) 400 meters should be no problem! But it depends.

Charly

25 Mar 2014

Anyone know of the proper transform from RSSI (0..255) to received power in dBm? There's a chart in the data sheet, but not sure to do with the end case values. Two RFM22's here, < 1m distance, my formula shows -4dBm received, with +17dBm TX. That seems high - should be perhaps 10dB less, from experience. At 150 ft. and many walls in the path, I see -25dBm which is a booming signal. Again maybe 10-20dB less is what I'd expect. Antennas are just wire, half the 1/4 wave they should be.

This is at 433MHz and yes the free space path loss is much less than 900MHz, and very much less than 2.4GHz.

27 Mar 2014

Hi!

I did never calculate the real dBm from the read RSSI-Register-Values. But as you say the only source is the diagram in the datasheet: /media/uploads/charly/rfm22_rssi.png

The datasheet says that the real dBm can be differ because of receiver-settings (Amplifier, AGC,...). Another issue could be the time when you read the RSSI-Value.

But my experience is, that the modules have a good receiver. I use them at 869 Mhz and thy work well between walls and floors. And you can send with a lot of power :-)

Charly

19 Dec 2014

Hi Karl, you did a amazing job!! I only spent half a day to make it working on my boards(stm32f407 and RF22). But I got a problem when I tried to drive two RF22 on just one board. it seems didn't work with multiple RF22 at the same time. I wonder if it's caused by "disable_irq()" and " enable_irq()" as of two RF22s using different interrupts. I replaced them with "_interrupt.disable_irq()" and "_interrupt.enable_irq()", it didn't work too. Would you please give me some advises, about how to connect two more RF22s to one board?

Thanks a lot!

12 Jan 2015

Hello John!

Sorry, but I didn't see your comment. I've never tried to connect 2 RFM22, but I can think that it makes problems. The protected sections are required to prevent parallel change of one ressource.

Do you use one SPI-Interface or two? I'm not sure if it is possible to define 2 SPI-Objects for the same lines. You use 2 interrupt-lines. And I think two different Chip-Select-Lines too. If not, this could be a problem.

Another issue could be power-consumption. The RFM22 can take a lot of current when sending. And sending on both devices the same time won't be a good idea I think.

When do you get errors? compiletime, initializing, receiving, sending?

I think the library must be adopted to support 2 devices at one time. At the moment I'm working on another project, so I have little time for this issue.

Maybe you can adopt the library and make a pull-request. Then I can integrate to the library.

BTW: What is your usecase for two RFM22? Receiving simultanoiusly on two different frequencies? I think there is an option like channel-hopping, but I'm not sure.

Charly

18 Nov 2015

Hi, I would like to test RFM22 with firmware K64.

Please log in to post comments.