Arduino attachInterrupt() register writing equivalent on SAMD51?

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm very new to programming SAM mcus so please bear with me. I'm using an Adafruit Metro M4 board.

I wrote some code in the Arduino IDE that I'd like to write the equivalent of in Atmel Studio by writing the registers directly.

 

void setup()
{
  PORT->Group[PORTA].PINCFG[21].bit.INEN = 1;  // Enable PA21 (pin 8) as an input
  PORT->Group[PORTA].PINCFG[21].bit.PULLEN = 1;
  PORT->Group[PORTA].DIRCLR.reg = PORT_PA21;
  PORT->Group[PORTA].OUTSET.reg = PORT_PA21; //set the pullup resistor
  attachInterrupt(digitalPinToInterrupt(8), fallISR, FALLING);
}

void loop()
{
  //do nothing
}

void fallISR()
{
  //if there was a falling edge on pin 8, do what's in this ISR
}

I have no clue how to write the equivalent of attachInterrupt() in Atmel studio. From what I've seen it's fairly complicated and requires a lot of lines of code. Definitely harder than 8 bit AVRs like I'm used to.
I thought the Arduino github documentation would help but it's farily confusing and seems to only work for the SAMD21?

 

https://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/WInterrupts.c

 

When I attempt to copy and paste the code from this library several errors show up, for example when I copy and paste

NVIC_SetPriority(EIC_IRQn, 0);

I get the error "'EIC_IRQn' was not declared in this scope; did you mean 'ICM_IRQn'?"
I don't see anything about EIC_IRQn or ICM_IRQn in the SAMD51 datasheet so I'm not sure where to find what these things mean.

Same with "NVIC_SetPriority". I just have no clue where any of this stuff is coming from. Any help is greatly appreciated

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The D51 core code is here

https://github.com/adafruit/Ardu...

/Lars

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
EIC_IRQn

You need to substitute a valid interrupt number. These will be defined in the samd51 headers.

Search for EIC_ and you'll see your options. AS7 hopefully has the means to help you with finding it. I don't use AS7, so I can't be more specific.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Kartman wrote:
AS7 hopefully has the means to help you with finding it

Indeed: as you type "EIC_IRQ" it should show you the available options beginning with that string 

 

EDIT

 

Like this:

 

 

Note that they are sorted as text - not numerically - so '1' comes after '15':

 

 

Once you have it in your code, you can right-click to get the  'Go To Definition' feature:

 

 

This will show you where the symbol is defined:

 

In this case, there are many options - depending on the specific chip variant you're using.

 

Click the appropriate one to go to the definition for that chip:

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Oct 20, 2020 - 08:43 AM