LoRa Module fails on first time init?

Hi, I am trying to establish communication between an arduino Micro and a Zero compatible one using a couple of LoRa Ra-02 modules.

The following is taken from the library examples :

void setup() {
  SerialUSB.begin(9600);
  while (!SerialUSB);

  SerialUSB.println("LoRa Receiver");
  LoRa.setSPIFrequency(4E6);
  LoRa.setPins(csPin, resetPin, irqPin);// set CS, reset, IRQ pin
  delay(1000);
  while (!LoRa.begin(433E6)) {
    SerialUSB.println("Starting LoRa failed!");
    delay(500);
  }

SerialUSB.println("Starting LoRa success!");
  
}



And the output:


LoRa Receiver
Starting LoRa failed!
Starting LoRa success!

In the case of Zero, LoRa module refused to initialise. I then added the while loop shown above and the module initialises successfully after the second attempt.
Please note that this happens on every occasion with the Arduino zero, while in the case of the Arduino micro, there is no need for the while loop and the module initialises on the first attempt.

Any ideas? Is this somehow CPU frequency related ?

Hi

  • post full code with pin definitions
  • how are things powered?

Powered via 3.3V (local) regulator.

#include <SPI.h>
#include <LoRa.h>

int counter = 0;

const int csPin = 6;          // LoRa radio chip select
const int resetPin = 4;       // LoRa radio reset
const int irqPin = 5;         // change for your board; must be a hardware interrupt pin



void setup() {
  SerialUSB.begin(9600);
  while (!SerialUSB);

  SerialUSB.println("LoRa Receiver");
  LoRa.setSPIFrequency(4E6);
  LoRa.setPins(csPin, resetPin, irqPin);// set CS, reset, IRQ pin
  delay(1000);
  while (!LoRa.begin(433E6)) {
    SerialUSB.println("Starting LoRa failed!");
    delay(500);
  }

SerialUSB.println("Starting LoRa success!");
  
}

void loop() {
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    SerialUSB.print("Received packet '");

    // read packet
    while (LoRa.available()) {
      SerialUSB.print((char)LoRa.read());
    }

    // print RSSI of packet
    SerialUSB.print("' with RSSI ");
    SerialUSB.println(LoRa.packetRssi());
  }
}


type or paste code here

may be try to set your custom cs pin as an HIGH output first

void setup() {
  pinMode(csPin, OUTPUT);
  digitalWrite(csPin, HIGH); 
  SerialUSB.begin(9600);
  while (!SerialUSB);
  ...

Nope... that didnt work.
In fact after seting CS hi to start with, the module refuses to initialise:

LoRa Receiver
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!
Starting LoRa failed!

you might also need to set the default hardware CS pin to an OUTPUT (special pin for each board - D8 on the Micro I think and not sure on the zero)

you might also need to set the default hardware CS pin to an OUTPUT (special pin for each board - D8 on the Micro I think and not sure on the zero)

Tried that too. Made no difference.
Micro works fine anyway. The issue is only with zero

which pin did you use for CS? D10 ?

Yes for both arduinos

I don't think it's the SS pin for the arduino Micro

I don't think it's the SS pin for the arduino Micro

What you mean?
Didnt understand

if you used D10 for both, I don't think it's the right pin number for the arduino Micro

can you try connecting your module with the default hardware SS pin rather than your custom pin?

Sorry ..misunderstanding! As per the code posted above CS is pin 6

OK - so my question is

Could you try using the built in SS pin rather than pin 6

Try SS pin on Zero instead of pin 6?
Not possible since everything is on a custom PCB.
Why would it make a difference though?

Just an idea to explore - not sure who is in charge of initializing the SPI library for your module

(I assume you have the right amount of current available for the module)

EDIT: lora.begin() will call begin for spi and the CS pin is set up correctly too

  // setup pins
  pinMode(_ss, OUTPUT);
  // set SS high
  digitalWrite(_ss, HIGH);

yes, current is not an issue.

Could it be that somehow this is speed / cpu architecture related , ie avr vs arm ?

You force the SPI bus speed at 4MHz

LoRa.setSPIFrequency(4E6);

it should be fine as the default for the Lora libray is 8Mhz.

You could try to slow it down even more, all the way to 125kHz

some docs say

There is also a dedicated CS pin that you can use (which must, at least, be set to an output in order for the SPI hardware to function), but note that you can use any other available output pin(s) for CS to your peripheral device(s) as well.

so I was suggesting to put the hardware SS pin as output yourself before configuring SPI

ok...will try that too...