Arduino and interruptions

Hi, i´m exploring arduino interruptions and I need some help.

I was looking for a timer interruption and I found this one the question is if that timer is used for other things like serial baud rate generator, delay function , PWM generator ,or one wire communication ?

Is there any kind of way to get a serial port interruption, like on receive event it will call a function? and the 128byte serial buffer it´s hardware or software buffer?

Will interruptions cause colisions used at same time? like using serial port and external interruption will causa data corruption on serial communication? Do the interruptions have the same priority?

Tanks to all arduino contributors 8-)

You can use timer2 interrupt. It is used for PWM, so you will lose PWM if you use it. Its not used for the serial port.

The way to use the serial port is to put something in the main loop like

if (Serial.available())
c =;

That runs pretty fast (according to my timings in my main loop about 600 microseconds round the loop).

The 128 byte serial buffer is a receive buffer; the transmit is 1 character at a time. You can see the code in the libraries.

The fragment below is how I am using Timer 2 interrupt, which is for a software serial implementation.

Its generally a bad idea for one interrupt to block another. Use short interrupt routines that set volatile flags. That way the hardware serial will keep working, and the millis() timer will keep accurate.

Look at the SoftwareSerial and TimerSerial libraries for how other people use interrupts.

You can also attach an function to an interrupt on a rising or falling pin (pins 2 and 3 only I think).

#include <avr/interrupt.h>
#include <avr/io.h>

#define INIT_TIMER_COUNT 46  // see scaling spreadsheet for value

// call this from setup
void setup_interrupt()
  //Timer2 Settings: Timer Prescaler /64  CS22 only
  TCCR2B |=  (1<<CS22);
  TCCR2B &= ~((1<<CS20) | (1<<CS21));
  TCCR2B &= ~(1<<WGM22);

  // Use normal mode
  TCCR2A &= ~((1<<WGM21) | (1<<WGM20));
  // Use internal clock - external clock not used in Arduino
  ASSR &= ~(1<<AS2);
  //Timer2 Overflow Interrupt Enable, clear the two output compare interrupt enables
  TIMSK2 |= (1<<TOIE2);
  TIMSK2 &= ~((1<<OCIE2A) | (1<<OCIE2B));

ISR(TIMER2_OVF_vect) {
  // read the input pin anyway, might use later, but timing more accurate here
  // direct port read is faster then digitalRead()
  byte_in_read_pin = PINB & 0x01;
  //byte_in_read_pin = digitalRead(rdbackPin);
  if (sw_tx_mult_counter++ >= sw_tx_mult_constant) {
   // do other stuff