-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache disabled but cached memory region accessed #1907
Comments
instead of volatile for each variable you are using in the ISRs try using DRAM_ATTR instead. volatile doesn't move it to IRAM/DRAM which is required for access in ISRs. |
Hi @atanisoft and @stickbreaker Thnaks for the comment. HOW CAN I CLEAR THE INTERRUPTS AFTER SOME INTERVAL OF TIME , LET SAY 10 SECONDS Thanks in advance. void loop()
{
} |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This stale issue has been automatically closed. Thank you for your contributions. |
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;
//=========================================================================================================================
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;
}
{
//=========================================================================================================
Serial.println ("===ON TIME===");
Serial.print("DATE: ");
Serial.println(dayStamp);
Serial.print("HOUR: ");
Serial.println(timeStamp);
}
}
}
The text was updated successfully, but these errors were encountered: