Go Down

Topic: Interrupt Priority (Read 96 times) previous topic - next topic


Is there a Interrupt priority in Due? Is it so how to prioritize the interrupt for pins, Timers & communication?

Thanks in advance


You can play with the priority number of a peripheral and enable/disable priorities from a priority level.

The priority handling is rather complex:

You can set a priority and a sub priority level: If an interrupt fires while an other interrupt is in process, if the pending interrupt has a higher priority level ( = a lower priority number), the previous priority will be interrupted. If an interrupt fires while another interrupt is in process with the same priority level, the pending interrupt can interrupt the interrupt in process if its sub priority level is higher.

You define priority grouping too.

An example sketch in which you can play with the priority level of an interrupt to enable/disable with __Set_BASEPRI():

Code: [Select]

/*       Timer Counter 2 Channel 2, namely TC8, 1 MHz frequency   */

void setup() {

  // Stop interrupts with a priority number equal or superior to 6
  __set_BASEPRI(6 << (8 - __NVIC_PRIO_BITS)); // priority shifted left !!
  __set_FAULTMASK(0); // 1 = Disable all interrupts, except NMI; 0=No effect

void loop() {


void tc_setup() {

  PMC->PMC_PCER1 |= PMC_PCER1_PID35;                      // TC8 power ON : Timer Counter 2 channel 2 IS TC8 - see page 38

  TC2->TC_CHANNEL[2].TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1  // MCK/2 = 42 M Hz, clk on rising edge
                              | TC_CMR_WAVE               // Waveform mode
                              | TC_CMR_WAVSEL_UP_RC;       // UP mode with automatic trigger on RC Compare

  TC2->TC_CHANNEL[2].TC_RC = 42;  //<*********************  Frequency = (Mck/2)/TC_RC  Hz

  NVIC_SetPriority(TC8_IRQn, 5); // Set the priority number for TC8
  TC2->TC_CHANNEL[2].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Software trigger TC2 counter and enable

void TC8_Handler() {

  static uint32_t Count;

  TC2->TC_CHANNEL[2].TC_SR;                               // Read and clear status register
  if (Count++ == 1000000) {
    Count = 0;
    PIOB->PIO_ODSR ^= PIO_ODSR_P27;                       // Toggle LED every 1 Hz

Go Up