M5Unit C6L Lora initialisation error
-
Hi, I am using the following program to test Lora on this model. However, i receive this error: [SX1262] Initializing... Failed, code: -2. I assume that i am using the correct ports as given in rthe documentation. Any suggestions ? Thanks ```
#include <RadioLib.h>
//#include <arduino.h>
#include <M5Unified.h>
#include <SPI.h>// SX1262: CS, IRQ, NRST, BUSY
SX1262 radio = new Module(23, 7, RADIOLIB_NC, 19);bool receiveFlag = false; // flag to indicate that a packet was received
// function to be called when a complete packet is received
void setFlag(void) {
receiveFlag = true;
}#define LORA_MISO 22 //38 //19
#define LORA_MOSI 21 //23
#define LORA_SCLK 20 //18void setup() {
// auto cfg = M5.config();
// M5.begin(cfg);Serial.begin(115200);
M5.begin();
delay(1000);Serial.println("And we have started");
if (SPI.begin(LORA_SCLK, LORA_MISO, LORA_MOSI,-1)) // SCK, MISO, MOSI, SS { Serial.println("Fine"); M5.Display.print("SPI is fine"); } else { Serial.println("Not fine"); M5.Display.print("SPI ERROR"); }auto& ioe = M5.getIOExpander(0);
ioe.digitalWrite(7, false);
delay(100);
ioe.digitalWrite(7, true); // re-enable SX_NRST
ioe.digitalWrite(6, true); // enable SX_ANT_SW
ioe.digitalWrite(5, true); // enable SX_LNA_EN// initialize SX1262
Serial.print("\n[SX1262] Initializing... ");
// frequency MHz, bandwidth kHz, spreading factor, coding rate denominator, sync word,
// output power dBm, preamble length, TCXO reference voltage, useRegulatorLDO
int beginState = radio.begin(868.0, 125.0, 12, 5, 0x34, 22, 20, 3.0, true);
if (beginState == RADIOLIB_ERR_NONE) {
Serial.println("Succeeded!");
} else {
Serial.print("Failed, code: ");
Serial.println(beginState);
while (true) { delay(100); }
}// set the function to be called when a new packet is received
radio.setPacketReceivedAction(setFlag);// start listening for LoRa packets
Serial.print("[SX1262] Starting to listen... ");
int receiveState = radio.startReceive();
if (receiveState == RADIOLIB_ERR_NONE) {
Serial.println("Succeeded!");
} else {
Serial.print("Failed, code: ");
Serial.println(receiveState);
while (true) { delay(100); }
}
}void loop() {
if (receiveFlag) { // check if a new packet is received
receiveFlag = false; // reset the flagString str; // read the received data as an Arduino String int readState = radio.readData(str); if (readState == RADIOLIB_ERR_NONE) { // packet was received successfully Serial.println("\n[SX1262] Received packet!"); Serial.print("[SX1262] Data: "); Serial.println(str); Serial.print("[SX1262] RSSI: "); Serial.print(radio.getRSSI()); // Received Signal Strength Indicator Serial.println(" dBm"); Serial.print("[SX1262] SNR: "); Serial.print(radio.getSNR()); // Signal-to-Noise Ratio Serial.println(" dB"); Serial.print("[SX1262] Frequency error: "); Serial.print(radio.getFrequencyError()); Serial.println(" Hz"); } else if (readState == RADIOLIB_ERR_CRC_MISMATCH) { // packet was received but malformed Serial.println("CRC error!"); } else { // some other error occurred Serial.print("Failed, code: "); Serial.println(readState); }}
} -
I receive this debug error message : GPIO pre-transfer timeout, is it connected? which is located in in the function
int16_t Module::SPItransferStream(const uint8_t* cmd, uint8_t cmdLen, bool write, const uint8_t* dataOut, uint8_t* dataIn, size_t numBytes, bool waitForGpio)
in the file Module.cppI am using the example in this M5Stack link : https://docs.m5stack.com/en/arduino/unit_c6l/lora
Help is appreciated.
Regards -
Hello @HappyUser
hmm, both examples (w/o any modifications) work for me ok - no error.
Question: why are you using
SPI.begin()in your code? I don't see that in the linked example.Thanks
Felix -
@felmue Thank you. I tried this extra spi call because I assumed that something is wrong with SPI. Leaving out this call does not solve the problem either. Bot M5Unified and and radiolib are updated. M5Stack board manager is also updated. This is very weird. Not sure how to process further.
-
@HappyUser
These are the libs that I am using. Could it be that somehow there is a difference with your config?
Multiple libraries were found for "SPI.h"
Used: /Users/..../Library/Arduino15/packages/m5stack/hardware/esp32/3.2.5/libraries/SPI
Not used: /Users/....../Library/Arduino15/packages/m5stack/hardware/esp32/3.2.5/libraries/_DontUse_SPI
Using library RadioLib at version 7.3.0 in folder: /Users/....../Documents/Arduino/libraries/RadioLib
Using library SPI at version 3.2.1 in folder: /Users....../Library/Arduino15/packages/m5stack/hardware/esp32/3.2.5/libraries/SPI
Using library M5Unified at version 0.2.13 in folder: /Users/....../Documents/Arduino/libraries/M5Unified
Using library M5GFX at version 0.2.15 in folder: /Users.../Documents/Arduino/libraries/M5GFX
/Users/....../Library/Arduino15/packages/m5stack/tools/esp-rv32/2411/bin/riscv32-esp-elf-size -A /Users/..../Library/Caches/arduino/sketches/E220783385D73AB555D51793968410FB/LoRa_Test.ino.elf
Sketch uses 434305 bytes (33%) of program storage space. Maximum is 1310720 bytes.
Global variables use 17508 bytes (5%) of dynamic memory, leaving 310172 bytes for local variables. Maximum is 327680 bytes.
esptool.py v4.8.1
Serial port /dev/cu.usbmodem1101:
Connecting...
Connected to ESP32-C6 on /dev/cu.usbmodem1101:
Chip type: ESP32-C6 (QFN40) (revision v0.2)
Features: Wi-Fi 6, BT 5 (LE), IEEE802.15.4, Single Core + LP Core, 160MHz
Crystal frequency: 40MHz
USB mode: USB-Serial/JTAG
MAC: 58:8c:81:ff:fe:50:00:08
BASE MAC: 58:8c:81:50:00:08
MAC_EXT: ff:fe