RFM22B transceiver help

I’m trying to test the RFM22B transceiver modules using the simplest code possible and it’s not working. First of all, I don’t know if the antenna is the problem. It says on the product page that a 17 cm antenna worked. I soldered a smaller wire on one of the transceiver modules due to space constraints. WIll it really only work if the antenna is this length? As for the code, I read the datasheet for the RFM22B and it shows the SDI format as R/W A5 A4 A3 A2 A1 A0 D7 D6 D5 D4 D3 D2 D1 D0. This is the transmit code I loaded into one Arduino Pro Mini:

//SPSR = status register
//SPDR = data register
//SPCR = control register


#define DATAOUT 11//MOSI
#define DATAIN  12//MISO 
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss

byte clr;

// R/W = 1 signifies WRITE, R/W = 0 signifies READ
char spi_transfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}

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

  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  digitalWrite(SLAVESELECT,HIGH); //disable device 
  // SPCR = 01010000
  //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
  //sample on leading edge of clk,system clock/4 rate (fastest)
  SPCR = (1<<SPE)|(1<<MSTR);
  clr=SPSR;
  clr=SPDR;
  delay(10);
}

byte write_transceiver(void)
{
  
   int data;
   digitalWrite(SLAVESELECT,LOW);
  
  //data = 1000000111111111
  //R/W = 1, address = 1, send "11111111"
  data = spi_transfer((char)(0x81FF));
  digitalWrite(SLAVESELECT,HIGH); //release chip, signal end transfer
  return data;
}

void loop()
{
  int data;
 data = write_transceiver();

}

This is the receive program I loaded into my other Arduino Pro Mini:

//SPSR = status register
//SPDR = data register
//SPCR = control register

#define DATAOUT 11//MOSI
#define DATAIN  12//MISO 
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss

byte clr;

// R/W = 1 signifies WRITE, R/W = 0 signifies READ
char spi_transfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}

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

  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  digitalWrite(SLAVESELECT,HIGH); //disable device 
  // SPCR = 01010000
  //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
  //sample on leading edge of clk,system clock/4 rate (fastest)
  SPCR = (1<<SPE)|(1<<MSTR);
  clr=SPSR;
  clr=SPDR;
  delay(10);
}

byte read_transceiver(void)
{
 
  int data;
  digitalWrite(SLAVESELECT,LOW);
  
  //data = 0000000100000000
  //R/W = 0, address = 1
  data = spi_transfer((char)(0x0100));
  digitalWrite(SLAVESELECT,HIGH); //release chip, signal end transfer
  return data;
}


void loop()
{
 
char result;
 result = read_transceiver();
 Serial.print("result:");
 Serial.print(result,BIN);
 Serial.print("\n");

}

The result printed is “0” when it should be “11111111” that is received. Can you see anything wrong or do you have any insight into the issues here? Thank you!!

A 17cm antenna works out to ¼ wavelength (for a 433Mhz module such as this). While this is ideal, a shorter length will still work (but will give a shorter range).

If your modules aren’t working even when in close proximity to each other, it’s not an antenna problem. Sorry, I can’t help with the code, but I know these modules are a pain to get working. Someone I know spent quite a while before he managed to get them working, including a number of discussions with the manufacturer. This was for a commercial project, so I don’t think he’d be able to share his code. Your best bet is to find someone who has already solved this and copy their code.

The antenna should not be an issue if you aren’t receiving/transmitting ANY signal. Even a poorly constructed, unmatched, coat hanger should pass the signal a few inches across your desk well enough to be received.

A photo would be nice. It would help solve some other issues that might come up as well.

Is this the breakout board or the bare RFM12B? Do you have filtering caps (see ref des. on pg 65)? Are you powering it with regulated 3v3? How long are the wires from the Arduino to the RF unit? Can you check the current draw to see if it is tranmitting or do you have a scanner? Is the arduino 5v or 3v3, level converting the signal sent to the RF unit?

One of the best reasons to use the Arduino (and other popular uc’s) is the vast amount of libraries. A quick search turned up [this library for the RF22B. Why not use this or another pre-made library to test the hardware and get things off the ground. Later, with known-good hardware config, you can either modify the library to remove unecessary functions or write your own.](RF22: RF22 library for Arduino)

start with working code for RFM’s. Lots on the 'net.