Array not updating--Not sure where the problem is

Hi, I have a project which uses an ISR on a laser trigger. after 2 laser triggers occur in a row, 3 arrays should update with ADC information. I then communicate this information to a Raspberry Pi over Serial. My problem is the arrays are not updating every time 2 triggers occur. I know this because the timestamp of the two triggers and the amount of triggers that has occurred are also sent serially, and they update every time. I believe the mechanism by which I refill the arrays is not working. Anyway, below is my code, I call every variable in the ISR that updates a volatile variable:

volatile int countevent = 0, count2 = 0,count3 = 0;// countevent lets shift register know an event (2 crossings) has happened so save the data, timer counts how long since last interrupt
 int i = 0, j = 0, eventnum = 0, evnum; //loop variable
 volatile unsigned long timing = 0, timestamp = 0;
 unsigned long timesince, timemid = 0; //timing times interrupt, timestamp gives time between 2 interrupts, timesince measures whether a false trigger occured
 float velocity;
 char LF = 10; //tells arduino xojo is done with command
 uint16_t p1ch[16], p2ch[16], bch[16],vdiffp1[16],vdiffp2[16];
 const String MyName = "Y1O";
 String CMD;

void setup() {
  // put your setup code here, to run once:
  attachInterrupt(digitalPinToInterrupt(3), myISR, RISING);//interrupt to store data from ADC in serial buffer after trigger event
  //serial number written to eeprom
Serial.begin(115200);     //Begin Serial Monitor 115200 baud rate
  SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE1));  //2MHz speed, most significant bit first, data capture on rising clock

void myISR() {
 if(count2 <= 1){
    timestamp = micros() - timing;//timer2.get_count()-timing;
    timing = micros();//timer2.get_count();
  PORTB &= 0xFB;//select ADC
  for(i = 0; i < 24; i++) { // artificially slow down interrupt
  digitalWrite(4, HIGH);
  digitalWrite(4, LOW);
  digitalWrite(CS, LOW);
  SPI.transfer16(0); //transfer 16 bits of dummy data, enough to fill Serial buffers                
  digitalWrite(CS, HIGH);
    SPI.end(); //allows for manual toggle of CLK to read data from Serial Buffer 
  digitalWrite(RST, LOW);
  digitalWrite(RST, HIGH);
  countevent++;//if 2 interrupts occur within 1 ms, an "event" has occured, gather shift register data

//bit bang data from Serial Buffer A
void SRA() {

p1ch[3] = SPI.transfer16(0);//order daisy-chained serial buffers' data comes in
p1ch[2] = SPI.transfer16(0);
p1ch[1] = SPI.transfer16(0);
p1ch[0] = SPI.transfer16(0);
p1ch[7] = SPI.transfer16(0);
p1ch[6] = SPI.transfer16(0);
p1ch[5] = SPI.transfer16(0);
p1ch[4] = SPI.transfer16(0);
p1ch[11] = SPI.transfer16(0);
p1ch[10] = SPI.transfer16(0);
p1ch[9] = SPI.transfer16(0);
p1ch[8] = SPI.transfer16(0);
p1ch[15] = SPI.transfer16(0);
p1ch[14] = SPI.transfer16(0);
p1ch[13] = SPI.transfer16(0);
p1ch[12] = SPI.transfer16(0);

//convert binary to decimal voltage
void SRConverter() {
  if(count2 == 2) { 
    count2 = 0;

void loop() {
while(Serial.available() >0) {
  String CMD = Serial.readStringUntil(LF);

  if(CMD == MyName) {
    digitalWrite(CTS, HIGH);
    for(j = 0; j < 16; j++) {
     p1ch[j] = 0;
     p2ch[j] = 0;
     bch[j] = 0;
  digitalWrite(CTS, LOW);

In SRConverter(), SRB and backGroundSignal are the exact same things as SRA, only filling up the other 2 arrays, so I left that out. SR converter only runs when count2 == 2, which happens after 2 triggers, and then is set back to 0 by SR converter, so every time 2 triggers occur, next time I poll the Arduino, the arrays should update. Any ideas?

   for (i = 0; i < 24; i++)  // artificially slow down interrupt
      digitalWrite(4, HIGH);
      digitalWrite(4, LOW);

Why ?
Normally ISRs are designed to execute as quickly as possible.

    SPI.transfer16(0); //transfer 16 bits of dummy data, enough to fill Serial buffers

Interrupts are disabled when in an ISR. Does SPI use interrupts ?

the delay
Should have gotten rid of that. For my specific project, the time between triggers are slower than they will be in the future, I have a sample and hold that I need to pull back up high after the ADC clocks in, and if I pull it up too high before the object passes through the laser, it will get pulled back down to exactly where it was during the first interrupt, thus I am artificially slowing it down. However, I'm controlling when exactly the interrupt happens in my lab, so I don't need it to be as short as possible.

SPI in interrupts
SPI can be used in interrupts, if you look at the SPI library info for aruduino. Some suggest to use the SPI.UsingInterrupts function to prevent conflicts, but both my spi (inside and outside ISR) use the same settings and the same device

There are many things that programmers do to make their code understandable. Please do them, as a courtesy to the members who volunteer their time to help you here. Use a standard indentation to clearly show the code blocks. Never put more than one statement per line. Place any brackets by themselves on a separate line. Use blank lines sparingly, no more than one at a time. Before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read. Another is to give things descriptive names. Use descriptive variable names, for example "temperature" instead of "t". You can name numerical constants, pin numbers, variables and many other things in this way. For example, you can refer to a pin and an output level by number, like digitalWrite(3,0). But such a statement doesn't reveal anything about the purpose. digitalWrite(hornRelayPin, LOW) does. You can do that by declaring const byte hornRelayPin = 3; before setup() in your program. Many such names are already defined for you by the compiler and the Arduino IDE. Here are some:

#define HIGH 0x1
#define LOW  0x0
#define PI 3.1415926535897932384626433832795

Use them. There are many more. Use compiler math to compute values so you can see where they came from (or at least document them). For example, if you see the number 73, you would be hard put to explain the significance of it. But if you see "daysPerYear/5", it is obvious. One more thing. When you work on program continuously, you become familiar with it. So many things seem obvious even if they are not spelled out explicitly. But try looking at your own code six months later. It will be as if a stranger wrote it. So write for strangers, not yourself.

Thanks for the tips aarg! ill keep those in mind next time :slight_smile: