Unable to attachinterrupt on core 0

ashishbindal93
Posts: 2
Joined: Tue Nov 05, 2019 5:22 am

Unable to attachinterrupt on core 0

Postby ashishbindal93 » Tue Nov 05, 2019 5:45 am

Hi everyone
I am trying to attach a hardware interrupt on pin 0 from core 0 of esp32 in dual core mode but this doesn't work at all (no response at all and no errors) and moreover attaching the interrupt in setup function (which i assume runs on core 1) does work but esp32 reboots with guru meditation error.

Heres my code

Code: Select all

#include <Arduino.h>
#include <ESP32Ticker.h>
#include <EEPROM.h>
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>

AsyncWebServer server(80);

const char* ssid = "******";
const char* password = "*******";

#define EEPROM_SIZE 21

#define INTR_PIN 0

#define EE_count 0

Ticker timer, timer2;
byte cntr = 0;

TaskHandle_t Task1;


//function to be fired at the zero crossing to dim the light
void IRAM_ATTR zero_crosss_int() {
  Serial.print(F("\n\nIntererupt Fired !! \non Core = "));
  Serial.println(xPortGetCoreID());
  Serial.println(F("\n\n"));
  resetCntr();
}

//Task1code: attach interrupt to the second core for multitasking
void startZeroCrossingInterrupt( void * pvParameters ) {
    
  //attachInterrupt(INTR_PIN, zero_crosss_int, FALLING);  // Choose the zero cross interrupt # from the table above
  
  for(;;) {
    delay(3000);
    Serial.print(F("-----------------------------Side loop running on core "));
    Serial.println(xPortGetCoreID());
    Serial.println(F("-----------------------------Updating EEPROM"));
    cntr++; writeToEEPROM();
  }
}

byte readFromEEPROM() {
   return (byte)EEPROM.read(EE_count);
}

void writeToEEPROM() {
   EEPROM.write(EE_count, cntr); EEPROM.commit();
}

void resetCntr(bool toZero=false) {
  if(toZero == false) { cntr = 0; }
  else { cntr = 1; }
  writeToEEPROM();
  Serial.print(F("\n* Counter Reset : toZero = "));
  Serial.print(toZero==false?"false":"true");
  Serial.println(F(" *\n"));
}

void deleteTimers() {
  timer.detach();
  timer2.detach();
  Serial.println(F("\n//// Deleting Counters ////\n"));
}

void setup() {
  
  EEPROM.begin(EEPROM_SIZE);

  //create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
  xTaskCreatePinnedToCore(
                    startZeroCrossingInterrupt,   /* Task function. */
                    "Zero Crossing Function",     /* name of task. */
                    10000,       /* Stack size of task */
                    NULL,        /* parameter of the task */
                    1,           /* priority of the task */
                    &Task1,      /* Task handle to keep track of created task */
                    0);          /* pin task to core 0 */                  
  delay(500);
  
  Serial.begin(115200);
  pinMode(INTR_PIN, INPUT_PULLUP);  
  //attachInterrupt(INTR_PIN, zero_crosss_int, FALLING);  // Choose the zero cross interrupt # from the table above

  timer.attach_ms(10000, resetCntr, true);
  timer2.attach_ms(60000, deleteTimers);
  
}

void loop() {

  delay(2000);
  Serial.print(F("Main loop running on core "));
  Serial.println(xPortGetCoreID());
  Serial.print(F("Reading EE_count = "));
  Serial.println(readFromEEPROM());
}


guru meditation error when if i make a hardware interrupt after attaching interrupt in setup func

Excerpt from my Serial

Code: Select all

Intererupt Fired !! 
on Core = 1



