Samd11 NMI interrupt pin PA14

Hello all, im pretty new in Arduino world.
For my current project i am using custom samd11d14AM board and FAB arduino Mattiartech library.

I use TPL5010 watchdog. Resistors are set for 1s.
i am trying to perform high priority interrupt on pin PA14
and want to read WAKE signal and reset . My code turn on/off via pwm buzzer and this task take around 600mS. Beeep-bep-bep. The problem is that samd11 constantly reset when i send commands via terminal, this mean external WDT constantly reset it.
So, just software check Wake signal not do the job, i need interrupt reading.

//Define MCU pins
int DONE = 15;
int WAKE = 14;
int BUZ1 = 16;
int BUZ2 = 17;
int LED = 10;
bool running = false;

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 10000;


void task_on(void) {
  delay(300);
  analogWrite(BUZ1, 130);
  analogWrite(BUZ2, 130);
  digitalWrite(LED, HIGH);
  delay(250);
  analogWrite(BUZ1, 0);
  analogWrite(BUZ2, 0);
  digitalWrite(LED, LOW);
  delay(150);
  analogWrite(BUZ1, 130);
  analogWrite(BUZ2, 130);
  digitalWrite(LED, HIGH);
  delay(45);
  analogWrite(BUZ1, 0);
  analogWrite(BUZ2, 0);
  digitalWrite(LED, LOW);
  delay(45);
  analogWrite(BUZ1, 130);
  analogWrite(BUZ2, 130);
  digitalWrite(LED, HIGH);
  delay(45);
  analogWrite(BUZ1, 0);
  analogWrite(BUZ2, 0);
  digitalWrite(LED, LOW);
  delay(45);
  analogWrite(BUZ1, 130);
  analogWrite(BUZ2, 130);
  digitalWrite(LED, HIGH);
  delay(45);
  analogWrite(BUZ1, 0);
  analogWrite(BUZ2, 0);
  digitalWrite(LED, LOW);
  delay(45);
  analogWrite(BUZ1, 130);
  analogWrite(BUZ2, 130);
  digitalWrite(LED, HIGH);
  delay(45);
  analogWrite(BUZ1, 0);
  analogWrite(BUZ2, 0);
  digitalWrite(LED, LOW);
  delay(45);
};

void task_off(void) {
  analogWrite(BUZ1, 0);
  analogWrite(BUZ2, 0);
  digitalWrite(LED, LOW);
};


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

  startMillis = millis();  //initial start time

  // // //Start External Watchdog

  pinMode(DONE, OUTPUT);
  pinMode(WAKE, INPUT_PULLDOWN);
  pinMode(LED, OUTPUT);
  task_off();
  
  digitalWrite(DONE, HIGH);
  delayMicroseconds(20);
  digitalWrite(DONE, LOW);

  Serial.println("beat");
}


void loop() 
{

  if (digitalRead(WAKE)==1) 
  {
    digitalWrite(DONE, HIGH);
    delayMicroseconds(20);
    digitalWrite(DONE, LOW);
  }
 
  currentMillis = millis();
  //get the current "time" (actually the number of milliseconds since the program started)
  if (currentMillis - startMillis >= period)  //test whether the period has elapsed
  {
    Serial.println("beat");
    startMillis = currentMillis;  //IMPORTANT to save the start time of the current LED state.
  }


  if (Serial.available() > 0) 
  {
    String str = Serial.readString();
    if (str == "helloknockknock") 
    {
      Serial.println("hellofromknockknock");
    }
    if (str == "ON") {
      running = true;
    } else if (str == "OFF") {
      running = false;
    }
  }
  if (running == true) {
    task_on();
  } else task_off();
}

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in https://forum.arduino.cc/c/using-arduino/uncategorized/184.

Just google arduino interrupt and you should get thousands of hits. Or start looking at button and bounce libraries. High Priority? I don't think the Arduino architecture has a priority scheme, but maybe I am under educated.

No, NMI interrupt is different. I think could help me someone with samd21 or samd51 arduino experience

When you post enough information, plus maybe code and wiring maybe someone can help.
I did a quick google. This looks germain
https://developerhelp.microchip.com/xwiki/bin/view/products/mcu-mpu/32bit-mcu/sam/samd21-mcu-overview/samd21-processor-overview/samd21-nvic-overview/configuration/
OR maybe a previous forum thread answers you

updated information. I use external watchdog tpl5010.
Wake signal is connected to PA14. I do not use sleep.
Just i want when i receive Wake signal, to set immediately Done, because i have 600ms delays in my code, and USB connection repetely restart.

I doubt you need interrupts if you write your task_on() properly without the use of delays.

Hi @sukhoi

Here's an example of how to configure the NMI (PA08) on the SAMD21:

// SAMD21 Non Maskable Interrupt (NMI) Test on PA08, detect rising edges and toggle built-in LED in response
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);                     // Set digital pin LED_BUILTIN to an OUTPUT

  PORT->Group[PORTA].PINCFG[8].bit.INEN = 1;        // Enable the pull-down resistor on PA08
  PORT->Group[PORTA].PINCFG[8].bit.PULLEN = 1;      
  
  PORT->Group[PORTA].PINCFG[8].bit.PMUXEN = 1;      // Enable the port multiplexer on PA08
  PORT->Group[PORTA].PMUX[8 >> 1].reg |= PORT_PMUX_PMUXE_A; // Switch the port multiplexer to EIC on PA08
 
  GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID_EIC |         // Disconnect GCLK0 from the EIC
                      GCLK_CLKCTRL_GEN_GCLK0;       // Select GCLK0                                          

  EIC->NMICTRL.reg = EIC_NMICTRL_NMISENSE_RISE;     // Trigger an NMI interrupt on the a rising edge
  // EIC->NMICTRL.reg |= EIC_NMICTRL_NMIFILTEN;       // Enable NMI filter

  GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN |          // Enable GCLK
                      GCLK_CLKCTRL_ID_EIC |         // Connect GCLK0 to the EIC
                      GCLK_CLKCTRL_GEN_GCLK0;       // Select GCLK0                                          
}

void loop() {}

void NMI_Handler() {
  static bool toggle = false;                       // Define the toggle variable
  
  EIC->NMIFLAG.bit.NMI = 1;                         // Clear the NMI interrupt flag
  digitalWrite(LED_BUILTIN, toggle);                // Toggle the built-in LED
  toggle = !toggle;                                 // Flip the toggle
}

Thanks a lot!
I tested your code and it works!

PORT->Group[PORTA].PINCFG[14].bit.INEN = 1;        // Enable the pull-down resistor on PA08
  PORT->Group[PORTA].PINCFG[14].bit.PULLEN = 1;      
  PORT->Group[PORTA].PINCFG[14].bit.PMUXEN = 1;      // Enable the port multiplexer on PA08
  PORT->Group[PORTA].PMUX[14 >> 1].reg |= PORT_PMUX_PMUXE_A; // Switch the port multiplexer to EIC on PA08
  GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID_EIC |         // Disconnect GCLK0 from the EIC
                      GCLK_CLKCTRL_GEN_GCLK0;       // Select GCLK0                                          

  EIC->NMICTRL.reg = EIC_NMICTRL_NMISENSE_RISE;     // Trigger an NMI interrupt on the a rising edge
  // EIC->NMICTRL.reg |= EIC_NMICTRL_NMIFILTEN;       // Enable NMI filter

  GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN |          // Enable GCLK
                      GCLK_CLKCTRL_ID_EIC |         // Connect GCLK0 to the EIC
                      GCLK_CLKCTRL_GEN_GCLK0;       // Select GCLK0```
  1. I see over 1s of delays() in task_on()
  2. I believe Serial.readstring() defaults to a 1s timeout; are you sure that your settimeout works in the SAMD11 core?
  3. How are you resetting the watchdog? I don't see any manipulation of DONE and WAKE in your loop()

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