RFM12B Range Issue

Hi guys,
I have problem with RFM12B 433MHz distance range issue, i am not using RFM12B library that is use for Arduino. Yes i am also working with arduino but with my RFM12B code and is working fine. What i found is RFM12B with Arduino library it works upto longer distance and high penetration through walls, even i dug a hole and put my unit inside, then also it was working and it worked upto 1 football ground. BUT with my code i am not getting that much range and penetration. Plz help me with this.
I know it may be Bit Error Rate problem as Low bit rate less bandwidth and more range, i tried that but problem not solved. I am beginner to this understanding big complicated Arduino Library of RFM12B is tough. Thats why i had written my own code but its Performance is not like them.

We exclusively use JeeLib. If you do not wish to use JeeLib, then you could try Low Power Labs:

(Note that the two libraries use a different protocol, so you cannot mix the two.)

i am using low power lab,its not about which library, i am saying library works very fine, giving long range and more penetration power. My code which doesn’t use library, its totally my code. Its working good but distance and penetration is less.

In that case, you must read the data sheet for the module that you are using, and see which of your settings are different to the those in the library, and change your operating parameters to give them more optimal settings. If you set up and operate the radio module in exactly the same way that the library does, then it must surely work in exactly the same way.

Hi,
Decoded code of Low Power Lab today. That library also Is reference of
Jeelib-Master library. I didn’t understand part of enum used in code.
// transceiver states, these determine what to do with each interrupt
enum {
TXCRC1=0, TXCRC2=1, TXTAIL=2, TXDONE=3, TXIDLE=4,
TXRECV=5,
TXPRE1=6, TXPRE2=7, TXPRE3=8, TXSYN1=9, TXSYN2=10,
};

This part.

They have used these states with rxstate in InterruptHandler() function, I
didn’t understand that part. How is that rxstate is updating?

Thank You that you are replying my problems.
waiting for reply
Omkar Teli.

I have never looked at the receive part of JeeLib, so I’m sorry but I cannot answer that.

I could easily be wrong, but I do not think that your problem will lie in that area. It is much more likely that you have made one or more of the power settings (transmit) or receiver gain settings different. I would check those things first.

Hi,
Here i am sending you my code and their code. kindly check it. i am also
so close reveal that secret.

  1. LIBRARY SOLVED is code that i decoded but is just transmitter code. To
    test transmit Receive you have to upload this transmit sketch and for
    receiver you have to upload Receive example in RFM12B-master.
    2)FineRxTx is my code
    3)RFM12B-master is that library which is available on Internet, You can
    test Send & Receive code of it, you will find its performance is far better
    than my code FineRxTx.

Thanks & Regards,
Omkar Teli.

hi,
As i am new to this community, i am unable to upload my code files so i am sharing my google drive link to refer my code. kindly click the link
https://drive.google.com/open?id=0B1yUVp_tiA2OYjNzakpjby1NT0E

Please upload your code here. You should be able to do that now.

ok i am uploading my code 1st
Transmitter

#include <SPI.h>
#include <stdlib.h>
#include <PinChangeInt.h>

#define SCK_PIN  13
#define MISO_PIN 12
#define MOSI_PIN 11
#define SS_PIN   10
#define LED       8
#define nIRQ      2


volatile unsigned int i,j,k;
unsigned int ChkSum;


void setup() 
{
    Serial.begin(115200);
    SPI.begin();
    portInit();
    rfInit();
    SPI.setClockDivider(SPI_CLOCK_DIV8);
}

void portInit()
{
        pinMode(nIRQ, INPUT);
        pinMode(LED, OUTPUT);
        pinMode(MOSI_PIN, OUTPUT);
        pinMode(MISO_PIN, INPUT);
        pinMode(SCK_PIN, OUTPUT);
        pinMode(SS_PIN, OUTPUT);
}

void rfInit()
{     Serial.println("rfInit Started");
      writeCmd(0x80E7); //EL,EF,868band,12.0pF
      writeCmd(0x8239); //!er,!ebb,ET,ES,EX,!eb,!ew,DC
      writeCmd(0xB800);
      writeCmd(0xA640); //frequency select
      writeCmd(0xC647); //4.8kbps
      writeCmd(0x94A0); //VDI,FAST,134kHz,0dBm,-103dBm
      writeCmd(0xC2AC); //AL,!ml,DIG,DQD4
      writeCmd(0xCA81); //FIFO8,SYNC,!ff,DR
      writeCmd(0xCED4); //SYNC=2DD4 , AG
      writeCmd(0xC483); //@PWR,NO RSTRIC,!st,!fi,OE,EN
      writeCmd(0x9850); //!mp,90kHz,MAX OUT
      writeCmd(0xCC17); //OB1 , ACOB0, LPX,Iddy,CDDIT,CBW0
      writeCmd(0xE000); //NOT USED
      writeCmd(0xC800); //NOT USED
      writeCmd(0xC040); //1.66MHz,2.2V
      Serial.println("rfInit Ended");*/
      
}

