jgromes / RadioLib

Universal wireless communication library for embedded devices
https://jgromes.github.io/RadioLib/
MIT License
1.47k stars 369 forks source link

[SX1268]: Failure on sending LoRa-Packets #1163

Closed Akira25 closed 1 month ago

Akira25 commented 1 month ago

General symptoms

We are using an SX1268-based radio module by EBYTE (E22 400M33S) on a ESP32-S3 development board (own PCB). When adjusting the PingPong Sketch to our setup, the Module will fail to send LoRa-Packets.

The log states, there would have been transmitted a packet once (which we weren't able to capture on another radio). After that, every other try will result in transmission failure code -2. After some tries, the ESP32 will crash. This happens in arbitrary amount of time.

When enabling the SPI-Debugging, the Programm seems to get stuck on a position before sending the packet.

We would highly appreciate any hints in how we could resolve this issue.

Sketch that is causing the module fail

// include the library
#include <Arduino.h>
#include <RadioLib.h>

#define INITIATING_NODE

// SX1268 has the following connections:
// NSS pin:   10
// DIO0 pin:  5
// RESET pin: 6
// DIO1 pin:  1
SX1268 radio = new Module(10, 5, 6, 1);

// save transmission states between loops
int transmissionState = RADIOLIB_ERR_NONE;

// flag to indicate transmission or reception state
bool transmitFlag = false;

// flag to indicate that a packet was sent or received
volatile bool operationDone = false;

// this function is called when a complete packet
// is transmitted or received by the module
// IMPORTANT: this function MUST be 'void' type
//            and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void)
{
    // we sent or received a packet, set the flag
    operationDone = true;
}

void setup()
{
    Serial.begin(9600);
    delay(10000);

    // initialize SX1268 with default settings
    Serial.print(F("[SX1268] Initializing ... "));
    //   int state = radio.begin();
    int state = radio.begin(430.2);
    if (state == RADIOLIB_ERR_NONE)
    {
        Serial.println(F("success!"));
    }
    else
    {
        Serial.print(F("failed, code "));
        Serial.println(state);
        while (true)
        {
            delay(10);
        }
    }

    // set the function that will be called
    // when new packet is received
    radio.setDio1Action(setFlag);

#if defined(INITIATING_NODE)
    // send the first packet on this node
    Serial.print(F("[SX1268] Sending first packet ... "));
    transmissionState = radio.startTransmit("Hello World!");
    transmitFlag = true;
#else
    // start listening for LoRa packets on this node
    Serial.print(F("[SX1268] Starting to listen ... "));
    state = radio.startReceive();
    if (state == RADIOLIB_ERR_NONE)
    {
        Serial.println(F("success!"));
    }
    else
    {
        Serial.print(F("failed, code "));
        Serial.println(state);
        while (true)
        {
            delay(10);
        }
    }
#endif
}

void loop()
{
    // check if the previous operation finished
    if (operationDone)
    {
        // reset flag
        operationDone = false;

        if (transmitFlag)
        {
            // the previous operation was transmission, listen for response
            // print the result
            if (transmissionState == RADIOLIB_ERR_NONE)
            {
                // packet was successfully sent
                Serial.println(F("transmission finished!"));
            }
            else
            {
                Serial.print(F("failed, code "));
                Serial.println(transmissionState);
            }

            // listen for response
            radio.startReceive();
            transmitFlag = false;
        }
        else
        {
            // the previous operation was reception
            // print data and send another packet
            String str;
            int state = radio.readData(str);

            if (state == RADIOLIB_ERR_NONE)
            {
                // packet was successfully received
                Serial.println(F("[SX1268] Received packet!"));

                // print data of the packet
                Serial.print(F("[SX1268] Data:\t\t"));
                Serial.println(str);

                // print RSSI (Received Signal Strength Indicator)
                Serial.print(F("[SX1268] RSSI:\t\t"));
                Serial.print(radio.getRSSI());
                Serial.println(F(" dBm"));

                // print SNR (Signal-to-Noise Ratio)
                Serial.print(F("[SX1268] SNR:\t\t"));
                Serial.print(radio.getSNR());
                Serial.println(F(" dB"));
            }

            // wait a second before transmitting again
            delay(1000);

            // send another one
            Serial.print(F("[SX1268] Sending another packet ... "));
            transmissionState = radio.startTransmit("Hello World!");
            transmitFlag = true;
        }
    }
}

Hardware setup

Please refer to the pdf-schematic attached below.

Debug mode output

This is debug output with -DRADIOLIB_DEBUG_BASIC=1 and -DRADIOLIB_DEBUG_PROTOCOL=1 enabled.

[SX1262] Initializing ... RLB_DBG: 
RadioLib Info
Version:  "6.6.0.0"
Platform: "ESP32"
Compiled: "Jul 14 2024" "19:14:54"
RLB_DBG: Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:
RLB_DBG: 0000320 53 58 31 32 36 38 20 56 32 46 20 32 46 30 32 00 | SX1268 V2F 2F02.
RLB_DBG: 
RLB_DBG: M      SX126x
success!
[SX1262] Sending first packet ... transmission finished!
[SX1262] Received packet!
[SX1262] Data:
[SX1262] RSSI:          -7.50 dBm
[SX1262] SNR:           -6.00 dB
[SX1262] Sending another packet ... failed, code -2
[SX1262] Received packet!
[SX1262] Data:
[SX1262] RSSI:          0.00 dBm
[SX1262] SNR:           0.00 dB
[SX1262] Sending another packet ... failed, code -2
[SX1262] Received packet!
[SX1262] Data:
[SX1262] RSSI:          0.00 dBm
[SX1262] SNR:           0.00 dB
[SX1262] Sending another packet ... failed, code -2
[SX1262] Received packet!
[SX1262] Data:
[SX1262] RSSI:          0.00 dBm
[SX1262] SNR:           0.00 dB
[SX1262] Sending another packet ... failed, code -2
[SX1262] Received packet!
[SX1262] Data:
[SX1262] RSSI:          0.00 dBm
[SX1262] SNR:           0.00 dB
[SX1262] Sending another packet ... failed, code -2
[SX1262] Received packet!
[SX1262] Data:
[SX1262] RSSI:          0.00 dBm
[SX1262] SNR:           0.00 dB
[SX1262] Sending another packet ... failed, code -2
CORRUPT HEAP: Bad head at 0x3fcec600. Expected 0xabba1234 got 0x80808080

assert failed: multi_heap_free multi_heap_poisoning.c:259 (head != NULL)

Backtrace: 0x403778f2:0x3fceb8f0 0x4037ad95:0x3fceb910 0x40380861:0x3fceb930 0x40380479:0x3fceba60 0x40377ec9:0x3fceba80 0x40380891:0x3fcebaa0 0x42015375:0x3fcebac0 0x42015925:0x3fcebae0 0x42002099:0x3fcebb00 0x420024e7:0x3fcebb30 0x42002f33:0x3fcebb70 0x42003a11:0x3fcebbb0 0x4200494a:0x3fcebbd0 0x42001c6a:0x3fcebc10 0x420066cd:0x3fcebc50

ELF file SHA256: e72f92070ed35629

Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x420270ee
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x4bc
load:0x403c9700,len:0xbd8
load:0x403cc700,len:0x2a0c
entry 0x403c98d0

This one shows all three enabled:

[SX1268] Initializing ... RLB_DBG: 
RadioLib Info
Version:  "6.6.0.0"
Platform: "ESP32"
Compiled: "Jul 14 2024" "20:14:40"
RLB_SPI: CMDW   80
RLB_SPI: SI             0
RLB_SPI: SO     FF      FF
RLB_SPI: CMDW   80
RLB_SPI: SI             0
RLB_SPI: SO     AA      AA
RLB_SPI: CMDW   80
RLB_SPI: SI             0
RLB_SPI: SO     A2      A2
RLB_SPI: CMDR   1D      3       20
RLB_SPI: SI                             0       0       0       0       0       0       0       0       0       0       0       0       0    00       0       0
RLB_SPI: SO     A2      A2      A2      A2      53      58      31      32      36      38      20      56      32      46      20      32   46       30      32      0
RLB_DBG: Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:
RLB_DBG: 0000320 53 58 31 32 36 38 20 56 32 46 20 32 46 30 32 00 | SX1268 V2F 2F02.
RLB_DBG: 
RLB_DBG: M      SX126x
RLB_SPI: CMDW   80
RLB_SPI: SI             0
RLB_SPI: SO     0       0
RLB_SPI: CMDW   80
RLB_SPI: SI             0
RLB_SPI: SO     AA      AA
RLB_SPI: CMDW   80
RLB_SPI: SI             0
RLB_SPI: SO     A2      A2
RLB_SPI: CMDW   80
RLB_SPI: SI             0
RLB_SPI: SO     A2      A2
RLB_SPI: CMDW   80
RLB_SPI: SI             0
RLB_SPI: SO     A2      A2
RLB_SPI: CMDR   17
RLB_SPI: SI             0       0       0
RLB_SPI: SO     A2      A2      0       20
RLB_SPI: CMDW   7
RLB_SPI: SI             0       0
RLB_SPI: SO     A2      A2      A2
RLB_SPI: CMDW   97
RLB_SPI: SI             0       0       1       40
RLB_SPI: SO     A2      A2      A2      A2      A2
RLB_SPI: CMDW   8F
RLB_SPI: SI             0       0
RLB_SPI: SO     A2      A2      A2
RLB_SPI: CMDW   8A
RLB_SPI: SI             1
RLB_SPI: SO     A2      A2
RLB_SPI: CMDW   93
RLB_SPI: SI             20
RLB_SPI: SO     A2      A2
RLB_SPI: CMDW   88
RLB_SPI: SI             3       16      A       0       0       0       0
RLB_SPI: SO     A2      A2      A2      A2      A2      A2      A2      A2
RLB_SPI: CMDW   2
RLB_SPI: SI             43      FF
RLB_SPI: SO     A2      A2      A2
RLB_SPI: CMDW   8
RLB_SPI: SI             0       0       0       0       0       0       0       0
RLB_SPI: SO     A2      A2      A2      A2      A2      A2      A2      A2      A2
RLB_SPI: CMDW   89
RLB_SPI: SI             7F
RLB_SPI: SO     A2      A2
RLB_SPI: CMDR   C0
RLB_SPI: SI             0       0
RLB_SPI: SO     A2      22      22
RLB_SPI: CMDR   11
RLB_SPI: SI             0       0
RLB_SPI: SO     A2      A2      1
RLB_SPI: CMDW   8B
RLB_SPI: SI             9       6       3       0
RLB_SPI: SO     A2      A2      A2      A2      A2
RLB_SPI: CMDR   11
RLB_SPI: SI             0       0
RLB_SPI: SO     B2      B2      1
RLB_SPI: CMDW   D       7       40
RLB_SPI: SI                             14      24
RLB_SPI: SO     C2      C2      C2      C2      C2
RLB_SPI: CMDR   11
RLB_SPI: SI             0       0
RLB_SPI: SO     C2      C2      1
RLB_SPI: CMDR   1D      7       36
RLB_SPI: SI                             0       0
RLB_SPI: SO     C2      C2      C2      C2      D
RLB_SPI: CMDR   C0
RLB_SPI: SI             0       0
RLB_SPI: SO     C2      42      C2
RLB_SPI: CMDW   D       7       36
RLB_SPI: SI                             D
RLB_SPI: SO     C2      C2      C2      C2
RLB_SPI: CMDW   8C
RLB_SPI: SI             0       8       0       FF      1       0
RLB_SPI: SO     C2      C2      C2      C2      C2      C2      C2
RLB_SPI: CMDW   96
RLB_SPI: SI             1
RLB_SPI: SO     A2      A2
RLB_SPI: CMDW   D       8       E7
RLB_SPI: SI                             18
RLB_SPI: SO     A2      A2      A2      A2
RLB_SPI: CMDW   9D
RLB_SPI: SI             1
RLB_SPI: SO     A2      A2
RLB_SPI: CMDR   11
RLB_SPI: SI             0       0
RLB_SPI: SO     A2      A2      1
RLB_SPI: CMDR   1D      7       36
RLB_SPI: SI                             0       0
RLB_SPI: SO     A2      A2      A2      A2      D
RLB_SPI: CMDR   C0
RLB_SPI: SI             0       0
RLB_SPI: SO     A2      22      22
RLB_SPI: CMDW   D       7       36
RLB_SPI: SI                             D
RLB_SPI: SO     A2      A2      A2      A2
RLB_SPI: CMDW   8C
RLB_SPI: SI             0       8       0       FF      1       0
RLB_SPI: SO     A2      A2      A2      A2      A2      A2      A2
RLB_SPI: CMDR   11
RLB_SPI: SI             0       0
RLB_SPI: SO     A2      A2      1
RLB_SPI: CMDR   1D      7       36
RLB_SPI: SI                             0       0
RLB_SPI: SO     A2      A2      A2      A2      D
RLB_SPI: CMDR   C0
RLB_SPI: SI             0       0
RLB_SPI: SO     A2      22      22
RLB_SPI: CMDW   D       7       36
RLB_SPI: SI                             D
RLB_SPI: SO     A2      A2      A2      A2
RLB_SPI: CMDW   8C
RLB_SPI: SI             0       8       0       FF      1       0
RLB_SPI: SO     A2      A2      A2      A2      A2      A2      A2
RLB_SPI: CMDW   98
RLB_SPI: SI             6B      6F
RLB_SPI: SO     A2      A2      A2
RLB_SPI: CMDW   86
RLB_SPI: SI             1A      E3      33      40
RLB_SPI: SO     A2      A2      A2      A2      A2
RLB_SPI: CMDR   11
RLB_SPI: SI             0       0
RLB_SPI: SO     A2      A2      1
RLB_SPI: CMDW   8B
RLB_SPI: SI             9       6       3       0
RLB_SPI: SO     A2      A2      A2      A2      A2
RLB_SPI: CMDR   11
RLB_SPI: SI             0       0
RLB_SPI: SO     A2      A2      1
RLB_SPI: CMDW   8B
RLB_SPI: SI             9       4       3       0
RLB_SPI: SO     A2      A2      A2      A2      A2
RLB_SPI: CMDR   1D      8       E7
RLB_SPI: SI                             0       0
RLB_SPI: SO     A2      A2      A2      A2      18
RLB_SPI: CMDR   C0
RLB_SPI: SI             0       0
RLB_SPI: SO     A2      22      22
RLB_SPI: CMDW   95
RLB_SPI: SI             4       7       0       1
RLB_SPI: SO     A2      A2      A2      A2      A2
RLB_SPI: CMDW   8E
RLB_SPI: SI             A       4
RLB_SPI: SO     A2      A2      A2
RLB_SPI: CMDW   D       8       E7
RLB_SPI: SI                             18
RLB_SPI: SO     A2      A2      A2      A2
RLB_SPI: CMDR   1D      8       D8
RLB_SPI: SI                             0       0
RLB_SPI: SO     A2      A2      A2      A2      E8
RLB_SPI: CMDR   C0
RLB_SPI: SI             0       0
RLB_SPI: SO     B2      B2      32
RLB_SPI: CMDW   D       8       D8
RLB_SPI: SI                             FE
RLB_SPI: SO     C2      C2      C2      C2
success!
[SX1268] Sending first packet ... RLB_SPI: CMDR 11
RLB_SPI: SI             0       0
RLB_SPI: SO     C2      C2      1
RLB_SPI: CMDR   1D      7       36
RLB_SPI: SI                             0       0
RLB_SPI: SO     C2      C2      C2      C2      D
RLB_SPI: CMDR   C0
RLB_SPI: SI             0       0
RLB_SPI: SO     C2      42      C2
RLB_SPI: CMDW   D       7       36
RLB_SPI: SI                             D
RLB_SPI: SO     AA      AA      AA      AA
RLB_SPI: CMDW   8C
RLB_SPI: SI             0       8       0       C       1       0
RLB_SPI: SO     AA      AA      AA      AA      AA      AA      AA

Additional info (please complete):

output.pdf

jgromes commented 1 month ago

From the description and the debug output, the SX1268 is behaving very strange. It seems to be randomly triggering frequency synthesis and Tx modes even before startTransmit gets called, and after that, it gets stuck at command execution failure. The -2 error code can be returned by startTransmit only if the SPI starts returning 0xFF or 0x00.

Comparing your pinout and schematic, you seem to have swapped DIO1 and BUSY pin, so I would start by fixing that.

jgromes commented 1 month ago

Closed due to inactivity.