newbie stuck with interrupts - atmega168

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

Hello guys!

I'm having problems with pin-change interrupts. I can't make them work any of the ways I've tried so far.

I'm using avrisp2 with avdurde with no apparent errors (read, writes and verifies ok), onto linux and with gcc as the toolchain.

Perhaps it is because I'm too new to this, but the following phrase confused me a lot within the specs:

"The External Interrupts are triggered by the INT0 and INT1 pins or any of the PCINT23..0 pins."

From the point of view that I don't know whether I should even enable external interrupts (or it's config) registers if willing to use just the pin-change ones, or if I ougth to say ISR (INT0_vec) or ISR (PCINT0_vec); tried with both anyways, among may other things.

This is the code I'm using:

http://pastebin.ca/1206842

It is commented. I pasted there the command-line I'm using, and there's an #ifdef region with code that works.

About the hardware, all vcc/avcc/vss are connected, have a led on PORTC5, and an omrom switch on PORTB1, which by default let the current flow till it's pressed.

And that's all, I'd really appreciate if someone could tell me something about.

Many thanks.

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

One thing I noticed in your code which would cause a problem:

You enable both PCINT0 and INT0, but you only have a handler for PCINT0. For undefined ISR handlers, GCC will reset your program. INT0 is on pin PD1. If this pin is left floating, you will likely be getting interrupts from it which will keep resetting your program.

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

General comments about pin-change interrupts. They are NOT the same as INT0 and INT1 where you can select the edge, you will get an interrupt every time the pin changes, up or down. So your code will need to deal with this by ingoring the unwanted edge.

In order to use them you will need to enable the correct group interrupt and use the correct input(s) mask. ie

	PCICR |= (1<<DS3232_int_group);				//Enable group interrupt for RTC
	DS3232_PC_mask_group |= (1<<DS3232_int);	//Enable interrupt for RTC	

where things are defines in this project as:

//Define pin change interrupt bits and groups
#define DS3232_int PCINT29			//DS3232 seconds interrupts
#define DS3232_int_group PCIE3
#define DS3232_PC_mask_group PCMSK3

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly