go_away

Author Topic: I2C ISR problems  (Read 3091 times)

0 Members and 1 Guest are viewing this topic.

Offline AsellithTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 648
  • Helpful? 9
  • "I'm a leaf on the wind. Watch how I soar"
I2C ISR problems
« 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?
Jonathan Bowen
CorSec Engineering
www.corseceng.com

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: I2C ISR problems
« Reply #1 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

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)
« Last Edit: January 01, 2010, 10:17:28 AM by rgcustodio »
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline AsellithTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 648
  • Helpful? 9
  • "I'm a leaf on the wind. Watch how I soar"
Re: I2C ISR problems
« Reply #2 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.
Jonathan Bowen
CorSec Engineering
www.corseceng.com

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: I2C ISR problems
« Reply #3 on: January 01, 2010, 12:44:11 PM »
Goodluck.
I haven't used the webbot library. Sorry.
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: I2C ISR problems
« Reply #4 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;
}
---
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

 


Get Your Ad Here