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).
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);
}