0

Setting up, say D2, as an INT pin on the Itsy Bitsy M4
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by Govner on Wed Aug 21, 2019 5:17 am

Hi,

My project needs the M4 Express to function as a slave. I understand that the board, currently, only functions as a MASTER. So, I2C slave functionality is forthcoming I understand. In the mean time, I am going to designate the ItsyBitsy M4 as MASTER and, although clumsy, have the MASTER set up to respond to an interrupt from a SLAVE that is generated whenever the SLAVE has data ready for the MASTER. The "ISR" on the MASTER would trigger a "request for data" from that SLAVE. This avoids the overhead of having the MASTER actually having to "poll" the SLAVE. The SLAVE responds to "onRequest", sends the requested number of bytes which the nice 120- Mhz MASTER displays on SPI TFT.

If there's a library for the AVR equivalent of attachInterrupt( nr, ISR, FALLING) , I couldn't find it after a week of searching. So, downloading the SAMD51 datasheet to see if I could write to the pertinent registers to initialize PA07 (D3, as I recall) resulted in a 2-day epic fail and the datasheet lacks example code found in the 21's datasheets. So..
..until the aforementioned I2C Slave "fix" arrives for the Express M4, would it be too much to ask for a few lines to set up D2 or D3 as an EXTINT? Or, if there's such an example elsewhere, please direct me. So far, the datasheet's descriptions of pertinent registers and control make sense, but lack of an example to implement them leads to even more unanswered questions. If this support request I'm making is unreasonable, that's understandable and I'll just wait on the I2C Slave functionality to be completed the Express M4 can be a Master or Slave as needed.

Much obliged,
GOV

Govner
 
Posts: 100
Joined: Wed Sep 14, 2016 4:42 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by adafruit_support_mike on Thu Aug 22, 2019 2:22 am

The attachInterrupt() function should be defined and working on the M4 platform.

SAMD microcontrollers handle pin interrupts differently than 8-bit AVR microcontrollers though.

For an 8-bit microcontroller, each pin that supports interrupts has its own ISR. When the pin's interrupt circuit sees the appropriate input, the ALU saves its state and branches to the address of the ISR.

A SAMD microcontroller sees all interrupts from the same peripheral as one interrupt, and you can arrange the peripherals in order of priority, so (for instance) a Timer-Counter generating PWM can suspend the ISR that responds to messages from the ADC. In that sense, all external interrupts are handled like pin-change interrupts on an AVR. The interrupt just tells you something happened, and the ISR has to check the registers to see which pin actually saw a signal.

The file Winterrupts.c in the SAMD board support package handles the job of associating functions with specific pins and finding/executing the correct one when an interrupt occurs:

https://github.com/adafruit/ArduinoCore ... terrupts.c

It has several chunks #ifdef'd for the SAMD51, so development has been done for the platform.

adafruit_support_mike
 
Posts: 58799
Joined: Thu Feb 11, 2010 2:51 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by Govner on Thu Aug 22, 2019 9:59 am

Thank you Mike. The comparison between processors that you iterated makes sense to me now that I've spent a couple days with the SAMD51 datasheet.

But, knowing that "attachInterrupt" is applicable and where to find the definitions should keep me busy and quiet for a while.

Thanks for the speedy reply also.

GOV

Govner
 
Posts: 100
Joined: Wed Sep 14, 2016 4:42 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by Govner on Tue Aug 27, 2019 3:03 pm

Govner wrote:Thank you Mike. The comparison between processors that you iterated makes sense to me now that I've spent a couple days with the SAMD51 datasheet.
But, knowing that "attachInterrupt" is applicable and where to find the definitions should keep me busy and quiet for a while.


( Is it possible that the combination of talking to myself followed by quoting my own post could lead to an endless loop. Scary thought at my age. Oh, well.)

Say, Mike, I followed your suggestion but for a few days now I've not been able to make it work for me (Itsy Bitsy M4 responding to interrupt methods I understand, that is).

Here's what I am seeking to make work on the Itsy-Bitsy. If I had a bare bones example from which to move forward, the SAMD51 would be viable in my projects.

Tutorials abound for the 328 to do the following, but the SAMD51? Zero tutorials - not even an example sketch (that I can find - exhaustively I must say).

Code: Select all | TOGGLE FULL SIZE
/*
 Hello Rangoon ! (Or NYC even). Please help with example of a functional equivalent to the following, simplest of
 sketches but that will function on an Itsy Bitsy M4 (SAMD51). Such an exammple
 appears to be non-existent and the datasheet for the SAMD51, well honestly, not much help
 at my level.
*/

// My standardized code for ATMEL328s and boards like
// Adafruit's Metro Mini, Pro-Mini, etc. that works like a charm.

  #define INT1_pin 3  // D3

  volatile boolean  NRF_data_ready_FLAG = false;

  //==============  ISR =================
      void ISR_NRF_data_ready() {
      NRF_data_ready_FLAG = true;
  }//====================================

