How to generate a portpin interrupt with ATtiny817?

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

Hello,

 

i am a newbie with ATtiny817 and i want to generate a simple portpin interrupt on PORTC Pin3 with a pushbutton.

I read the datasheet but there is no little code example how to handle it.

 

Can somebody guide me through the steps or post a little code example?

 

Many thanks!

This topic has a solution.
Last Edited: Fri. Mar 30, 2018 - 09:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ledi001 wrote:
i am a newbie with ATtiny817

Do you have any experience with any other microcontroller(s) ?

 

Note that a pushbutton will not not generate a clean, single pulse - it will bounce:

 

http://www.ganssle.com/debouncin...

 

 

EDIT

 

The way to start for pretty much any chip is to go to the Product Page on the manufacturer's website; in this case:

 

http://www.microchip.com/wwwproducts/en/ATtiny817

 

Open the 'Documentation' section

 

Amongst the many documents, you will see:

 

AN_8469 - AVR1201: Using External Interrupts for tinyAVR Devices
 

Sounds like a good place to start ...

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: Thu. Mar 29, 2018 - 04:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for your reply,

 

yes i have experience e.g. with ATMega88 and ATtiny44 and i know that a pushbutton will bounce.

I need the interrupt as a wake up source if the controller is in power down mode.

 

But the AVR1 series like ATtiny817 are very different with the naming and handling with their registers. The document you mentioned above is usefull for AVR but not for AVR1 series.

 

I miss the little example codes in the new datasheets from microchip. 

 

 

 

Last Edited: Thu. Mar 29, 2018 - 05:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Have you tried Atmel Start?   See what code it generates for you and pick out what you need from that.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

ledi001 wrote:
But the AVR1 series like ATtiny817 are very different with the naming and handling with their registers.

I don't disagree, and don't have any direct experience with that new family.  Let's see if the datasheet gives any hints for mere mortals...

PowerDown

Only the WDT is enabled.
The only wake-up sources are the pin change interrupt and TWI address match.
 

So old 'Freaks can grasp using pin change for wakeup.  And the next hit on "pin change"...

Asynchronous pin change sensing that can wake the device from all sleep modes
 

...so that sounds like the right track.  And Atmel/Microchip put out theis new Xtiny series with a bit of fanfare without giving any simple interrupt examples?!?  Those b******s.

 

The PORT also supports synchronous and asynchronous input sensing with interrupts and events for
selectable pin change conditions. Asynchronous pin-change sensing means that a pin change can wake
the device from all sleep modes, including the modes where no clocks are running.
 

So it looks like an event is triggered?  The next search hit

indicates that for each port, there is an INTFLAGS register with a bit for each pin.  Let's see if the "refer to" is the next search hit...nope; no more hits.  For ISC

...so I'd guess that INTDISABLE should be off (if like AVR8 needing an enabled interrupt source to wake up), and pick the edge(s).

 

Now, how does one then connect that to an event?

 

 

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Guys,

 

now i solved the problem with the new ATtiny817 controller:-)

 

In this example a push button on PC3  triggers an external interrupt with falling edge. The pushbutton is pulled-up with an internal resistor to high level.

Please note, a push button basically is bouncing and therefore a few interrupts can be generated by one button press.

 

Hope this code snippet will help others:

 

#include <avr/io.h>
#include <avr/interrupt.h>


int main(void)
{
	PORTC.DIRCLR = PIN3_bm;						// Pin PC3 = input
	PORTC.DIRSET = PIN0_bm;						// Pin PC0 = output
	
	PORTC.PIN3CTRL = PORT_PULLUPEN_bm;			// enables the internal pull-up resistor on PC3				
	PORTC.PIN3CTRL |= PORT_ISC_FALLING_gc ;		// Sense falling edge on PC3. PORT_INT3_bp = 0x03
	
	// CPUINT.LVL0PRI = 0 << CPUINT_LVL0PRI_gp;		// Interrupt Level Priority: 0
	// CPUINT.LVL1VEC = 0x0A << CPUINT_LVL1VEC_gp;	// Interrupt Vector with High Priority: 0x08

	sei();										// Global interrupts enable

	while (1)
	{
		
	}
}

ISR(PORTC_PORT_vect) 
{
	PORTC.OUTTGL = PIN0_bm;					// Toggle LED
	PORTC.INTFLAGS |= PORT_INT3_bm  ;		// Clear Interrup Pin Flag, must do this to handle next interrupt
}

 

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

Hi,

 

I tried using your code but a ran into a few issues.
 

So I used ports PA2 OUTPUT, PA6 INPUT + pull-up enabled

 

PA6 is reading correctly when the switch is going high and low, the interrupt flag is being triggered as well. However, I don't think that my interrupt is working. The interrupt flag is not getting cleared and the LED on PA2 is not turning on either.

Another error I see is that the sei() is coming up as unknown. I did include the same libs btw.

 

Please help.

Is there an interrupt enable on PA6 that I am missing?

April Inamura

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

ania wrote:
I tried using your code

Note that you are replying to a post that's over a year old!

 

 

Another error I see is that the sei() is coming up as unknown.

What do you mean by that?

 

Surely that's a build error? If you're getting build errors, then you don't have any code to run!

 

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

awneil wrote:
Surely that's a build error? If you're getting build errors, then you don't have any code to run!

 

Indeed. How could the code be tested, if sei() was not recognized? In that case the code wouldn't compile.

 

Anyway, this sentence is basically meaningless:

ania wrote:

Another error I see is that the sei() is coming up as unknown.

 

If you have errors, just copy them and post.

Last Edited: Mon. Dec 9, 2019 - 11:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I got my code to work.

I went into avr/interrupt.h and found the definition of sei(). That's it. When I went back to my main code, sei() wasn't underlined with red anymore. I don't get it.

As for the interrupt, I just needed to press play. I was stepping through the program individually with the debugger and it wasn't working for whatever reason. As soon as I pressed upload and run it was working.

 

I've posted my code down below. I wrote it to interrupt two different interrupts on the same port to drive a motor.

April Inamura

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

ania wrote:

 When I went back to my main code, sei() wasn't underlined with red anymore. I don't get it.

 

Yeah, this is a known bug. The syntax highlighter used by Atmel Studio sometimes doesn't recognise stuff that it should, inducing people in error. These "errors" are fake news.