how to use NVIC_SET_PRIORITY, teensy 3.6

ozeng

Member
I want to set interrupt priorities on input pins; however, my interrupts do not seem to be pre-empting each other. I believe pin 0 (the interrupt that I want to interrupt) is on IRQ_PORTB and I have set that to priority 240, which should correspond to the lowest urgency. Why isn't this working?

Code:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);

  attachInterrupt(0, hi, FALLING);
  attachInterrupt(1, hi2, FALLING);
  attachInterrupt(2, hi3, FALLING);
  attachInterrupt(3, hi4, FALLING);
  attachInterrupt(4, hi5, FALLING);
  attachInterrupt(5, hi6, FALLING);
  NVIC_SET_PRIORITY(IRQ_PORTA + 16, 16);
  NVIC_SET_PRIORITY(IRQ_PORTB + 16, 240);
  NVIC_SET_PRIORITY(IRQ_PORTC+ 16, 48);
  NVIC_SET_PRIORITY(IRQ_PORTD + 16, 64);
  NVIC_SET_PRIORITY(IRQ_PORTE+ 16, 80);
}

void loop() {
}

void hi() {
  Serial.println("a");
  Serial.flush();
  for (int i = 0; i < 200000000; i++) {
    
  }
  Serial.println("bye");
  Serial.flush();
}

void hi2() {
  Serial.println("b");
  Serial.flush();
  delay(5);
}

void hi3() {
  Serial.println("c");
  Serial.flush();
  delay(3);
}

void hi4() {
  Serial.println("d");
  Serial.flush();
  delay(1);
}
void hi5() {
  Serial.println("e");
  Serial.flush();
  delay(1);
}
void hi6() {
  Serial.println("f");
  Serial.flush();
  delay(1);
}
void hi7() {
  Serial.println("g");
  Serial.flush();
  delay(1);
}

Serial output:
a
bye
d
e
a
bye
b
c
 
NVIC_SET_PRIORITY expects the IRQ number, not the vector number. So drop the '+ 16'.
 
Back
Top