Guru Meditation Error: Core  1 panic'ed (Interrupt wdt timeout on CPU1)
Core 1 register dump:
PC      : 0x4008a8fc  PS      : 0x00060834  A0      : 0x80089c73  A1      : 0x3ffbe5d0  
A2      : 0x3ffb7df4  A3      : 0x3ffbc780  A4      : 0x00000001  A5      : 0x00000001  
A6      : 0x00060823  A7      : 0x00000000  A8      : 0x3ffbc780  A9      : 0x3ffbc780  
A10     : 0x00000001  A11     : 0x00000001  A12     : 0x3ffb81cc  A13     : 0x00000018  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x0000001d  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  
Core 1 was running in ISR context:
EPC1    : 0x40088337  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x4008a8fc

Backtrace: 0x4008a8fc:0x3ffbe5d0 0x40089c70:0x3ffbe5f0 0x400886fb:0x3ffbe610 0x400dc0fa:0x3ffbe650 0x400dc1ba:0x3ffbe670 0x40082b96:0x3ffbe690 0x4008248e:0x3ffbe6b0 0x400dac95:0x3ffbe700 0x400d1831:0x3ffbe720 0x400d159b:0x3ffbe740 0x400d15be:0x3ffbe760 0x40081181:0x3ffbe780 0x400811d1:0x3ffbe7a0 0x400819fd:0x3ffbe7c0 0x400fcef7:0x3ffbc670 0x400db67f:0x3ffbc690 0x400898e1:0x3ffbc6b0 0x400879e1:0x3ffbc6d0

Core 0 register dump:
PC      : 0x40087e9c  PS      : 0x00060034  A0      : 0x80088d15  A1      : 0x3ffbbf70  
A2      : 0x3ffbec24  A3      : 0xb33fffff  A4      : 0x00060023  A5      : 0x003fffff  
A6      : 0x00060021  A7      : 0x00000000  A8      : 0x0000cdcd  A9      : 0x0000cdcd  
A10     : 0x0000abab  A11     : 0x00060023  A12     : 0x00060021  A13     : 0x3ffbc120  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x00000020  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  

Backtrace: 0x40087e9c:0x3ffbbf70 0x40088d12:0x3ffbbfa0 0x4008a614:0x3ffbbfc0 0x4008a5ca:0x40081998

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9232
load:0x40080400,len:6400
entry 0x400806a8


Intererupt Fired !! 
on Core = 1



Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU0)
Core 0 register dump:
PC      : 0x40087e9a  PS      : 0x00060034  A0      : 0x80088d15  A1      : 0x3ffbbfd0  
A2      : 0x3ffbec24  A3      : 0xb33fffff  A4      : 0x00060023  A5      : 0x003fffff  
A6      : 0x00060021  A7      : 0x00000000  A8      : 0x0000abab  A9      : 0x0000cdcd  
A10     : 0x0000abab  A11     : 0x00060023  A12     : 0x00060021  A13     : 0x3ffbc080  
A14     : 0x00000003  A15     : 0x00060a23  SAR     : 0x00000014  EXCCAUSE: 0x00000005  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  

Backtrace: 0x40087e9a:0x3ffbbfd0 0x40088d12:0x3ffbc000 0x4008a614:0x3ffbc020 0x4008a5ca:0x3ffbc040 0x4008b487:0x00000000

Core 1 register dump:
PC      : 0x4008a8f8  PS      : 0x00060e34  A0      : 0x80089c73  A1      : 0x3ffbe5e0  
A2      : 0x3ffb7df4  A3      : 0x3ffb8074  A4      : 0x00000001  A5      : 0x00000001  
A6      : 0x00060e23  A7      : 0x00000000  A8      : 0x3ffb8074  A9      : 0x3ffb8074  
A10     : 0x00000001  A11     : 0x00000001  A12     : 0x00311000  A13     : 0x0000ff00  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x00000019  EXCCAUSE: 0x00000005  
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  