void setup() {
  pinMode(INT1_pin, INPUT_PULLUP); //
  attachInterrupt (digitalPinToInterrupt (INT1_pin), ISR_NRF_data_ready, FALLING); // nrf24L01 INT connected to D3
  Serial.begin(9600);
 }
 
 void loop() {
   // Acknowledge the help and then get back to work.
     if(NRF_data_ready_FLAG){
      Serial.println( "Thank you Adafruit for the Itsy_Bitsy_M4 !!");
      NRF_data_ready_FLAG = false; 
     }
 }

Govner
 
Posts: 100
Joined: Wed Sep 14, 2016 4:42 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by adafruit_support_mike on Fri Aug 30, 2019 12:11 am

Hrm.. try printing the output from digitalPinToInterrupt( INT1_pin ). Let's see if the underlying code is mapping things correctly.

adafruit_support_mike
 
Posts: 58799
Joined: Thu Feb 11, 2010 2:51 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by Govner on Fri Aug 30, 2019 11:05 am

adafruit_support_mike wrote:The attachInterrupt() function should be defined and working on the M4 platform.
SAMD microcontrollers handle pin interrupts differently than 8-bit AVR microcontrollers though.
For an 8-bit microcontroller, each pin that supports interrupts has its own ISR. When the pin's interrupt circuit sees the appropriate input, the ALU saves its state and branches to the address of the ISR. A SAMD microcontroller sees all interrupts from the same peripheral as one interrupt, and you can arrange the peripherals in order of priority, so (for instance) a Timer-Counter generating PWM can suspend the ISR that responds to messages from the ADC. In that sense, all external interrupts are handled like pin-change interrupts on an AVR. The interrupt just tells you something happened, and the ISR has to check the registers to see which pin actually saw a signal. The file Winterrupts.c in the SAMD board support package handles the job of associating functions with specific pins and finding/executing the correct one when an interrupt occurs:

https://github.com/adafruit/ArduinoCore ... terrupts.c

It has several chunks #ifdef'd for the SAMD51, so development has been done for the platform.

>> Hrm.. try printing the output from digitalPinToInterrupt( INT1_pin ). Let's see if the underlying code is mapping things correctly.



Hi Mike,

I assume that "compiler verbose", or similar will give us what you request / need ?

If so, I attached .pdf file of the printout I created by copying the output of the compiler (verbose).

Thanks much. If this is not what you actually need, please let me know and I'll gladly get to work.

GOV
Attachments
ItsyBitsy_INT_Config_MIKE_adafruit.pdf
(86.04 KiB) Downloaded 4 times

Govner
 
Posts: 100
Joined: Wed Sep 14, 2016 4:42 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by adafruit_support_mike on Sun Sep 01, 2019 1:41 am

No, just a simple:

Code: Select all | TOGGLE FULL SIZE
Serial.println( digitalPinToInterrupt( INT1_pin ) );
The macro's job is to associate the pin number with the correct interrupt, and I want to see if it matches what's in the datasheet.

adafruit_support_mike
 
Posts: 58799
Joined: Thu Feb 11, 2010 2:51 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by Govner on Sun Sep 01, 2019 3:20 pm

adafruit_support_mike wrote:No, just a simple:

Code: Select all | TOGGLE FULL SIZE
Serial.println( digitalPinToInterrupt( INT1_pin ) );
The macro's job is to associate the pin number with the correct interrupt, and I want to see if it matches what's in the datasheet.





Ahhh, ok. Here you go Mike. This is a copy of the Serial Monitor output. Is this what you expected?
==========================================================
The output of 'Serial.println( digitalPinToInterrupt( INT1_pin )' = 3
==========================================================

Govner
 
Posts: 100
Joined: Wed Sep 14, 2016 4:42 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by adafruit_support_mike on Sun Sep 01, 2019 11:37 pm

Yeah, that's what I expected from the code, but it's wrong for the hardware.

Try using the simple integer 6 in setInterrupt() instead of calling digitalPinToInterrupt(). See if that makes pin 3 accept interrupts the way you expect.

adafruit_support_mike
 
Posts: 58799
Joined: Thu Feb 11, 2010 2:51 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by Govner on Mon Sep 02, 2019 3:33 am

adafruit_support_mike wrote:The attachInterrupt() function should be defined and working on the M4 platform.



Aha... you recommended pin "6" in the following

attachInterrupt(pin, ISR, mode)

So,

attachInterrupt(6, myISR, FALLING);

is what I will try the first thing tomorrow. It's 3:40 AM, after about 20 hours of fun with Arduino. I'm looking forward to trying this.

Did you get "6" from the datasheet? I'd be interested in the thought process there. I have read the proper section on interrupts in the datasheet and this "6" will help me connect some dots.

Will let you know how the "attachInterrupt" function works out. It should be a simple test. Thanks for hanging in here with me on it Mike. More later....


GOV

Govner
 
Posts: 100
Joined: Wed Sep 14, 2016 4:42 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by Govner on Mon Sep 02, 2019 10:25 pm

