Setting serial interrupt vectors

Hi

Bit of a dumb question this. I am new to using the Arduino although I have done plenty of assembly programming for embedded projects in the past.

I am choosing not to use the Serial library and create my own serial handling, I like to know EXACTLY what is going on and its all part of the learning process.

Most of what I have seen is perfectly logical but how on earth do I set the serial data ready interrupt to my own interrupt routine?

Thanks

from this page on the 328P you can see

---

19 USART Rx Complete USART_RX_vect
20 USART Data Register Empty USART_UDRE_vect
21 USART Tx Complete USART_TX_vect

which you’ll find is used in HardwareSerial0.cpp for example

Most of what I have seen is perfectly logical but how on earth do I set the serial data ready interrupt to my own interrupt routine?

The answer is more than likely within the files that normally take care of this, being HardwareSerial.h .cpp & mainly in HardwareSerial0.cpp

Excellent, thanks for the help.

This tutorial deals with UART1 Port of MEGA without using the Library Functions. This sketch uses register level instructions to exchange data with phone via Bluetooth (Fig-1) on RX1-ready interrupt.

1. Hardware Setup
hc5Mega.png
Figure-1:

2. Upload the following sketch.

volatile char x;
volatile bool flag = false;
void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  //--configure UART1 of MEGA---
  UCSR1B = 0b10011000;  //RX1 int enable, RX1/TX1 enable
  UCSR1C = 0b00000110;//async mode, no parity, 1-stopbit, 8-data, RE/FE=TX1/RX1
  //-Bd = 9600-------------
  UBRR1L = 0x67;       //9600 bits/sec
  UBRR1H = 0x00;
  //--global int enable--
  bitSet(SREG, 7);
}

void loop()
{
  if (flag == true)
  {
    Serial.print(x);
    flag = false;
  }
}

ISR(USART1_RX_vect)
{
  //digitalWrite(13, HIGH);  //for debugging purpose
  x = UDR1;    //recive from phone via BT
  UDR1 = x;    //sending to phone via BT
  flag = true;
}

3. Pair BT and Phone.

4. Send S from Phone and check that it (S) has appeared on Serial Monitor (Fig-2) and Phone.

3. Serial Monitor of MEGA
sml.png
Figure-2:

hc5Mega.png

sml.png