Can I have an interrupt when a pin changes?

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

I'd like to have an interrupt to execute some code when the level of a pin changes from low to high or reverse. No sleep mode involved, so nothing to wake up. The closest information I found on this topic was this thread. It doesn't help me in finding a solution though. It proposes code that is unclear to me. I don't have PORTC to begin with. Reading the datasheet (sections about CPUINT and PORT) doesn't make me any wiser. And Google doesn't know other sources that might help. Has anybody done that before? Is it possible at all? Is it possible for any pins or just a few special undocumented pins? What code will I have to write for that? What's the ISR name? Will I have a separate interrupt handler for each pin and/or change event or a shared one that first has to find out what just happened?

 

I find it surprising that there is no information available online but I really couldn't find any. It's a big mystery.

 

My MCU is an ATtiny1614 (and I'd also be interested in the ATtiny412 which I haven't unpacked yet).

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

It helps to read the datasheet. Read the chapter called "PORT - I/O Pin Configuration", there will be a section on interrupts.

To find out the name used for the interrupt, a good source is the respective ioxxxx.h file for example "iotn1614.h" for the tiny1614. Do a search and you will find it.

 

edit: there is one ISR per port, you have to determine the pin that caused the ISR in software. For example, for port B it's PORTB_PORT_vect.

Last Edited: Thu. Jan 2, 2020 - 10:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, that worked. I wasn't that far from the solution. It turned out, however, that in my case it's probably better to poll the port in the main loop because I can't do much anyway in the ISR. (Especially not sending out a message over USART. It can only be queued there for sending in the next loop run.)