thinkpeace
Active member
I've been working on using the HopeRF RFM69 low power RF tranceiver with the Teensy 3.1 and a WizNet820io Ethernet module. The conflict occurs because the RFM69 and the Ethernet both use the SPI port to communicate with the Teensy. The arduino library does not provide support for sharing the SPI port with multiple devices. I attempted to work around this limitation with two attempts.
The closest I've got this to working is by using the Low Power Lab RFM69 library. I would disable interrupts and put the radio to sleep before using the Ethernet module to send data to a server every 10 seconds. Most of the time is spent polling the RFM69 for available packets. This works, but the Teensy would hang up every ten minutes or so. The watchdog timer will reset the Teensy when this happens, but messages are lost in the process.
My next try was to use the RadioHead library which also provides a software SPI mode. I figured that if no interrupts were used, then everything would happen in the loop() function, and the conflicts would be avoided.
The software SPI mode works fine on the Teeensy without using the Ethernet library. But, when I add Ethernet.begin(mac); to my sketch, the RadioHead library hangs up on the first call to radiohead.available(); If I call Ethernet.begin(mac) before calling radiohead.init(), init fails.
The RFM module is connected as follows:
Teensy..RFM
0.......IRQ
8.......SS
11......MOSI
12......MISO
13......SCK
The Ethernet is connected as follows
Teensy..Ethernet
9.......RESET
10......SS
11......MOSI
12......MISO
13......SCK
This is the setup() and loop() code for the radio. This code works, until I add Ethernet.begin() to the setup() function.
The closest I've got this to working is by using the Low Power Lab RFM69 library. I would disable interrupts and put the radio to sleep before using the Ethernet module to send data to a server every 10 seconds. Most of the time is spent polling the RFM69 for available packets. This works, but the Teensy would hang up every ten minutes or so. The watchdog timer will reset the Teensy when this happens, but messages are lost in the process.
My next try was to use the RadioHead library which also provides a software SPI mode. I figured that if no interrupts were used, then everything would happen in the loop() function, and the conflicts would be avoided.
The software SPI mode works fine on the Teeensy without using the Ethernet library. But, when I add Ethernet.begin(mac); to my sketch, the RadioHead library hangs up on the first call to radiohead.available(); If I call Ethernet.begin(mac) before calling radiohead.init(), init fails.
The RFM module is connected as follows:
Teensy..RFM
0.......IRQ
8.......SS
11......MOSI
12......MISO
13......SCK
The Ethernet is connected as follows
Teensy..Ethernet
9.......RESET
10......SS
11......MOSI
12......MISO
13......SCK
This is the setup() and loop() code for the radio. This code works, until I add Ethernet.begin() to the setup() function.
Code:
#define USE_RADIOHEAD
RFServer rfServer; // Singleton class
#define VERBOSE_TRACE
#define ENCRYPTKEY "kd8w3a0mz8q01gbh" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HW
// Singleton instance of the radio driver
#ifdef USE_RADIOHEAD
RHSoftwareSPI spi;
RH_RF69 radiodriver(8,0,spi);
uint8_t encryptionKey[] = ENCRYPTKEY;
// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram radiohead(radiodriver, 1);
#else
RFM69 radio(8,0,true);
#endif
extern bool needToSendMessagesToServer;
// Call this function in setup() to initialize the RFM12B interface
void RFServer::setup( int cfg_node, int cfg_group, int cfg_freq, int cfg_spi_ss )
{
pinMode( 0, INPUT );
node = cfg_node;
group = cfg_group;
Serial.print( "radio.init(" ); Serial.print( cfg_freq ); Serial.print( ", " );
Serial.print( node ); Serial.print( ", " ); Serial.print( group ); Serial.println( " );" );
delay(100);
#ifdef USE_RADIOHEAD
if (!radiohead.init())
Serial.println("Radio init() failed");
else
Serial.println("Radiohead init successful" );
// Defaults after init are 434.0MHz, modulation FSK_Rb2Fd5, +13dbM
// No encryption
radiodriver.setEncryptionKey(encryptionKey);
if (!radiodriver.setFrequency(433.0))
Serial.println("setFrequency failed");
if (!radiodriver.setModemConfig(RH_RF69::GFSK_Rb250Fd250))
Serial.println("setModemConfig failed");
#else
radio.initialize(cfg_freq, node, group );
#ifdef IS_RFM69HW
radio.setHighPower(); //uncomment only for RFM69HW!
#endif
radio.encrypt(ENCRYPTKEY);
radio.setPowerLevel(10);
#endif
}
// Call this function in the main loop() to reive any pending messages and process them
void RFServer::loop()
{
int sender;
Serial.println( "loop" );
delay(100);
#ifdef USE_RADIOHEAD
while(radiohead.available())
{
Serial.print( "." );
delay(100);
radio.DATALEN = MAX_DATA_LEN;
if (radiohead.recvfromAck(radio.DATA, &radio.DATALEN, &radio.SENDERID))
#else
while(radio.receiveDone())
{
Serial.print( "-" );
delay(100);
#endif
{
ProcessMessage();
}
}
Serial.println("$");
delay(100);
updateConnectedStatus();
}