Usart Interrupt for receiving data

Hello, I'm trying to figure out if I can somehow set a variable High with an interrupt when I have available data to receive in my Usart and then in my loop check if the variable is HIGH to actually parse the data incoming?

If someone could give some lights i would be really grateful! Thanks!

luisaraujo123:
Hello, I'm trying to figure out if I can somehow set a variable High with an interrupt when I have available data to receive in my Usart and then in my loop check if the variable is HIGH to actually parse the data incoming?

If someone could give some lights i would be really grateful! Thanks!

If I understand the question, you have some remote device that will send a digital signal to the Arduino that is is preparing to send data. And you want to watch for that signal for some reason. Am I close?

Paul

If you're using the Arduino framework and a serial device,the interrupt is handled for you.

As mentioned, the interrupt is already handled and the "variable" you want is available():

 if (Serial.available() > 0) {

  }

gfvalvo:
As mentioned, the interrupt is already handled and the "variable" you want is available():

 if (Serial.available() > 0) {

}

Yes you are absolutely right, but now i have other problem can I find out when all my data has been transfered through the TX pin?

When Serial.flush returns.

luisaraujo123:
Yes you are absolutely right, but now i have other problem can I find out when all my data has been transfered through the TX pin?

I think this works for non-blocking test:

if (Serial.availableForWrite() >= SERIAL_TX_BUFFER_SIZE-1)
  ....

(You might need to wait for the last byte to go out in hardware though).

Is this for a half-duplex RS485 bus perchance?

Oh, BTW for serial input you can use the serialEvent() mechanism to handle incoming characters independently from loop():

void setup()
{
  Serial.begin (115200) ;
}

void serialEvent ()
{
  char ch = Serial.read() ;
  Serial.println ((int)ch) ;
}

void loop() 
{}