🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    M5Unit C6L Lora initialisation error

    Units
    1
    1
    14
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      HappyUser
      last edited by

      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 //18

      void 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 flag

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

      }
      }

      1 Reply Last reply Reply Quote 0
      • First post
        Last post