Backtrace: 0x4008a8f8:0x3ffbe5e0 0x40089c70:0x3ffbe600 0x400886fb:0x3ffbe620 0x400dc0fa:0x3ffbe660 0x400dc1ba:0x3ffbe680 0x40082b96:0x3ffbe6a0 0x40082201:0x3ffbe6c0 0x40082293:0x3ffbe6e0 0x400dacd9:0x3ffbe700 0x400d1821:0x3ffbe720 0x400d159b:0x3ffbe740 0x400d15be:0x3ffbe760 0x40081181:0x3ffbe780 0x400811d1:0x3ffbe7a0 0x400819fd:0x3ffbe7c0 0x4000bfed:0x3ffb1ee0 0x40089269:0x3ffb1ef0 0x40083c8a:0x3ffb1f10 0x400d64b9:0x3ffb1f30 0x400d64d1:0x3ffb1f60 0x400d1679:0x3ffb1f80 0x400d6f1f:0x3ffb1fb0 0x400879e1:0x3ffb1fd0

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9232
load:0x40080400,len:6400
entry 0x400806a8
Please help me with this I want to build an triac driving output circuit by phase cutting on zero crossing detection.
I have implemented this on arduino uno and pro mini but now i want to shift to ESP32.

I want to detect zero crossing and do phase cutting stuff on core 0 and make core 1(normal loop function) do all other stuff.

One more question please tell on which core does network calls get executed, I dont want to disturb core 0 (zero crossing stuff) atall.
As you can infer from my libraries I want to start a webserver also.

Thank you everyone in advance

ESP_Sprite
Posts: 9040
Joined: Thu Nov 26, 2015 4:08 am

Re: Unable to attachinterrupt on core 0

Postby ESP_Sprite » Thu Nov 07, 2019 4:41 am

Moving ADF -> Arduino.

idahowalker
Posts: 166
Joined: Wed Aug 01, 2018 12:06 pm

Re: Unable to attachinterrupt on core 0

Postby idahowalker » Thu Nov 07, 2019 6:20 am

Your interrupt routine is doing way to many things. The ISR should just, in the case of an ESP32 do event triggers and a bit of counting.

Code: Select all

void IRAM_ATTR onTimer()
{
  BaseType_t xHigherPriorityTaskWoken;
  iTicCount++;
  xEventGroupSetBitsFromISR(eg, OneMilliSecondGroupBits, &xHigherPriorityTaskWoken);
  if ( (iTicCount % 2) == 0 )
  {
    if ( (xSemaphoreTakeFromISR(sema_ReceiveSerial_LIDAR, &xHigherPriorityTaskWoken)) == pdTRUE ) // grab semaphore, no wait
    {
      xEventGroupSetBitsFromISR(eg, evtReceiveSerial_LIDAR, &xHigherPriorityTaskWoken); // trigger every 2mS, if not already processing
    }
  }
  if ( (iTicCount % 3) == 0 )
  {
    if ( (xSemaphoreTakeFromISR(sema_HexaPodAdjustment, &xHigherPriorityTaskWoken)) == pdTRUE ) // grab semaphore, no wait
    {
      xEventGroupSetBitsFromISR(eg1, evtWalk_Forward, &xHigherPriorityTaskWoken);
    }
  }
  if ( iTicCount == OneK )
  {
    xEventGroupSetBitsFromISR(eg, OneSecondGroupBits, &xHigherPriorityTaskWoken); // trigger every 1X a second
    // reset counter to start again
    iTicCount = 0;
  }
  if ( !bLIDAR_OK )
  {
    xSemaphoreTakeFromISR ( sema_iLIDAR_Power_Reset, &xHigherPriorityTaskWoken );
    ++iLIDAR_Power_Reset;
    xSemaphoreGiveFromISR ( sema_iLIDAR_Power_Reset,  &xHigherPriorityTaskWoken);
    if ( iLIDAR_Power_Reset >= 4000 )
    {
      xEventGroupSetBitsFromISR(eg, evtfLIDAR_Power_On, &xHigherPriorityTaskWoken);
    }
  }
} // void IRAM_ATTR onTimer()
An ISR doing very little work but triggering other task to do the work.

Serial print from an ISR, not a good thing do considering how many clock cycles a serial print consumres.

Who is online

Users browsing this forum: No registered users and 70 guests