Community
OpenEnergyMonitor

Community

RFM69CW with ATMEGA2560 RFM69CW no data sending


(gosch) #1

Hi

I’m heavely struggeling adapting the RFM69CW library from Jeelib on a ATmega2560 to work together with a Standard emonPI on raspberry PI3. The base of the HW and SW design is emontxV3.4.

I have an custom made ATmega2560 board with an RFM69CW 868MHz (connected over and voltage Level converter 5V/3.3V)

So the problem is that the ATMega is not sending any data over the SPI bus to the module. The Pins SS=Pin53, MOSI=Pin51, MISO=Pin50, SCK=Pin52 and SS=Pin2 are not changing. I’m using Arduino IDE 1.6.12.
I set up the correct ATMega2560 CPU in the IDE.

I’m using the commands from the library jeelibmaster:

#define RF69_COMPAT 1
#include <JeeLib.h
#define RF_freq RF12_868MHZ
rf12_initialize(nodeID, RF_freq, networkGroup);
rf12_sendNow(0, &emontx, sizeof emontx);

Here is my test code:

#define RF69_COMPAT 1        // using RFM69CW
#include <JeeLib.h>          // https://github.com/jcw/jeelib
ISR(WDT_vect) { Sleepy::watchdogEvent(); }  
const byte LEDpin=                 41;      // Test LED Pin of ATmega2560 custom plattform
//-------------------------------------------------------------------------------------------------------------------------------------------

//-----------------------RFM69CW SETTINGS----------------------------------------------------------------------------------------------------
#define RF_freq RF12_868MHZ   // Frequency of RF69CW module can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. You should use the one matching the module you have.
byte nodeID = 8;              // node ID
const int networkGroup = 210;

typedef struct { 
  int power1, power2, power3, power4, Vrms, temp; 
} PayloadTX;     // create structure - a neat way of packaging data for RF comms
PayloadTX emontx;

//-------------------------------------------------------------------------------------------------------------------------------------------


void setup()
{ 
  pinMode(LEDpin, OUTPUT);    
  digitalWrite(LEDpin,HIGH); 
  rf69_initialize(nodeID, RF_freq, networkGroup);    // initialize RFM69CW
  digitalWrite(LEDpin,HIGH);  // just for test
 /*
  for (int i=10; i>=0; i--)     // Send RF test sequence (for factory testing)
  {
    emontx.power1=i; 
    rf12_sendNow(0, &emontx, sizeof emontx);
    delay(100);
  }
*/  
 // rf12_sendWait(2);
  digitalWrite(LEDpin,0);                        
} //end SETUP

void loop()
{
  emontx.power1=5;  // test value
// rf12_sleep(RF12_WAKEUP);   // not used, HW has enough power and is always powered by source
   rf12_sendNow(0, &emontx, sizeof emontx);   // *SEND RF DATA*
// rf12_sendWait(2);  
  delay(2000);  
}

The rest of the HW works fine. I’m using a digital oscilloscope to see the Signals. I can see the signals when I’m programing the ATmega over USBtiny, but not when the HW runs by it self.

The ATmega2560 can write and read to the device. I tested this by sending and reading singe data to the RFM69CW.

I checked SPI the signals from ATmega2560 so that SS=Pin53, MOSI=Pin51, MISO=Pin50, SCK=Pin52 and SS=Pin2. The signals translations from the ATMega 5V to 3.3V RFM69CW are fine. So clear 5V signals resp. clear 3.3V signals ( 0 -> 0V and 1 -> VCC, no Offset).

See here the schematic of the RFM69CW Connection to the ATmega2560:

Many thanks for your help!


(gosch) #2

I forgot to say that the ATMega is running on 16MHz external.
I tried to add the statement: SPI.setClockDivider(SPI_CLOCK_DIV128) but there is no SPI instance there.


(Bryon van Prooyen) #3

Hi. I am having exactly the same problem. I have added jumpers between an emonTX Shield to an Arduino Mega 2560, swapping I2C pins to 50-53 and SS on 2 as done in the previous post.

If I compile with RF69_COMPAT 1, there is no communication except for some erratic data on pin 53. If I recompile with RF69_COMPAT 0, all the I2C lines spark into life.

Is there an issue with the JeeLib RFM69 library (I have downloaded the latest (though no mention of V12 anywhere that I can find…), or just something else that needs to be modified to make this work on a Mega 2560? I have spent the last couple of days pulling my hair out over this one! Data lines confirmed with a Salae Logic probe.

Any help would be greatly appreciated. Thanks!


(Bryon van Prooyen) #4

I had some limited success with a sketch I found uploaded by Robert Wall https://community.openenergymonitor.org/t/rfm69cw-to-code/825/6
in Klause.zip. The code successfully initialized the RFM69 and sent formatted packets to EmonCMS.
Can anyone give me a hint as to why I cannot get this to work using the Jeelibs library? Is it possible that the code is not compatible with an Arduino Mega 2560? If so, is there anywhere I should try to modify the library files to make this work? Thanks!


(Robert Wall) #5

See RFM69CW to code
also
http://jeelabs.net/boards/7/topics/3849
That might offer some clues.


(Bryon van Prooyen) #7

Thanks mate, will read into it.


(Bryon van Prooyen) #8

Just a quick update. I received an Arduino Uno and installed the EmonTx Shield on it. Worked first go. So it seems the Jeelib RFM69 library is fine, but will need someone more experienced than me to get it to work properly on a Mega 2560!

So I think the trick is to stick with ‘approved’ hardware!