Can't communicate M4 and M7 core of Arduino giga

I am using multiple interrupts to read the IR sensor and store this a in array in the M4 core. I am calling updateIR, that returns the IR with the maximum value, in main core. However, the giga starts blink red when using RPC.call with as. Can anyone spot an error ? Can I use interrupts with RPC ?

//M4 Code
#include "Arduino.h"
#include "RPC.h"

uint16_t ir_values[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t ir_addr[16] = {15, 4, 5, 18, 19, 36, 39, 23, 13, 14, 26, 25, 33, 32, 35, 34};

int updateIR() {
  int pin = -1;
  int bValue = 0;
  for (int i = 0; i < 16; ++i) {
    if (ir_values[i] > bValue) {
      pin = i;
      bValue = ir_values[i];
    }
  }
  for (int i = 0; i < 16; ++i) ir_values[i] = 0;
  delay(100);

  return pin;
}

void setup() {
  // put your setup code here, to run once:
  RPC.begin();
  Serial.begin(9600);

  RPC.bind("updateIR", updateIR);
  for (int i = 0; i < 16; ++i) pinMode(ir_addr[i], INPUT);
  attachInterrupt(digitalPinToInterrupt(ir_addr[0]), read_sensor_0, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[1]), read_sensor_1, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[2]), read_sensor_2, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[3]), read_sensor_3, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[4]), read_sensor_4, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[5]), read_sensor_5, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[6]), read_sensor_6, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[7]), read_sensor_7, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[8]), read_sensor_8, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[9]), read_sensor_9, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[10]), read_sensor_10, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[11]), read_sensor_11, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[12]), read_sensor_12, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[13]), read_sensor_13, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[14]), read_sensor_14, FALLING);
  attachInterrupt(digitalPinToInterrupt(ir_addr[15]), read_sensor_15, FALLING);


}

void loop() {

}

void read_sensor_0() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) {
    if (digitalRead(ir_addr[0])) break;
  }
  ir_values[0] += micros() - start_time;
}

void read_sensor_1() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[1])) break;
  ir_values[1] += micros() - start_time;
}

void read_sensor_2() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[2])) break;
  ir_values[2] += micros() - start_time;
}

void read_sensor_3() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[3])) break;
  ir_values[3] += micros() - start_time;
}

void read_sensor_4() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[4])) break;
  ir_values[4] += micros() - start_time;
}

void read_sensor_5() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[5])) break;
  ir_values[5] += micros() - start_time;
}

void read_sensor_6() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[6])) break;
  ir_values[6] += micros() - start_time;
}

void read_sensor_7() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[7])) break;
  ir_values[7] += micros() - start_time;
}

void read_sensor_8() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[8])) break;
  ir_values[8] += micros() - start_time;
}

void read_sensor_9() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[9])) break;
  ir_values[9] += micros() - start_time;
}

void read_sensor_10() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[10])) break;
  ir_values[10] += micros() - start_time;
}

void read_sensor_11() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[11])) break;
  ir_values[11] += micros() - start_time;
}

void read_sensor_12() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[12])) break;
  ir_values[12] += micros() - start_time;
}

void read_sensor_13() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[13])) break;
  ir_values[13] += micros() - start_time;
}

void read_sensor_14() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[14])) break;
  ir_values[14] += micros() - start_time;
}


void read_sensor_15() {
  unsigned long start_time = micros();
  for (int i = 0; i < 2000; ++i) if (digitalRead(ir_addr[15])) break;
  ir_values[15] += micros() - start_time;
}
//M7 Code
#include "Arduino.h"
#include "RPC.h"

using namespace rtos;

Thread servoThread;

void setup() {
  // put your setup code here, to run once:
  RPC.begin();
  Serial.begin(9600);

  servoThread.start(printIR);
}

void loop() {
}

void printIR() {
  while (true) {
    auto ir = RPC.call("updateIR").as<int>();
    if (ir != -1) Serial.println(ir);
  }
}

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.