Attaching an interrupt. TWI

Greetings,

I am a bit stuck on understanding some of the underlying infrastructure. I was playing with ADC and was able to add an interrupt handler as simply as:

ISR(ADC_vect) { // My stuff here. }

But I have been unable to get a TWI interrupt service routine to be called. Can anyone confirm that the following should work:

ISR(TWI_vect) { // My stuff here. }

Is there some other way to declare a TWI interrupt? Is there any documentation on the "ISR" preprocessor scheme? I know that TWI is the 25th vector on my Atmega328P. Any guidance would be helpful.

Thanks in advance, Brian.

Doesn't onReceive(handler) and onRequest(handler) do what you need? http://arduino.cc/en/Reference/Wire

I'm attempting to do a number of things which include - Profiling - Reducing Dependencies - Squeezing out every byte of storage and performance - Pushing configuration offline instead of at runtime

The only reason I ask here is that I don't quite understand the dependencies that are hi-jacking the interrupt vector. I assume the boot loader contains the vector table and has some mechanism to forward the interrupts on to user defined handlers.

Is there a reason why this wont/doesnt work:

ISR(TWI_vect) { // My stuff here }

Cheers, Brian.

I'll assume the answer to my question is "no". I'll also assume you know that twi.c in the wire/utils folder is already using SIGNAL(TWI_vect) so that it can create an ISR defined by onReceive and onRequest.

Yah, my answer was roughly, "no".... Its all mostly due to my own desire to really punish myself/learn. :) And to squeeze every bit of performance I can.

I did see that SIGNAL.. But I can't tell what is behind that. Why is "ISR" used for ADC and "SIGNAL" used for TWI?

Is there a good description of ISR versus SIGNAL? Ill do a search for that.

Oh, and for the record the following works as I expect too:

ISR(TIMER2_OVF_vect) { // My stuff }

I just don't know why the following doesn't seem to work. Should it work? ISR(TWI_vect) { // My stuff here } I can double check interrupt enables and other stuff. I see toggling on SDA and SCL with my logic analyzer.

I use the Atmel TWI code and interrupts in my RTC library. The RTC and TWI library are at

http://wiblocks.luciani.org/PICO/index.html

(* jcl *)

legerde: I did see that SIGNAL.. But I can't tell what is behind that. Why is "ISR" used for ADC and "SIGNAL" used for TWI?

Is there a good description of ISR versus SIGNAL? Ill do a search for that.

From interrupt.h:

This is the same as the ISR macro without optional attributes. (deprecated) Do not use SIGNAL() in new code. Use ISR() instead.

So, they are very similar. Look at the code for the exact differences ... or see below:

#ifdef __cplusplus
#  define ISR(vector, ...)            \
    extern "C" void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__; \
    void vector (void)
#else
#  define ISR(vector, ...)            \
    void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__; \
    void vector (void)
#endif

and

#ifdef __cplusplus
#  define SIGNAL(vector)                   \
    extern "C" void vector(void) __attribute__ ((signal, __INTR_ATTRS));  \
    void vector (void)
#else
#  define SIGNAL(vector)                   \
    void vector (void) __attribute__ ((signal, __INTR_ATTRS));        \
    void vector (void)
#endif

I have some new information. I started a new project and got the interrupt to work. I believe my problem may be that at one time I include "Wire.h". Even though I don't include it now, I believe the build process is "still" including things that are causing breakage.

How do I do a "clean" build?

How about making a test case that reproduces the problem, and post the error message? Or at least the lines from your existing code that cause the problem, and the error message?