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?
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
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.