STM32L051C8 gets stuck at LoRa.endPacket() using RA-02 module
I am unable to send or receive through a STM32L051C8T7 board.. No failure in setup, but it freezes on LoRa.endPacket();, hSerial.print("4"); is never called in the code below. It also freezes when LoRa.read() is called to receive data. Is STM32L051C8 not supported? Or am I doing something wrong.
`#include <Arduino.h> #include <SPI.h> #include <LoRa.h> #include <HardwareSerial.h>
HardwareSerial hSerial(PA10, PA9);
#define LORA_SCK PA5 #define LORA_MISO PA6 #define LORA_MOSI PA7 #define LORA_CS PA4 #define LORA_RST PB11
int counter = 0;
void setup() { delay(500); hSerial.begin(115200); // while (!hSerial); delay(500);
hSerial.println("LoRa Receiver");
delay(500);
LoRa.setPins(LORA_CS, LORA_RST); SPI.setMISO(LORA_MISO); SPI.setMOSI(LORA_MOSI); SPI.setSCLK(LORA_SCK); SPI.setSSEL(LORA_CS);
SPI.begin();
if (!LoRa.begin(433E6)) { hSerial.println("Starting LoRa failed!"); while (1) ; }
delay(500); hSerial.println("LoRa Receiver Setup Done"); delay(500); }
void loop() {
hSerial.print("Sending packet: "); hSerial.println(counter);
// send packet LoRa.beginPacket(); hSerial.print("1"); LoRa.print("hello "); hSerial.print("2"); LoRa.print(counter); hSerial.print("3"); LoRa.endPacket(); hSerial.print("4");
counter++;
delay(1000);
} `
I had a similar problem with an ESP32 module and it turned out to be a grounding issue. Make sure ALL ground pins on your STM32 board are attached to ground as well as ALL ground pins on your LoRa module.
agozie did you solve your issue?
I am having the same issue using a ATTiny and a SX1278 module on a custom PCB. It worked well for about a year and then endPacked() stopped to terminate. (readRegister(REG_IRQ_FLAGS) in LoRa.cpp will always return 0) It looks like other libraries have the same issue [1][2] and solved it by implementing a TX_timeout that resets the LoRa module. I have not tried adapting the library yet. Also [2] indicates that this is related to a routing issue in the SPI line or PCB design in general. That fits into the picture of my situation, since everything worked originally, but stopped working after the setup was in use over an extended period of time and slightly degraded. However, they did not mention their sources and I did not find any reasoning of what exactly causes the SPI issue. My SPI and power supply / GND lines still seem to be in tact physically and their resistances are neglectable. However, impedances might have changed slightly. Reducing the SPI frequency to 1MHz or 100kHz using setSPIFrequency() didn't help. A SW solution would be ideal, so I am curious what your progress was.
[1] https://forum.arduino.cc/t/lora-hang-in-endpacket-and-its-probable-reason/552297/6 [2] https://github.com/Lora-net/LoRaMac-node/commit/233214fe19f03c3d608d66367eedf06e3f47c03d
Hello @aster1cs. The endPacket() method causes the module to perform the actual transmission which can draw a lot of power depending on your TX power setting. I had to add a 1uF cap very near the power supply pin to make my custom PCB work at highest power. You can try reducing the TX power and see if that helps. It would certainly be an indicator as to a PS issue.