Society of Robots - Robot Forum

Software => Software => Topic started by: Asellith on January 01, 2010, 08:23:22 AM

Title: I2C ISR problems
Post by: Asellith on January 01, 2010, 08:23:22 AM
Ok I got some code from atmel as a  example and I am dissecting/modifying it to work as a simple I2C slave. Problem is I don't know how to define an ISR in AVR studio with winavr.

Code: [Select]
#pragma vector=TWI_vect
__interrupt void TWI_ISR( void );

that is what Atmel used but they use a different compiler. So my code ignores that statement and spits out an error on the second line. How do I define the TWI_ISR for this?
Title: Re: I2C ISR problems
Post by: rgcustodio on January 01, 2010, 10:14:47 AM
This should get you started for WinAVR and avrlibc:
http://winavr.scienceprog.com/avr-gcc-tutorial/avr-microcontroller-interrupts-handling-using-winavr.html (http://winavr.scienceprog.com/avr-gcc-tutorial/avr-microcontroller-interrupts-handling-using-winavr.html)

Code: [Select]
#include <avr/interrupt.h>

ISR(TWI_vect)
{
  /* your code here */
}

don't forget to properly setup your MCU type because interrupt.h does some magic behind the scenes ...
if you don't define your MCU type properly you might get compile errors ... which might be caused by interrupt.h not including the correct header files ... not all AVRs support TWI (or I2C)
Title: Re: I2C ISR problems
Post by: Asellith on January 01, 2010, 12:24:38 PM
I just need to stop being lazy and write this stuff from scratch. I'm using webbots library and his frame work and I need to just figure out how to control the TWI interface from scratch. Thanks for the link looking at it now.
Title: Re: I2C ISR problems
Post by: rgcustodio on January 01, 2010, 12:44:11 PM
Goodluck.
I haven't used the webbot library. Sorry.
Title: Re: I2C ISR problems
Post by: rgcustodio on January 05, 2010, 04:57:18 PM
I was just browsing through the Webbot library.
It seems it uses GCC style ISR handling...

crossreference a2d.c
---
// Interrupt handler for ADC complete interrupt.
#ifndef ADC_vect
#  error Missing ADC_vect
#endif
ISR(ADC_vect)
{
   // set the a2d conversion flag to indicate "complete"
   a2dCompleteFlag = TRUE;
}
---