ESP8266 SPI boot error

A LoRa module is connected to ESP8266 via SPI (not the flash SPI but: MOSI GPIO13, MISO GPIO12, SCK GPIO14) to an `ESP8266.
Scenario 1: When the ESP8266 is started up without the LoRa module on the SPI bus, then initialisation occurs, waiting for the LoRa module to be plugged in. When that is done, the program is further initialised and data reception occurs as normal.
Scenario 2: However, when startup occrus with the LoRa module in place, then even setup is not performed.

A logic analyser shows proper data transfers in the first scenario.
In scenario 2 errors are shown: "Settings mismatch" and "The initial (idle) state of the CLK line does not match the settings".

Power is not the issue: a 3.3V 1A line powers the LoRa module separately, grounds connected.

EDIT: led on pin 14 interferes with SPI SCK. Moving to LED_BUILTIN (GPIO16) does not solve the issue.

EDIT #2: solved. ESP8266 GPIO0 is used for interrupt attach. However GPIO0 also is used to set the ESP in flash mode. Solution: connect LoRa interrupt output to the only remaining useable ESP8266 GPIO pin which is GPIO16.

See attachment: logic analyser output.

Code:

#include <SPI.h>
#include <LoRa.h>
#define led 14
const int csPin = 15;         // LoRa chip select   GPIO15(D8)->SS or chip select
const int resetPin = 2;       // LoRa reset         GPIO2(D4)->RESET OF Lora module
const int DIO0Pin = 0;         // LoRa IRQ (Callback)      GPIO0 (D3) -> IRQ or "Callback"
volatile bool doRead = false; // Flag set by callback to perform read process hand interrupt main loop

void setup() {
  SPI.begin();
  LoRa.setPins(csPin, resetPin, DIO0Pin); // set CS, reset, IRQ pin. Override the default CS, reset, and IRQ pins (optional)
  Serial.begin(9600);
  delay(1000);
  while (!Serial);
  Serial.println("LoRa Receiver IRQ");
  Serial.flush();
  while (!LoRa.begin(868E6)) {
    Serial.print(".");
    delay(500);
  }

  // LoRa.setSyncWord(0xF3); // syncword default or private: 0x12; LoRaWAN/TTN: 0x34
  // LoRa.setTxPower(20);

  Serial.println("LoRa Initializing OK!");
  // trigger interrupt on pin 2 (INT0) (Arduino) or GPIO0 (D3) on ESP8266 (NodeMCU) from DIO0
  // register the receive callback
  LoRa.onReceive(onReceive);
  // put the radio into receive mode
  LoRa.receive();
}

void loop() {

  while (!doRead) {
    digitalWrite(led, HIGH);
    delay(1550);
    digitalWrite(led, LOW);
    delay(1550);
    // wait for a second
  }

  // yield();
}

void onReceive(int packetSize) {

  if (packetSize == 0) {
    return;
  }
  doRead = true;
  //  incomingPacketSize = packetSize;
  // Read 2 bytes into a
  uint16_t a;
  char LoRaStringA[12];
  for (int i = 0; i < sizeof(a); i++) {
    *(((uint8_t*)&a) + i) = (uint8_t)LoRa.read();
    //     LoRaString = a+(char)LoRa.read();
    // itoa(a, LoRaStringA, 12);
  }
  char a1 = a;

  // Read 2 bytes into b
  uint16_t b;
  char LoRaStringB[12];
  for (int i = 0; i < sizeof(a); i++) {
    *(((uint8_t*)&b) + i) = (uint8_t)LoRa.read();
    //     LoRaString = b+(char)LoRa.read();
    // itoa(b, LoRaStringB, 12);
  }
  char b1 = b;

  // Read 2 bytes into counter
  uint16_t counter;
  for (int i = 0; i < sizeof(counter); i++) {
    *(((uint8_t*)&counter) + i) = (uint8_t)LoRa.read();
  }
  // Read 4 bytes into x
  float x;
  for (int i = 0; i < sizeof(x); i++) {
    *(((uint8_t*)&x) + i) = (uint8_t)LoRa.read();
  }
  // Read 4 bytes into z
  float z;
  for (int i = 0; i < sizeof(z); i++) {
    *(((uint8_t*)&z) + i) = (uint8_t)LoRa.read();
  }
  // Display read values
  Serial.print("Received: ");
  Serial.print("a = ");
  Serial.print(a1);
  Serial.print("  b = ");
  Serial.print(b1);

  Serial.print("  counter = ");
  Serial.print(counter);

  Serial.print("  x = ");
  Serial.print(x);
  Serial.print("  z = ");
  Serial.print(z);
  Serial.print("  with RSSI ");
  Serial.println(LoRa.packetRssi());
  Serial.flush();
  doRead = false;    // Set flag back to false so next read will happen only after next ISR event
}

SPI LoRa ESP8266 errors.pdf (216.2 KB)

  • List item