RFM69HW Bit rate settings config problems

Started by hdphilip, April 20, 2014, 02:40:30 PM

hdphilip

I really enjoy these modules, but here's what I found, and maybe someone can confirm my findings.

I was doing a range test last night, which worked very well, here's a picture of my test setup:


So I was thinking to improve it.

I changed the settings in RFM69.cpp to:

          /* 0x03 */ { REG_BITRATEMSB, RF_BITRATEMSB_1200}, //default:4.8 KBPS
          /* 0x04 */ { REG_BITRATELSB, RF_BITRATELSB_1200},
          /* 0x05 */ { REG_FDEVMSB, RF_FDEVMSB_2000}, //default:5khz, (FDEV + BitRate/2 <= 500Khz)
          /* 0x06 */ { REG_FDEVLSB, RF_FDEVLSB_2000},


but when I did a register dump "r" command in my sketch
#include <RFM69.h>
#include <SPI.h>
#define NODEID      9
#define NETWORKID   100
#define GATEWAYID   1
#define FREQUENCY   RF69_433MHZ //
#define KEY         "thisIsEncryptKey" //has to be same 16 characters
#define LED         9
#define SERIAL_BAUD 115200
#define ACK_TIME    30  // # of ms to wait for an ack

int TRANSMITPERIOD = 3000; //transmit a packet to gateway so often (in ms)
byte sendSize=0;
boolean requestACK = false;

RFM69 radio;
int rxrssi;
unsigned int ncount = 0;
typedef struct {		
  int nodeId;       //store this nodeId
  int node_rssi;    // this node's rssi
  float  temp;      // nodes temp
  unsigned int count;
  
} Payload;
Payload theData;

void setup() {
  Serial.begin(SERIAL_BAUD);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  radio.setHighPower(); //uncomment only for RFM69HW!
  radio.setPowerLevel(25);
  radio.encrypt(null);
  char buff[50];
  sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
  
}

long lastPeriod = -1;
void loop() {
  
  //check for any received packets
  if (radio.receiveDone())
  {
    Serial.print('[');Serial.print(radio.SENDERID, DEC);Serial.print("] ");
    for (byte i = 0; i < radio.DATALEN; i++)
    Serial.print((char)radio.DATA[i]);
     rxrssi = radio.readRSSI();
    Serial.print("   [RX_RSSI:");Serial.print(radio.readRSSI());Serial.print("]");

    if (radio.ACK_REQUESTED)
      {
      radio.sendACK();
        delay(10);
      }
    Blink(LED,5);
  }
 
  int currPeriod = millis()/TRANSMITPERIOD;
  if (currPeriod != lastPeriod)
  {
        
    ncount = ncount + 1;
    //fill in the struct with new values
    theData.nodeId = NODEID;
    theData.node_rssi = rxrssi ;
      byte temperature =  radio.readTemperature(-1); // -1 = user cal factor, adjust for correct ambient
      byte ftemp = 1.8 * temperature + 32; // 9/5=1.8
    
    theData.temp = ftemp; //it's hot!
    theData.count = ncount; 
    
    Serial.print("Sending struct (");
    Serial.print(sizeof(theData));
    Serial.print(" bytes) ... ");
    if (radio.sendWithRetry(GATEWAYID, (const void*)(&theData), sizeof(theData)))
      Serial.print(" ok!");
    else Serial.print(" nothing...");
    Serial.println();
    Blink(LED,3);
   
    lastPeriod=currPeriod;
  }
}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}


I found when i did a register dump, "r" command,
reg 3, 0x2E    it should be    0x68
reg 4, 0x66    it should be    0x2B
reg 5, 0x05    it should be    0x00
reg 6, 0x63    it should be    0x21

so i changed this line in RFM69.cpp to:

/* 0x03 */ { REG_BITRATEMSB, RF_BITRATEMSB_1201}, //default:4.8 KBPS

knowing that "_1201 " wasn't defined, should have crashed the compile, but it didn't.

here's a picture of the carrier output on my SDR spectrum analyzer: capture 3



I added the following lines of code to my sketch:
  radio.setHighPower(); //uncomment only for RFM69HW!
  radio.setPowerLevel(25);
  radio.encrypt(null);
  radio.writeReg(0x03,0x68);
  radio.writeReg(0x04,0x2B);
  radio.writeReg(0x05,0x00);
  radio.writeReg(0x06,0x21);


now my spectrum analyzer output looks like this: capture 2


What clued me into this was when i changed the bitrate settings on my node, the gateway was still receiving packets ok on the lcd screen.

gateway code for my node:
#include <RFM69.h>
#include <SPI.h>


#define NODEID      9
#define NETWORKID   100
#define GATEWAYID   1
#define FREQUENCY   RF69_433MHZ //
#define KEY         "thisIsEncryptKey" //has to be same 16 characters
#define LED         9
#define SERIAL_BAUD 115200
#define ACK_TIME    30  // # of ms to wait for an ack

int TRANSMITPERIOD = 3000; //transmit a packet to gateway so often (in ms)
byte sendSize=0;
boolean requestACK = false;

RFM69 radio;
int rxrssi;
unsigned int ncount = 0;
typedef struct {		
  int nodeId;       //store this nodeId
  int node_rssi;    // this node's rssi
  float  temp;      //temperature maybe?
  unsigned int count;
  
} Payload;
Payload theData;

void setup() {
  Serial.begin(SERIAL_BAUD);
  delay (100);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  radio.setHighPower(); //uncomment only for RFM69HW!
  radio.setPowerLevel(25);
  radio.encrypt(null);
  radio.writeReg(0x03,0x68);
  radio.writeReg(0x04,0x2B);
  radio.writeReg(0x05,0x00);
  radio.writeReg(0x06,0x21);
  char buff[50];
  sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
  
}

long lastPeriod = -1;
void loop() {
  
  if (Serial.available() > 0)
  {
    char input = Serial.read();
    if (input == 'r') //d=dump register values
      radio.readAllRegs();
  } 
  
  //check for any received packets
  if (radio.receiveDone())
  {
    Serial.print('[');Serial.print(radio.SENDERID, DEC);Serial.print("] ");
    for (byte i = 0; i < radio.DATALEN; i++)
    Serial.print((char)radio.DATA[i]);
     rxrssi = radio.readRSSI();
    Serial.print("   [RX_RSSI:");Serial.print(radio.readRSSI());Serial.print("]");

    if (radio.ACK_REQUESTED)
      {
      radio.sendACK();
        delay(10);
      }
    Blink(LED,5);
  }
 
  int currPeriod = millis()/TRANSMITPERIOD;
  if (currPeriod != lastPeriod)
  {
    
    
    ncount = ncount + 1;
    //fill in the struct with new values
    theData.nodeId = NODEID;
    theData.node_rssi = rxrssi ;
      byte temperature =  radio.readTemperature(-1); // -1 = user cal factor, adjust for correct ambient
      byte ftemp = 1.8 * temperature + 32; // 9/5=1.8
    
    theData.temp = ftemp; //it's hot!
    theData.count = ncount; 
    
    Serial.print("Sending struct (");
    Serial.print(sizeof(theData));
    Serial.print(" bytes) ... ");
    if (radio.sendWithRetry(GATEWAYID, (const void*)(&theData), sizeof(theData)))
      Serial.print(" ok!");
    else Serial.print(" nothing...");
    Serial.println();
    Blink(LED,3);
   
    lastPeriod=currPeriod;
  }
}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}


code for my LCD gateway:
#include <RFM69.h>
#include <SPI.h>
#include <LCD5110_Graph.h>

#define NODEID      1
#define NETWORKID   100
#define FREQUENCY   RF69_433MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
#define KEY         "thisIsEncryptKey" //has to be same 16 characters/bytes on all nodes, not more not less!
#define LED         9
#define SERIAL_BAUD 115200
#define ACK_TIME    30  // # of ms to wait for an ack

RFM69 radio;
LCD5110 myGLCD(7,6,5,3,4);
extern uint8_t SmallFont[];
bool promiscuousMode = false; //set to 'true' to sniff all packets on the same network

typedef struct {		
  int      nodeId; //store this nodeId
  int      node_rssi; //uptime in ms
  float    temp;   //temperature maybe?
  unsigned int count;
} Payload;
Payload theData;

void setup() {
  Serial.begin(SERIAL_BAUD);
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  delay(100);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  radio.setHighPower(); //uncomment only for RFM69HW!
  radio.setPowerLevel(25);
  radio.encrypt(null);
  radio.writeReg(0x03,0x68);
  radio.writeReg(0x04,0x2B);
  radio.writeReg(0x05,0x00);
  radio.writeReg(0x06,0x21);
  radio.promiscuous(promiscuousMode);
  char buff[50];
  sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
 
     }

byte ackCount=0;

void loop() {
  
   if (Serial.available() > 0)
  {
    char input = Serial.read();
    if (input == 'r') //d=dump register values
      radio.readAllRegs();
  } 
  
  if (radio.receiveDone())
  {
    myGLCD.clrScr();
    myGLCD.print("SENDERID:", LEFT, 0 );
    myGLCD.print("RX_RSSI:", LEFT, 9 );
    myGLCD.printNumI(radio.readRSSI(), RIGHT, 9);
    myGLCD.printNumI(radio.SENDERID, RIGHT, 0);
    myGLCD.update();
   
	
    if (radio.DATALEN != sizeof(Payload))
       {
      myGLCD.print("Invalid RX", CENTER, 28 ); 
     // Serial.print("Invalid payload received, not matching Payload struct!");
      myGLCD.update();
       }
    else
    {
      theData = *(Payload*)radio.DATA; //assume radio.DATA actually contains our struct and not something else
                                                    // Serial.print(" nodeId=");
                                                    //  Serial.print(theData.nodeId);
      myGLCD.print("Node RSSI", LEFT, 18 );
    //  Serial.print("Node RSSI =");
     // Serial.print(theData.node_rssi);
      myGLCD.printNumI(theData.node_rssi, RIGHT, 19);
                                                     //Serial.print(" temp=");
      myGLCD.print("Node Temp", LEFT, 27 );
                                                     // Serial.print(theData.temp);
      myGLCD.printNumF(theData.temp,1, RIGHT, 27);
      myGLCD.print("Ncount", LEFT, 36 );
      myGLCD.printNumI(theData.count, RIGHT, 36);
      myGLCD.update();
    }
    
    if (radio.ACK_REQUESTED)
    {
      byte theNodeID = radio.SENDERID;
      radio.sendACK();
                                                     //  Serial.print(" - ACK sent.");

      
    }
                                                     // Serial.println();
    Blink(LED,3);
  }
}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}


the data now has a better sound through my speaker


Philip