simple beginners questions about ESP32 - Arduino

YvesDS
Posts: 9
Joined: Sat Sep 30, 2017 10:57 am

simple beginners questions about ESP32 - Arduino

Postby YvesDS » Fri Oct 13, 2017 6:34 pm

Hi all,

i have some simple questions about ESP32 programming in Arduino :

My setup :
Windows 7, Arduino IDE with latest ESP32 toolchain installed, NodeMCU-32S board, 80Mhz,921600, COM4

The esp32 has two cores, one can assign a task to either one of the cores.
I would like to do some logic on one core: taking input from a sensor (photocell) connected to GPIO25 through a interrupt and ISR (where i take the time when the interrupt fired and store it in a volatile variable "interruptExecuteTime")
On the second core i would like to do the output part (first on serial monitor, later on I2C LCD)
so the question is : how to create 2 tasks and according functions for the two seperate cores, and assign them to the correct core?
how to trigger the different tasks each time the sensors fire the interrupt?
is it OK to pass the data by declaring a volatile variable?

I have done this to start with :

Code: Select all

#include "arduino.h"

const byte interruptPin = 25;
volatile int interruptCounter = 0;
volatile double interruptExecuteTime = 0;
static int taskCore0 = 0;
static int taskCore1 = 1;
int numberOfInterrupts = 0;
 
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;

void core1Task( void * pvParameters ){
      Serial.print("An interrupt has occurred. Total: ");
      Serial.print(numberOfInterrupts);
      Serial.print(" at :");
      Serial.print(interruptExecuteTime);
      Serial.print(" on Core :");
      Serial.println(xPortGetCoreID());
}
void handleInterrupt(void * pvParameters) {
  portENTER_CRITICAL_ISR(&mux);
  interruptExecuteTime = millis(); // this is the important part for me
  interruptCounter++;
  portEXIT_CRITICAL_ISR(&mux);
}

 
void setup() {
 
  Serial.begin(115200);
  Serial.println("Monitoring interrupts: ");
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
  xTaskCreatePinnedToCore(
                  handleInterrupt,   /* Function to implement the task */
                  "handleinterrupt", /* Name of the task */
                  10000,      /* Stack size in words */
                  NULL,       /* Task input parameter */
                  0,          /* Priority of the task */
                  NULL,       /* Task handle. */
                  taskCore0);  /* Core where the task should run */
  xTaskCreatePinnedToCore(
                  core1Task,   /* Function to implement the task */
                  "core1Task", /* Name of the task */
                  10000,      /* Stack size in words */
                  NULL,       /* Task input parameter */
                  0,          /* Priority of the task */
                  NULL,       /* Task handle. */
                  taskCore1);  /* Core where the task should run */
}
 
 
void loop() {
 
  if(interruptCounter>0){ // greater than 0 means there was a interrupt fired
       portENTER_CRITICAL(&mux);
      interruptCounter--; // decrease to reset the value
      portEXIT_CRITICAL(&mux);
      numberOfInterrupts++; // count the numbers of interrupts fired at this moment
}
  if (numberOfInterrupts >= 25){
    numberOfInterrupts = 0;
    esp_restart(); // restart example by cleaning all data and resetting MCU
  }
}


when i compile, i get this error message :

Code: Select all

C:\Users\Beheerder\Documents\Arduino\ESP32 projects\esp_restart_with_interrupts_example1\esp_restart_with_interrupts_example1.ino: In function 'void setup()':

esp_restart_with_interrupts_example1:34: error: invalid conversion from 'void (*)(void*)' to 'void (*)()' [-fpermissive]

   attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);

                                                                                ^
In file included from C:\Users\Beheerder\Documents\Arduino\hardware\espressif\esp32\cores\esp32/esp32-hal.h:52:0,

                 from C:\Users\Beheerder\Documents\Arduino\hardware\espressif\esp32\cores\esp32/Arduino.h:35,

                 from C:\Users\BEHEER~1\AppData\Local\Temp\arduino_build_465995\sketch\esp_restart_with_interrupts_example1.ino.cpp:1:

C:\Users\Beheerder\Documents\Arduino\hardware\espressif\esp32\cores\esp32/esp32-hal-gpio.h:81:6: note:   initializing argument 2 of 'void attachInterrupt(uint8_t, void (*)(), int)'

 void attachInterrupt(uint8_t pin, void (*)(void), int mode);

      ^
exit status 1
invalid conversion from 'void (*)(void*)' to 'void (*)()' [-fpermissive]

So my code did not work for me :(
Since i am a absolute beginner on the ESP32 platform, this looked like a no-brainer, but that came out very different ;)
What am i doing wrong?
What should i read as documentation on this?

Grtz,
Yves

Markonian
Posts: 1
Joined: Sat Oct 21, 2017 5:48 pm

Re: simple beginners questions about ESP32 - Arduino

Postby Markonian » Sat Oct 21, 2017 6:04 pm

Please re-read the first error message. It tells you exactly what the error is.

Now if you look to see why the compiler wants to convert 'void (*)(void*)' to 'void (*)()', you will notice that attachInterrupt() requires a pointer to a function that returns nothing and takes NO ARGUMENTS. You are supplying a function that has 1 ARGUMENT.

See the documentation for attachInterrupt() for further details.

Now, my question for anyone that can help... what's wrong with my embedded link markup above? It doesn't seem to work the way I expected (should not show markup and url, just link text).

YvesDS
Posts: 9
Joined: Sat Sep 30, 2017 10:57 am

Re: simple beginners questions about ESP32 - Arduino

Postby YvesDS » Sun Oct 22, 2017 11:53 am

Markonian wrote:Please re-read the first error message. It tells you exactly what the error is.
Now if you look to see why the compiler wants to convert 'void (*)(void*)' to 'void (*)()', you will notice that attachInterrupt() requires a pointer to a function that returns nothing and takes NO ARGUMENTS. You are supplying a function that has 1 ARGUMENT.


so i need to write : "attachInterrupt(digitalPinToInterrupt(interruptPin), &handleInterrupt, FALLING);" then? (by & referencing then?)
Grtz,
Yves

Who is online

Users browsing this forum: Bing [Bot] and 2 guests