Skip to content

Cache disabled but cached memory region accessed #1907

Closed
@anandpanchal

Description

@anandpanchal

whatsapp image 2018-09-27 at 3 54 46 pm

Hello Sir @stickbreaker

i am getting the same error. i am reading two ir sensors on two gpios of esp32 using interrupts.
i am using wifi, interrupts, isr, spifs in my code.
can you please help me in this regard by reviewing my code.

#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

#include "SPIFFS.h"
// Replace with your network credentials
const char* ssid = "=====";
const char* password = "======";

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);

// Variables to save date and time
String formattedDate;
String dayStamp;
String timeStamp;

volatile unsigned long fall_time1;
volatile unsigned long fall_time2;
volatile bool fall_flag1 = false;
volatile bool fall_flag2 = false;
volatile bool button_flag = false;

unsigned long previousMillis = 0; // last time update
unsigned long interval ; // interval at which to do something (milliseconds)

unsigned long interval_button ;
int led = 5;
int count = 0;

int button = 4;

int ir1 = 19;
int ir2 = 21;
int tr = 23;

#define duration 1500

volatile unsigned long duration_button = 0;
int wait = 10000;

unsigned long interval_1 = 0;
unsigned long interval_2 = 0;

hw_timer_t *timer0 = NULL;
portMUX_TYPE timerMux0 = portMUX_INITIALIZER_UNLOCKED;

volatile bool ledstat = 0;

void IRAM_ATTR onTimer0() //===================ESP32 TIMER ISR=====================================================//
{
portENTER_CRITICAL_ISR(&timerMux0);
ledstat = 1-ledstat;
digitalWrite(23, ledstat);
portEXIT_CRITICAL_ISR(&timerMux0);

}

void IRAM_ATTR fall_isr1() //=======================ISR IR1===========================================================//
{

unsigned long last_1 = millis();
if ((last_1 - interval_1) > duration)
{
fall_flag1 = true;

fall_time1 = last_1;
interval_1 = last_1;
//Serial.println("=====isr1====");
}
}

void IRAM_ATTR fall_isr2() //=========================ISR IR2===========================================================//
{

unsigned long last_2 = millis();
if((last_2 - interval_2) > duration)
{
fall_flag2 = true;
fall_time2 = last_2;
interval_2 = last_2;
//Serial.println("=======isr2=====");
}
}

void IRAM_ATTR button_isr()
{
interval_button = millis();
button_flag = true;

}

void setup()
{
Serial.begin(115200);

Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

// Initialize a NTPClient to get time
timeClient.begin();
// Set offset time in seconds to adjust for your timezone, for example:
// GMT +1 = 3600
// GMT +8 = 28800
// GMT -1 = -3600
// GMT 0 = 0
//GMT +5:30 = 19900 Indian Time
timeClient.setTimeOffset(19900);

pinMode(led, OUTPUT); //=====================RELAY PIN====================================================//
pinMode(tr, OUTPUT); //=====================TRANSMITTER PIN===============================================//
digitalWrite(tr , LOW);
Serial.println("Monitoring interrupts: ");
pinMode(ir2, INPUT_PULLUP); //======================IR 2=========================================================//
pinMode(ir1, INPUT_PULLUP); //======================IR 1=========================================================//
pinMode(button, INPUT_PULLUP); //======================BUTTON=======================================================//
digitalWrite(button, HIGH);
attachInterrupt(digitalPinToInterrupt(21), fall_isr2, FALLING);
attachInterrupt(digitalPinToInterrupt(19), fall_isr1, FALLING);
attachInterrupt(digitalPinToInterrupt(button), button_isr, FALLING);

timer0 = timerBegin(0, 80, true); //===================ESP32 TIMER0=============================================//
timerAttachInterrupt(timer0, &onTimer0, true); // edge triggered
timerAlarmWrite(timer0, 14, true); // 14 * 1us, autoreload true.
timerAlarmEnable(timer0);

//SPIFFS.begin();
if(!SPIFFS.begin(true))
{
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}

File file = SPIFFS.open("/test.txt", FILE_WRITE); // file open /create

if(!file)
{
Serial.println("There was an error opening the file for writing");
return;
}

}

