Rst cause:2, boot mode:(3,6)

I have an ESP8266 board with the code below:

#include <ESP8266WiFi.h>
#include <Wire.h>
#include <DS1307RTC.h>
#include <SD.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define WIFI_SSID "***************"
#define WIFI_PASSWORD "************"

const int voltageSensorPin = A0;
const int currentSensorPin = A0;

File dataFile;

OneWire oneWire(4);
DallasTemperature sensors;

void setup() {
  Serial.begin(115200);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  while (WiFi.status() != WL_CONNECTED) {
    // Aguarde a conexão WiFi
  }

  setSyncProvider(RTC.get);

  if (timeStatus() != timeSet) {
    setTime(0, 0, 0, 1, 1, 2000);
  }

  if (!SD.begin(4)) {
    while (1);
  }

  sensors.setOneWire(&oneWire);
  sensors.begin();
  sensors.requestTemperatures();
}

void loop() {
  float voltage = analogRead(voltageSensorPin) * (5.0 / 1023.0);
  float current = analogRead(currentSensorPin) * (5.0 / 1023.0);
  time_t now = RTC.get();

  dataFile = SD.open("data.txt", FILE_WRITE);
  if (dataFile) {
    dataFile.print(now);
    dataFile.print(",");
    dataFile.print(voltage, 2);
    dataFile.print(",");
    dataFile.println(current, 2);
    dataFile.close();
  }

  float temperature = sensors.getTempCByIndex(0);
}

When checking no errors occur, when uploading neither, only in the serial monitor that the message below appears:

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3424, room 16
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8
tail 0
chksum 0x2b
csum 0x2b
v0004cdb0
~ld

This msg and reebot happen when something crashes the ESP8266.
As it divides the time between your code and the management of the internal WIFI system, if you stop your process, it keeps giving this message and "rebooting".
Where do I think it's crashing?
In the while (1); of this if.
if (!SD.begin(4)) {
while (1);

If it fails to start the SD, it will enter a while stuck.

So for testing purposes and to be able to see if this is true, remove this if and this while.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.