Hi Mike!

Sorry for the delay today. Dorian has our full attention down here in Jupiter, FL but I did wire up the ItsyBitsy M4 and see if your suggestion would solve the issue.

And, I'm happy to say, Adafruit comes through again!!

The "attachInterrupt( )" vice the "digitalPinToInterrupt ( )" was, as you pointed out, the correct method for the SAMD51.

I can't thank you enough. My ISR, when properly invoked now, spawns a Serial.println( "Thank you Adafruit...."). Here is the actual output, contact bounce notwithstanding:

Thank you Adafruit for the Itsy_Bitsy_M4 !!
Thank you Adafruit for the Itsy_Bitsy_M4 !!
Thank you Adafruit for the Itsy_Bitsy_M4 !!
Thank you Adafruit for the Itsy_Bitsy_M4 !!
Thank you Adafruit for the Itsy_Bitsy_M4 !!


Thanks Mike. I am so happy to be able to swap in the M4 for its speed and memory. Currently, I'm using two Metro Minis together for the task. Being able to substitute the 120 Mhz ItsyBitsy M4 for one of them (16 Mhz) will create far more processing power, memory and lightning fast TFT display side of the two-dev board project. I am a VERY happy camper.

Best,

GOV

Govner
 
Posts: 100
Joined: Wed Sep 14, 2016 4:42 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by adafruit_support_mike on Tue Sep 03, 2019 1:17 am

Actually I need to confirm something.. I think you might have found a bug in the board support package:

The SAMD51 pin assigned to D3 on an ItsyBitsy M4 is an input for EXTINT[6], but the digitalPinToInterrupt() macro in the BSP just echoes the pin number (in this case, 3).

Did using a 6 make your code work?

adafruit_support_mike
 
Posts: 58799
Joined: Thu Feb 11, 2010 2:51 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by Govner on Wed Sep 04, 2019 4:32 am

adafruit_support_mike wrote:Actually I need to confirm something.. I think you might have found a bug in the board support package:

The SAMD51 pin assigned to D3 on an ItsyBitsy M4 is an input for EXTINT[6], but the digitalPinToInterrupt() macro in the BSP just echoes the pin number (in this case, 3).

Did using a 6 make your code work?


No but I understand why you asked and I am really sorry for causing the confusion Mike.

As my posted Serial.print output confirmed:

attachInterrupt(digitalPinToInterrupt(3), ISR, FALLING); // does indeed just echo "3" and not 6 as it should. However,
by omitting the "digitalPinToInterrupt" does work.


To answer you PRECISELY this time, here's the actual code that works great and is copied here directly. Now, when Pin 3 of the ItsyBitsy M4
sees a falling voltage level, it invokes the ISR as expected.

Code: Select all | TOGGLE FULL SIZE

  #define INT1_pin 3

// The following line works with UNO, Metro Mini, etc.. 16 Mhz processors, NOT SAMD51s.
  //attachInterrupt (digitalPinToInterrupt (INT1_pin), ISR_NRF_data_ready, FALLING); 
 
  //But, for the SAMD51, must use:
 
  attachInterrupt (INT1_pin, ISR_NRF_data_ready, FALLING);



FYI,
I didn't go back and try to use '6' in the "digitalPinToInterrupt(6)" to see if the 6 would be echoed as was the '3'. When I just eliminated the "digitalPin...." converter completely, it worked fine as in the code. There's no doubt that there's a bug there. Even if '6' would work, users would have to grab the datasheet table of EXTINT to get the proper correlation for SAMD51, if I understand what's happening here.

If it would help you for me to experiment further with this "bug", I would be happy to try it by substituting '6' in the digitalPinToInterrupt(6) expression and see if it propagates.



Thanks again Mike.


Regards,
GOV

PS: A couple weeks ago, Adafruit2 was going to look into why this product will not
function fully as an I2C device (SLAVE). It does work as a Master but it's a known issue
that prior to release, the product slipped through without fully testing all I2C modes.
Full I2C operations is a must-have so I'm really counting on the support for this one.
I have a post/thread on the subject if you could kindly check on it. Thanks again!!

Govner
 
Posts: 100
Joined: Wed Sep 14, 2016 4:42 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by adafruit_support_mike on Wed Sep 04, 2019 11:41 pm

Thank you. I'll have to dig into it further.

The digitalPinToInterrupt() macro's job is to save people from having to look up interrupts in the datasheet, and if it's broken we'll need to fix it. I'll poke around some more and see if I can make sense of things.

adafruit_support_mike
 
Posts: 58799
Joined: Thu Feb 11, 2010 2:51 pm

Re: Setting up, say D2, as an INT pin on the Itsy Bitsy M4

by Govner on Thu Sep 05, 2019 3:44 pm

Can't wait to hear what you discover.

Thanks,
GOV

Govner
 
Posts: 100
Joined: Wed Sep 14, 2016 4:42 pm

Please be positive and constructive with your questions and comments.