void loop()
{

//volatile unsigned long interval_button = millis();
//File file = SPIFFS.open("/tes.txt", FILE_WRITE);
while(!timeClient.update())
{
timeClient.forceUpdate();
}
// The formattedDate comes with the following format:
// 2018-05-28T16:00:13Z
// We need to extract date and time
formattedDate = timeClient.getFormattedDate();
//Serial.println(formattedDate);

// Extract date
int splitT = formattedDate.indexOf("T");
dayStamp = formattedDate.substring(0, splitT);
//Serial.print("DATE: ");
//Serial.println(dayStamp);
// Extract time
timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1);
//Serial.print("HOUR: ");
//Serial.println(timeStamp);
//delay(1000);

unsigned long currentMillis = millis();

if (fall_flag1 && fall_flag2)
{
fall_flag1 = false;
fall_flag2 = false;

   if ((fall_time2 > fall_time1))   //================ENTRY ON==================================================//
   {
    digitalWrite(led, HIGH);
    interval = millis();
  //  Serial.println("======HIGH======");
    count = count + 1;
   // Serial.println("=====count=====");
   // Serial.println(count);

//=========================================================================================================================
File file = SPIFFS.open("/test.txt", FILE_WRITE); // file open /create

if(!file)
{
Serial.println("There was an error opening the file for writing");
return;
}

   if(file.print(dayStamp))                  // file write
        {
            Serial.println("Day File was written");;
        }
   else 
       {
            Serial.println("File write failed");
       }

       if(file.print(timeStamp))                  // file write
        {
            Serial.println("Time File was written");;
        }
   else 
       {
            Serial.println("File write failed");
       }

  file.close();


  File fileToAppend = SPIFFS.open("/test.txt", FILE_APPEND);     // file append

if(!fileToAppend){
    Serial.println("There was an error opening the file for appending");
    return;
}

if(fileToAppend.println(dayStamp)){
    Serial.println("Day File content was appended");
} else {
    Serial.println("File append failed");
}


if(fileToAppend.println(timeStamp)){
    Serial.println("Time File content was appended");
} else {
    Serial.println("File append failed");
}

fileToAppend.close();



File file2 = SPIFFS.open("/test.txt");                //===============file read ====================//
 
if(!file2){
    Serial.println("Failed to open file for reading");
    return;
}

Serial.println("File Content:");
Serial.write(file2.read()); 
while(file2.available())

{

    Serial.write(file2.read());
}

file2.close();

//=========================================================================================================
Serial.println ("===ON TIME===");
Serial.print("DATE: ");
Serial.println(dayStamp);
Serial.print("HOUR: ");
Serial.println(timeStamp);

   }
   if (fall_time1 > fall_time2)                  //=====================EXIT OFF=================================================================//
   {
    digitalWrite(led, LOW);
  //  Serial.println("=======LOW======");
    
    }

}

  if (button_flag)
  {
   //button_flag = false; 
   digitalWrite(led, HIGH); 
   //Serial.println("=======================================");
  }
  
  if (currentMillis - interval_button > wait)
  {
    //Serial.println("=========");
    button_flag = false;
    //digitalWrite(led, LOW);
  }

   if(currentMillis - interval == wait)             //====================TIMEOUT FUNCTION==============================================================//
 {
 
   Serial.println("====OFF TIME===");
   Serial.print("DATE: ");
   Serial.println(dayStamp);
   Serial.print("HOUR: ");
   Serial.println(timeStamp);
   delay(500);

 
   }
  if(currentMillis - interval > wait)             //====================TIMEOUT FUNCTION==============================================================//
 {
 
 digitalWrite(led , LOW);
 
 
   }  
  if(currentMillis - interval == 20000)             //====================TIMEOUT FUNCTION==============================================================//
 {
 
 fall_flag1 = false;
 fall_flag2 = false;
 Serial.println ("==========flag clear=====");

}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions