Hardware interrupt does not work when serial read continuously

In my code i have used interrupt pin 2,3 for pushbuttons. and in loop() in continuously take data from serial port (10 times per second 11 bytes per time). and now my interrupt routine does not run.

//Stepper Motor Pins
#define PIN 5
#define DIR 4
#define expValve 6

int startPoint = 0;
volatile int systemStatus = 0; // interrupts are not working so i made this 1 to run without command and test
int volumeSteps = 0; 
int FinalizeValue=0;

//inital values
int Volume = 700;//volume 500ml
int bpm = 12; //12 bpm
int ie = 2; //1:2 ratio

long ForwardSpeed = 0;
long totalTime = 0; 
long Ratio = 0; 
long riseTime = 100;
long waitTime;
long fwaitTime;

void setup() {
  // put your setup code here, to run once:
  pinMode(PIN, OUTPUT);
  pinMode(DIR, OUTPUT);
  pinMode(expValve, OUTPUT);
  pinMode(7, INPUT);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), detectStart,FALLING);
  attachInterrupt(digitalPinToInterrupt(3), detectStop, FALLING);
  digitalWrite(expValve, HIGH);
  Serial.begin(9600);
  delay(1000);
  ForwardSpeed = 2000;
  initialization();
}

void loop() {
  getData();
  FinalizeValue = volumeSteps;
  calculate_Forward_Delay();
  
  if (systemStatus == 1) {
      rotateStepper(FinalizeValue, 1, 1000);
      delay(waitTime);
      digitalWrite(expValve, LOW);
      rotateStepper(FinalizeValue, 0, ForwardSpeed);
      delay(fwaitTime);
      digitalWrite(expValve, HIGH);
  }
}
void getData() {
  if (Serial.available() > 0) {
    char c = "";
    while (c != 'b') {
      c = Serial.read();
    }
    if (c == 'b') {
      for (int i = 1; i < 4; ++i) {
        int raw = Serial.parseInt();
        if (i == 1)
          Volume = raw;
        if (i == 2)
          bpm = raw;
        if (i == 3)
          ie = raw;
      }
    }
  }
  volumeSteps = Volume / 4;
  totalTime = (60 / bpm) * 1000;
  Ratio = ie;
  Serial.print("Volume = ");
  Serial.print(Volume);
  Serial.print(" , ");  
  Serial.print("BPM = ");
  Serial.print(bpm);
  Serial.print(" , ");  
  Serial.print("Ratio = ");
  Serial.print(ie);
  Serial.println("  ");
  
}

void calculate_Forward_Delay() {
  long  time0 = (totalTime * 1000) / (Ratio + 1);
  long x = (time0 * riseTime) / 100;
  fwaitTime = (time0 - x) / 1000;
  waitTime  = time0 * Ratio;
  waitTime = waitTime / 1000;
  time0 = x / FinalizeValue;
  time0 = time0 / 2;
  ForwardSpeed = time0;
}

void detectStop() {
  delayMicroseconds(200);
  Serial.println("stop detected");
  if (digitalRead(3) == LOW) {
    systemStatus = 0;
  }
}

void detectStart() {
  delayMicroseconds(200);
  Serial.println("start detected");
  if (digitalRead(2) == LOW) {
    systemStatus = 1;
    FinalizeValue = volumeSteps;
  }
}
/*
void readVolume() {
  Volume = analogRead(VolumeNob);
  Volume = map(Volume, 0, 1023, 200, 1500);
  Serial.print("Volume = ");
  Serial.print(Volume);
  Serial.print(" , ");
  volumeSteps = Volume / 4;
}

void readSpeed() {
  long x = analogRead(SpeedNob);
  x = map(x, 0, 1023, 5, 20);
  Serial.print("Speed = ");
  Serial.print(x);
  Serial.print(" , ");
  x = (60 / x) * 1000;
  totalTime = x;
}

void readRatio() {
  int x = analogRead(RatioNob);
  x = map(x, 0, 900, 1, 3);
  Serial.print("Ratio = ");
  Serial.println(x);
  Ratio = x;
}
*/
//Direction 1 - Back / 0 - Forward
void initialization() {
  while (digitalRead(7) == 0) {
    rotateStepper(10, 1, 1000);
  }
  delay(2000);
  rotateStepper(530, 0, 1000);
}

void rotateStepper(int Steps, int dir, long Speed) {
  if (dir == 1) {
    digitalWrite(DIR, HIGH);
  } else {
    digitalWrite(DIR, LOW);
  }

  for (int i = 0 ; i < Steps ; ++i) {
    digitalWrite(PIN, HIGH);
    delayMicroseconds(Speed);
    digitalWrite(PIN, LOW);
    delayMicroseconds(Speed);
  }
}

FINAL_2.ino (3.58 KB)

  attachInterrupt(2, detectStart, FALLING);
  attachInterrupt(3, detectStop, FALLING);

The attachinterrupt() function takes the interrupt number, not the pin number as its first parameter

The recommendations are:

attachInterrupt(digitalPinToInterrupt(2), detectStart, FALLING);
attachInterrupt(digitalPinToInterrupt(3), detectStop, FALLING);

UKHeliBob:

  attachInterrupt(2, detectStart, FALLING);

attachInterrupt(3, detectStop, FALLING);



The attachinterrupt() function takes the interrupt number, not the pin number as its first parameter

GolamMostafa:
The recommendations are:

attachInterrupt(digitalPinToInterrupt(2), detectStart, FALLING);

attachInterrupt(digitalPinToInterrupt(3), detectStop, FALLING);

you just contributed to save another patient . this code belongs to prototype ventilator i'm making these days due to shortage of ventilators in sri lanka.