uint8_t writeCmd(uint16_t cmd) 
{
      digitalWrite(SS_PIN, LOW);
      Byte(cmd >> 8) << 8;
      Byte(cmd);
      digitalWrite(SS_PIN, HIGH);
}

uint8_t Byte(uint8_t out)
{
      delayMicroseconds(402);
       SPDR = out;
      // this loop spins 4 usec with a 2 MHz SPI clock
      while (!(SPSR & _BV(SPIF)));
      return SPDR;
}

uint16_t XFERSlow(uint16_t cmd) 
{
      digitalWrite(SS_PIN , LOW);
      uint16_t reply = Byte(cmd >> 8) << 8;
      reply |= Byte(cmd);
      digitalWrite(SS_PIN , HIGH);
    
      cmd = 0x0000;
      digitalWrite(SS_PIN , LOW);
      reply = Byte(cmd >> 8) << 8;
      reply |= Byte(cmd);
      digitalWrite(SS_PIN , HIGH);
    
      return reply;
}

void rfSend(unsigned char data)
{
        while(nIRQ==0);
        XFERSlow(0xB800 + data);
}

void loop()
{
  while(1)
  {
        writeCmd(0x823D);
        digitalWrite(LED,HIGH);
        
        writeCmd(0x0000);
        
        rfSend(0xAA); // PREAMBLE
        rfSend(0xAA);
        rfSend(0xAA);
        rfSend(0x2D); // SYNC
        rfSend(0xD4);
    
        rfSend(3);
          
        rfSend(0xAA); // DUMMY BYTES
        rfSend(0xAA);
        rfSend(0xAA);
        
        digitalWrite(LED,LOW);
        for(k=0; k<10000; k++); // some not very
      
    }
}

Receiver

#include <SPI.h>
#include <stdlib.h>

#define SCK_PIN  13
#define MISO_PIN 12
#define MOSI_PIN 11
#define SS_PIN   10
#define LED       8
#define nIRQ      2

volatile unsigned int i,j,data;
unsigned int count=0;
void setup()
{
        Serial.begin(115200);
        portInit();
        SPI.begin();
        SPI.setClockDivider(SPI_CLOCK_DIV8);
        rfInit();
        FIFOReset();
}

void portInit()
{
        pinMode(nIRQ, INPUT);
        pinMode(LED, OUTPUT);
        pinMode(MOSI_PIN, OUTPUT);
        pinMode(MISO_PIN, INPUT);
        pinMode(SCK_PIN, OUTPUT);
        pinMode(SS_PIN, OUTPUT);
}

void rfInit()
{ 
      Serial.println("rfInit Started");
      writeCmd(0x0000);
      writeCmd(0x80E7); //EL,EF,868band,12.0pF
      writeCmd(0x8205); //er,!ebb,ET,ES,EX,!eb,!ew,DC (bug was here)
      writeCmd(0xB800);
      writeCmd(0xA640); //freq select
      //writeCmd(0xC647); //4.8kbps
      writeCmd(0x94A0); //VDI,FAST,134kHz,0dBm,-103dBm
      writeCmd(0xC2AC); //AL,!ml,DIG,DQD4
      writeCmd(0xCAF1); //FIFO8,SYNC,!ff,DR (FIFO level = 8)
      writeCmd(0xCED4); //SYNC=2DD4;
      writeCmd(0xC483); //@PWR,NO RSTRIC,!st,!fi,OE,EN
      writeCmd(0x9850); //!mp,90kHz,MAX OUT
      writeCmd(0xCC17); //!OB1,!OB0, LPX,!ddy,DDIT,BW0
      writeCmd(0xE000); //NOT USE
      writeCmd(0xC800); //NOT USE
      writeCmd(0xC040); //1.66MHz,2.2V
      Serial.println("rfInit Ended");
      delay(2000);
      
}

uint8_t writeCmd(uint16_t cmd) 
{
      digitalWrite(SS_PIN, LOW);
      Byte(cmd >> 8) << 8;
      Byte(cmd);
      digitalWrite(SS_PIN, HIGH);
      delay(10);
}

uint8_t Byte(uint8_t out)
{
       SPDR = out;
      // this loop spins 4 usec with a 2 MHz SPI clock
      while (!(SPSR & _BV(SPIF)));
      return SPDR;
}

uint16_t XFERSlow(uint16_t cmd) 
{
      digitalWrite(SS_PIN , LOW);
      uint16_t reply = Byte(cmd >> 8) << 8;
      reply |= Byte(cmd);
      digitalWrite(SS_PIN , HIGH);
      return reply;
}

void rfSend(unsigned char data)
{
        while(nIRQ==0);
        XFERSlow(0xB800 + data);
}

unsigned char rfRecv() 
{
        
        while(1)
        {
        data = XFERSlow(0x0000);
        if ( (data & 0x8000) ) 
           {
               data = XFERSlow(0xB000);
               return (data & 0x00FF);//return data;//
           }
        }
}

void FIFOReset()
{
        writeCmd(0xCA81);
        writeCmd(0xCA83);
}

void loop()
{
       delayMicroseconds(500);
       writeCmd(0x82DD);
       delay(10);

       data = rfRecv();
       Serial.println(data,HEX);
       FIFOReset();
}

I seen 1 command which used to make BER(Bit Error Rate) 38kbps. Is 0xC608 in library file. That is may be the reason. i tried to put that command in mt code but is not working for 38kbps. My BER is 4.7kbps

You must transmit and receive at the same bit rate. As you wrote above, a lower bit rate will give longer range. The same register value is used for both transmit and receive, therefore you should set the same value in both transmit and receive sketches. The data sheet warns you: “It is recommended for long data packets to include enough 1/0 and 0/1 transitions, and to be careful to use the same division ratio in the receiver and in the transmitter.”

We have found problems with sending a long stream of 0x00 values, it will result in receive errors - hence the need for data that is not exclusively 0x00 or 0xFF.

(It is Bit Rate, or Data Rate, not Bit Error Rate (BER). That is quite different.)

Yea thanks for correction of bit error rate, yea you are right. that mistake while pasting, yes i made it same and Happy to say I got the problem. Is in Bit rate and SPI clock speed. Logically what i got is wrong. High bit rate more range. I don’t know why? for now.
another thing i posted my code where i was editing so now i am posting my backup code.

for transmitter----->

#include <SPI.h>
#include <stdlib.h>
#include <PinChangeInt.h>

#define SCK_PIN  13
#define MISO_PIN 12
#define MOSI_PIN 11
#define SS_PIN   10
#define LED       8
#define nIRQ      2


volatile unsigned int i,j,k;
unsigned int ChkSum;


void setup() 
{
    Serial.begin(115200);
    SPI.begin();
    portInit();
    rfInit();
}

void portInit()
{
        pinMode(nIRQ, INPUT);
        pinMode(LED, OUTPUT);
        pinMode(MOSI_PIN, OUTPUT);
        pinMode(MISO_PIN, INPUT);
        pinMode(SCK_PIN, OUTPUT);
        pinMode(SS_PIN, OUTPUT);
}

void rfInit()
{     Serial.println("rfInit Started");
      writeCmd(0x80E7); //EL,EF,868band,12.0pF
      writeCmd(0x8239); //!er,!ebb,ET,ES,EX,!eb,!ew,DC
      writeCmd(0xB800);
      writeCmd(0xA640); //frequency select
      writeCmd(0xC647); //4.8kbps
      writeCmd(0x94A0); //VDI,FAST,134kHz,0dBm,-103dBm
      writeCmd(0xC2AC); //AL,!ml,DIG,DQD4
      writeCmd(0xCA81); //FIFO8,SYNC,!ff,DR
      writeCmd(0xCED4); //SYNC=2DD4 , AG
      writeCmd(0xC483); //@PWR,NO RSTRIC,!st,!fi,OE,EN
      writeCmd(0x9850); //!mp,90kHz,MAX OUT
      writeCmd(0xCC17); //OB1 , ACOB0, LPX,Iddy,CDDIT,CBW0
      writeCmd(0xE000); //NOT USED
      writeCmd(0xC800); //NOT USED
      writeCmd(0xC040); //1.66MHz,2.2V
      Serial.println("rfInit Ended");

}

uint8_t writeCmd(uint16_t cmd) 
{
      digitalWrite(SS_PIN, LOW);
      Byte(cmd >> 8) << 8;
      Byte(cmd);
      digitalWrite(SS_PIN, HIGH);
}

uint8_t Byte(uint8_t out)
{
     
       Serial.print("0x");
       Serial.println(out,HEX);
       SPDR = out;
      // this loop spins 4 usec with a 2 MHz SPI clock
      while (!(SPSR & _BV(SPIF)));
      return SPDR;
}

