Interrupt Vectors

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

Hi,

 

I'm new to Atmel Studio 7.  Can someone tell me how to setup the interrupt vectors for an ATmega328 (using C code)?

 

I need an interrupt for Timer/Counter2 Compare Match A.

 

Thanks,
Dan

 

This topic has a solution.
Last Edited: Wed. Sep 13, 2017 - 01:46 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

This is how I prototyped the ISR in my .h file:

 

void ISR(TIMER2_COMPA_vect);

 

However, the compiler is giving me an error.  Obviously, I have left something out.

 

And, as you may have guessed, I'm not a C programming expert.

 

Thanks,
Dan

Last Edited: Wed. Sep 13, 2017 - 01:32 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You don't prototype ISRs... Just think a bit, why would you need to prototype it? (Also, make a habit of providing what error you get... Usually makes it easier to understand what is going on...)

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

Last Edited: Wed. Sep 13, 2017 - 01:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Obviously, I have left something out.

An 'R', matey.

ISR(TIMER2_COMPA_vect);

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Wed. Sep 13, 2017 - 01:40 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As I said, I'm not a C programming expert.  But, I really do appreciate your help.

 

Thanks again,

Dan

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

But it should still be obvious that, to help you with "an error" from the compiler, we are going to need to know what, exactly, that "error" was - aren't we?

 

It's like saying, "a light came on in my car - what does it mean?" - clearly, anyone is going to need to know what light it was in order to give any suggestions!

 

The way way to do this is to copy the entire message from Atmel Studio and paste it into the forum - never try to manually re-type stuff.

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

meolsen wrote:
You don't prototype ISRs... Just think a bit, why would you need to prototype it?

Well, I guess we all can infer which toolchain is being used.  And indeed the expansion of ISR() with the chosen toolchain may not be swallowed as a "prototype".

 

That said, with a different AVR8 C toolchain I indeed prototype my ISRs.  True enough, they will be void functions with no parameters.  But IME it helps to catch mis-spelled vector identification.  YMMV.

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.

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

In GCC "ISR" is a macro:

#  define ISR(vector, ...)            \
    void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__; \
    void vector (void)
#endif

So that is a declaration immediately followed by the definition.

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

Shive me timbes!  You'e ight!

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

clawson wrote:
So that is a declaration immediately followed by the definition.

But--but--but--

meolsen wrote:
You don't prototype ISRs... Just think a bit, why would you need to prototype it?

No wonder old guys are accused of being confused.

 

"Mongo just pawn in game of life." -- Blazing Saddles

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.

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

The point is you cannot use:

void ISR(SOME_vect);

(as OP tried) because the macro would expand out as:

void  void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__; \
      void vector (void);

Too many voids there for the compiler's liking methinks.

 

The misunderstanding here comes from the fact that "ISR(...)" looks like a "function" but isn't.

 

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

clawson wrote:
The point is you cannot use:

The point is, that as you said, the macro IS the declaration (prototype), followed by the start of the definition.

 

The point is, as the ISR() mechanism essentially creates a prototype, then

meolsen wrote:
You don't prototype ISRs... Just think a bit, why would you need to prototype it?

...with respect to this particular toolchain doesn't seem to hold much water.

 

Now, does OP really want to expand

 void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__;

into a "proper" prototype?  Dunno.

 

void __vector_13 (void) __attribute__ ((signal,used, externally_visible)) ; 

 

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.

Last Edited: Wed. Sep 13, 2017 - 06:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

... I was thinking from the C perspective, but if you want to split hairs then yes, I glossed over the macro detail..

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

dps wrote:
Shive me timbes! You'e ight!

 

If ye don't mind ye arr's your bound to be eft

 

JIm

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user