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