uint16_t XFERSlow(uint16_t cmd) 
{
      digitalWrite(SS_PIN , LOW);
      uint16_t reply = Byte(cmd >> 8) << 8;
      reply |= Byte(cmd);
      digitalWrite(SS_PIN , HIGH);
    
      cmd = 0x0000;
      digitalWrite(SS_PIN , LOW);
      reply = Byte(cmd >> 8) << 8;
      reply |= Byte(cmd);
      digitalWrite(SS_PIN , HIGH);
    
      return reply;
}

void rfSend(unsigned char data)
{
        while(nIRQ==0);
        XFERSlow(0xB800 + data);
}

void loop()
{
  while(1)
  {
     
        digitalWrite(LED,HIGH);
        
        writeCmd(0x0000);
        
        rfSend(0xAA); // PREAMBLE
        rfSend(0xAA);
        rfSend(0xAA);
        rfSend(0x2D); // SYNC
        rfSend(0xD4);
    
        rfSend(3);
          
        rfSend(0xAA); // DUMMY BYTES
        rfSend(0xAA);
        rfSend(0xAA);
        
        digitalWrite(LED,LOW);
        for(k=0; k<10000; k++); // some not very
      
    }
}

For Receiver--------->

#include <SPI.h>
#include <stdlib.h>

#define SCK_PIN  13
#define MISO_PIN 12
#define MOSI_PIN 11
#define SS_PIN   10
#define LED       8
#define nIRQ      2

volatile unsigned int i,j,data;
unsigned int count=0;
void setup()
{
        Serial.begin(115200);
        portInit();
        SPI.begin();
        SPI.setClockDivider(SPI_CLOCK_DIV8);
        rfInit();
        FIFOReset();
}

void portInit()
{
        pinMode(nIRQ, INPUT);
        pinMode(LED, OUTPUT);
        pinMode(MOSI_PIN, OUTPUT);
        pinMode(MISO_PIN, INPUT);
        pinMode(SCK_PIN, OUTPUT);
        pinMode(SS_PIN, OUTPUT);
}

void rfInit()
{ 
      Serial.println("rfInit Started");
      writeCmd(0x0000);
      writeCmd(0x80E7); //EL,EF,868band,12.0pF
      writeCmd(0x8205); //er,!ebb,ET,ES,EX,!eb,!ew,DC (bug was here)
      writeCmd(0xB800);
      writeCmd(0xA640); //freq select
      writeCmd(0xC647); //4.8kbps
      writeCmd(0x94A0); //VDI,FAST,134kHz,0dBm,-103dBm
      writeCmd(0xC2AC); //AL,!ml,DIG,DQD4
      writeCmd(0xCAF1); //FIFO8,SYNC,!ff,DR (FIFO level = 8)
      writeCmd(0xCED4); //SYNC=2DD4;
      writeCmd(0xC483); //@PWR,NO RSTRIC,!st,!fi,OE,EN
      writeCmd(0x9850); //!mp,90kHz,MAX OUT
      writeCmd(0xCC17); //!OB1,!OB0, LPX,!ddy,DDIT,BW0
      writeCmd(0xE000); //NOT USE
      writeCmd(0xC800); //NOT USE
      writeCmd(0xC040); //1.66MHz,2.2V
      Serial.println("rfInit Ended");
      delay(2000);
      
}

uint8_t writeCmd(uint16_t cmd) 
{
      digitalWrite(SS_PIN, LOW);
      Byte(cmd >> 8) << 8;
      Byte(cmd);
      digitalWrite(SS_PIN, HIGH);
      delay(10);
}

uint8_t Byte(uint8_t out)
{
       SPDR = out;
      // this loop spins 4 usec with a 2 MHz SPI clock
      while (!(SPSR & _BV(SPIF)));
      return SPDR;
}

uint16_t XFERSlow(uint16_t cmd) 
{
      digitalWrite(SS_PIN , LOW);
      uint16_t reply = Byte(cmd >> 8) << 8;
      reply |= Byte(cmd);
      digitalWrite(SS_PIN , HIGH);
      return reply;
}

void rfSend(unsigned char data)
{
        while(nIRQ==0);
        XFERSlow(0xB800 + data);
}

unsigned char rfRecv() 
{
        
        while(1)
        {
        data = XFERSlow(0x0000);
        if ( (data & 0x8000) ) 
           {
               data = XFERSlow(0xB000);
               return (data & 0x00FF);//return data;//
           }
        }
}

void FIFOReset()
{
        writeCmd(0xCA81);
        writeCmd(0xCA83);
}

void loop()
{
       delayMicroseconds(500);
       writeCmd(0x82DD);
       delay(10);

       data = rfRecv();
       Serial.println(data,HEX);
       FIFOReset();
}

This is my code, previously i did mistake while copy pasting here.