4

I just wanted to know if I did this right:

I created a task on the 2nd core and inserted an interrupt in it.

xTaskCreatePinnedToCore(coreTask1, "CPU_1", 1000, NULL, 0, &Core1TaskHnd, 1); //Creating Task on Core 1

void coreTask1(void *parameter) //The Task I call
{
  attachInterrupt(2, encoderEvent_Motor1, CHANGE); 

  //attachInterrupt(2, encoderEvent_Motor2, CHANGE); //TODO
  //attachInterrupt(2, encoderEvent_Motor3, CHANGE); //TODO
  //attachInterrupt(2, encoderEvent_Motor4, CHANGE); //TODO

  Serial.println(xPortGetCoreID());

  while (1)
  {
    /* code */
  }
}

My question is: Is the interrupt really running on the 2nd core.

1 Answer 1

2

According to ESP-IDF's documentation, "External Peripheral Interrupts":

Allocating an external interrupt will always allocate it on the core that does the allocation.

So, yes, when you set up an interrupt handler, the interrupt will be handler by the core that set up the handler.

That said, it's unnecessary to create a task to pin it to the second core (core 1) as Arduino code automatically runs on that core. The first core (core 0) runs the network stack.

You can test this by calling xPortGetCoreID() in Setup() as you did in your task:

Serial.print("Current CPU core ");
Serial.println(xPortGetCoreID());

You should see "Current CPU core 1" as output (the cores are normally numbered 0 and 1).

You can also test that your interrupt handler is running on core 1 by calling this from it. For extra credit, have the interrupt handler increment a counter every time it runs on core 0 and then check the counter periodically from your main program and output a message if it's ever not zero.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.