Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

ATMega1284p External Interrupt 2 Setup

ATMega1284p External Interrupt 2 Setup

2012-03-13 by Chuck Hackett

I am trying to enable external interrupt 2 to trigger on a falling edge on
an ATMega1284p but I am unable to get the proper bits in the EICRA register.
I'm using the following:

(1) EIMSK &= ~_BV( INT2 );				// Disable external
interrupt 2
(2) EICRA &= ~(_BV( ISC21 ) | _BV( ISC20 ));		// Clear the
external interrupt 2 control bits
(3) EICRA |= (_BV( ISC21 ) /*| _BV( ISC20 )*/);		// Setup interrupt 2
for interrupt on falling edge
(4) EIFR |= _BV( INTF2 );				//  Clear any
pending interrupt
(5) EIMSK |= _BV( INT2 );				// Enable external
interrupt 2

(Yes, I know that lines 2 & 3 can be combined but I split them in an attempt
to diagnose the problem)

A JTAG breakpoint at line 4 shows the EICRA register unchanged from its
initial value of 0x00 ...

ISC21 has a value of "5" ...

Even if I replace line 3 with "EICRA = 32" the register remains unchanged
...

When I look at the disassembled code it appears to be storing to location
0x69 (the EICRA reg) ...

It is as though there is some control bit that I have to turn on to enable
changes to the EICRA register ...

Note: at this time Global Interrupt Enable happens to be disabled (it is
enabled later in the code).

This is code that is being converted from an ATMega32 where it is working
fine just using:

GICR |= _BV( INT2 ); // Enable interrupt on (default) falling edge of
external interrupt 2

I know that this has to be something simple and I've read the datasheet
section on external interrupts over and over.  Can someone point out where
I'm going wrong?
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

RE: [AVR-Chat] ATMega1284p External Interrupt 2 Setup

2012-03-13 by Chuck Hackett

> From: Chuck Hackett

Added info:

I am using AVR Studio and a Dragon for the JTAG debug connection.

If I attempt to change the EICRA register with AVR Studio it changes but is
back to 0x00 after the next statement execution (the statement does not
modify the EIARA register).

......

Just found the (non) problem:  Apparently AVR Studio (Version 4.18, build
716) has a bug in it?

The EICRA always shows 0x00 but my interrupt seems to be working fine ...

So, I wasted an hour on a non-problem ...
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

RE: [AVR-Chat] ATMega1284p External Interrupt 2 Setup

2012-03-13 by Chuck Hackett

> From: Chuck Hackett
> ....
> Just found the (non) problem:  Apparently AVR Studio (Version 4.18, build
> 716) has a bug in it?
> ....

False alarm, the interrupt is still not working so I'm guessing that the
EICRA register really isn't getting set and is still 0x00 ...

So original question still stands:  Why can't I set the ISC2x bits in the
EICRA register?
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

RE: [AVR-Chat] ATMega1284p External Interrupt 2 Setup

2012-03-13 by Chuck Hackett

> From: Chuck Hackett
> ....

Sorry for talking to myself so much :-)   ...

I placed "uint8_t test = EICRA;" after setting EICRA and "test" did have the
expected 0x20 in it ... but AVR Studio still shows the EICRA as 0x00 so I
think I've confirmed that the Dragon or AVR Studio has a problem ...

My Interrupt still doesn't work but at least the EICRA is set correctly but
first I'll get the scope out to be sure that the pin is actually changing
(driven by an MCP2515 CAN controller).

Sorry for the false alarm(s) ...
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

RE: [AVR-Chat] ATMega1284p External Interrupt 2 Setup

2012-03-13 by John Samperi

At 02:18 AM 14/03/2012, you wrote:
>Sorry for talking to myself so much :-)   ...

That's not what's worrying me, the answering to yourself is
a sign of madness they say... :-)

I don't have one of those chips but I may be able to try it
on a M644p a little later.



Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

RE: [AVR-Chat] ATMega1284p External Interrupt 2 Setup

2012-03-14 by Chuck Hackett

> From: John Samperi
> ....
> >Sorry for talking to myself so much :-)   ...
> 
> That's not what's worrying me, the answering to yourself is a sign of
> madness they say... :-)

Darn, you obviously know me ... :-)

> I don't have one of those chips but I may be able to try it on a M644p a
little
> later.

The status of things:  My code is now working but AVR Studio/Dragon still
will not show EICRA as anything other than 0x00 in either the "Register",
"Flat Register View" or the memory "Extended I/O" displays.  I can change it
with AVR Studio but if you then step, etc. the display returns to 0x00.

Since my code is working and loading a test variable with the EICRA value
shows a correct value I'm sure that it is AVR Studio/Dragon which is causing
the problem.
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.