LoRa module not working with ESP32-C3's SPI interface

I have wired a LoRa module (SX1278) with the ESP32C3.

The LoRa module uses the SPI interface to communicate with the ESP32C3.

When I connect all the SPI pins to the C3, the sketch seems to stop executing.

If I remove the MISO wire and reboot, the sketch executes, but the LoRa module is not recognized.

I have checked the SPI pin assignments (MOSI, MISO, SCK, SS) and they are all okay.

If I connect the LoRa module to my ESP32-WROOM dev kit, it works perfectly.

Not sure what to do next to diagnose the problem.

Any help would be greatly appreciated.

Regards,
Anand.

The problem is something to do with the way the ESP32C3 reads various pins at startup, with a bare bones SX127X in circuit the ESP32 goes into waiting for USB upload mode.

Fit pullup resistors to the LoRa devices NSS and SCK pins cures the problem for me.

The problem seems to be that the SX1278 pulls down the MISO pin on startup. The MISO / D9 pin is used to put the ESP32C3 into BOOT mode, which is why the ESP32C3 gets stuck!
As @StuartsProject suggests, adding a pullup resistor on NSS solves the issue (NSS = high deactivates the SX1278 module).

I fixed it by reassigning the SPI pins:

#include <SPI.h>

SPIClass spiCustom(HSPI);

...

spiCustom.begin(/* SCK  = */ 6, 
                    /* MISO = */ 7, 
                    /* MOSI = */ 21, 
                    /* SS   = */ 2);
    // Init SPI
    SPI.begin();

1 Like

Dear Anand,
I created a dedicated function for setting up the LoRa SX1278, and it seems to have solved the issue. Additionally, it does not require a pull-up resistor. Below is the code I used for an ESP32-C3 SuperMini as a receiver.

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

#define SS 7     // Pino NSS (CS)
#define RST 3    // Pino de Reset
#define DIO0 1   // Pino de interrupção

/*
ESP 32 C3 / RA-01 SX1278

SCK   -> 4
MISO  -> 5
MOSI  -> 6
SS    -> 7
RST   -> 3
DIO0  -> 1
VCC   -> 3V3
GND   -> GND

*/

long BAND = 433E6; 

void loraSetup(){
  Serial.println("Inicializando LoRa...");

  SPI.begin(4, 5, 6, 7);  // SCK, MISO, MOSI, SS
 
  LoRa.setPins(SS, RST, DIO0);
  
  
  if (!LoRa.begin(BAND)) { // FrequĂȘncia do LoRa (433 MHz ou 915E6 para 915 MHz)
    Serial.println("Erro ao iniciar LoRa!");
    while (1);
  }
  LoRa.receive();
  Serial.println("LoRa iniciado com sucesso!");
}

void setup() {
  Serial.begin(115200);
  delay(500);  // Pequeno atraso para garantir inicialização correta

  loraSetup();
}

void loop() {
  // Verifica se hĂĄ um pacote LoRa disponĂ­vel
  int packetSize = LoRa.parsePacket();
  if (packetSize) { 
    Serial.print("Pacote recebido: ");

    String receivedData = "";
    
    while (LoRa.available()) {
      receivedData += (char)LoRa.read();  // LĂȘ o pacote corretamente como string
    }

    Serial.println(receivedData);
  }

Att.
Marcos Dantas