RadioHead library not working with LoRa32u4 (RFM95) board

Hello,

I have several BSFrance LoRa32u4 II v1.2 boards running with the lmic library and a local lorawan Gateway.

I also like to experiment with low leve communication between nodes. For this I use the RadioHead library(v 1.98).

As a start I use the rf95_client and rf95_server examples that come with the library. For some reason the server does not receive any data.

The rf95.init() functions at the client and server do not return an error.
Sending by the rf95_client seems to work, on my Lorawan Gateway I see the “Hallo World” message.

The rf95_server does not receive any data (rf95.available false).
The strange thing is that everything worked fine for the first couple of hours, but then it stopped working. I spend days to find the course using several boards, but no success.

Does somebody has an idea?, I’m thinking about an Interrupt issue.
Maybe somebody who also uses this board with this library can share a working example.

Thanks,
Tony

rf95_client (sending seems to work)

#include <SPI.h>
#include <RH_RF95.h>

#define RF95_FREQ 868.0

#define RFM95_CS 8    //chip select
#define RFM95_RST 4   //reset
#define RFM95_INT 7   //interrupt //1,3, 4 blijft hangen in waitPacketSent, 7 ok

RH_RF95 rf95(RFM95_CS, RFM95_INT);

void setup() 
{
  while (!Serial);
  Serial.begin(9600);
  delay(100); 

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    while (1);
  }
  Serial.println("LoRa radio init OK!");

  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
  //rf95.setTxPower(23);  //default 13
  delay(5000);
  rf95.printRegisters();
}

void loop()
{
  //Serial.println("Sending to rf95_server");
  // Send a message to rf95_server
  uint8_t data[] = "Hello World!";
  rf95.send(data, sizeof(data));
  
  if(rf95.waitPacketSent())
  {
    Serial.println("Sending....."); 
  }
  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  if (rf95.waitAvailableTimeout(3000))
  { 
    // Should be a reply message for us now   
    if (rf95.recv(buf, &len))
   {
      Serial.print("got reply: ");
      Serial.println((char*)buf);
//      Serial.print("RSSI: ");
//      Serial.println(rf95.lastRssi(), DEC);    
    }
    else
    {
      Serial.println("recv failed");
    }
  }
  else
  {
    Serial.println("No reply, is rf95_server running?");
  }
  delay(400);
}

rf95_server (does not receive anything)

#include <SPI.h>
#include <RH_RF95.h>


#define RF95_FREQ 868.0

#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 7

RH_RF95 rf95(RFM95_CS, RFM95_INT);

void setup() 
{
  while (!Serial);
  Serial.begin(9600);
  delay(100); 

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    while (1);
  }
  Serial.println("LoRa radio init OK!");

  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
  //rf95.setTxPower(23);  //default 13
  delay(5000);
  rf95.printRegisters();
}

void loop()
{
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  if (rf95.available())
  {
    // Should be a message for us now   

    if (rf95.recv(buf, &len))
    {
//      RH_RF95::printBuffer("request: ", buf, len);
      Serial.print("got request: ");
      Serial.println((char*)buf);
//      Serial.print("RSSI: ");
//      Serial.println(rf95.lastRssi(), DEC);
      
      // Send a reply
      uint8_t data[] = "And hello back to you";
      rf95.send(data, sizeof(data));
      rf95.waitPacketSent();
      Serial.println("Sent a reply");
    }
    else
    {
      Serial.println("recv failed");
    }
  }
}

The code you posted works, when the LoRa devices are connected correctly.

I forgot to add; that was using an ATmega328P.

Thanks, for you reply,
good te hear.

The BSFrance Lora32u4 II board has a ATmega328P and a rfm95 on board.
There are some PIN differences in the several versions, I have v 1.2

The only thing I can configure for the library is:
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 7

rfm95 - Board

RST - D4(RST)
NSS - D8 (CS)
MOSI - D16 (MOSI)
MISO - D14 (MISO)
SCK - D15 (SCK)
DIO0 - D7 (IRQ)
DIO1 - DIO1 (not used)
DIO2 - DIO2 (not used)
DIO3 - DIO3 (not used)
DIO5 - NC
DIO4 - NC

I will check how the SPI interface is used in the library.
Thanks again.

In general, when things work for a long time, as in hours, and then stop working with no hardware or software changes, and a reset does not cure it, something is broken in the hardware.

I was triggered by the response. (wrong connection)

I think I found the problem.

The Interrupt and Chipselect can be set through RH_RF95 rf95(RFM95_CS, RFM95_INT), however
the SCK, MOSI and MISO pins used in the library do not match the Lora32u4 board.

I changed the setPins call in RHSoftwareSPI.ccp

RHSoftwareSPI.ccp
void RHSoftwareSPI::setPins(uint8_t miso, uint8_t mosi, uint8_t sck)
....................

#ifdef LORA32U4
  setPins(14, 16, 15);
#else
  setPins(12, 11, 13);  //original setting
#endif

Why would you want to use soft SPI ?

Does the board you bought not use hardware SPI ?

With hardware SPI you dont need to define the SPI pins, its automatic.

The Lora32U4 board has hardware SPI and if possible I want to use this.
In the RH_RF95 there is an explanation how to connect an Arduino to the RFM95. (seel below).

The board has an ATmega and RFM95, not connected as explained in in RH_RF95.
With the constructor I can set the CS and interrupt but I see no way to tell the library which ports are SCK, MOSI and MISO.
As I understand from the last response it is automatically detected which ports must be used for the SPI interface.
If this is the case, than I have still no idea why it is not working. (I had no time yet to test the software SPI).

From RH_RF95.h
/// If you have a bare RFM95/96/97/98 that you want to connect to an Arduino, you
/// might use these connections (untested): CAUTION: you must use a 3.3V type
/// Arduino, otherwise you will also need voltage level shifters between the
/// Arduino and the RFM95. CAUTION, you must also ensure you connect an
/// antenna.

/// antenna.
///
/// \code
/// Arduino RFM95/96/97/98
/// GND----------GND (ground in)
/// 3V3----------3.3V (3.3V in)
/// interrupt 0 pin D2-----------DIO0 (interrupt request out)
/// SS pin D10----------NSS (CS chip select in)
/// SCK pin D13----------SCK (SPI clock in)
/// MOSI pin D11----------MOSI (SPI Data in)
/// MISO pin D12----------MISO (SPI Data out)
/// \endcode
/// With these connections, you can then use the default constructor RH_RF95().
/// You can override the default settings for the SS pin and the interrupt

Any response welcome,
Thanks, Tony