how to use serial interrupt in arduino instead of polling if(Serial.available)?

I have seen some functions for timer interrupt in ardunio.

Timer1.attachinterrupt(function) // function on ISR
Timer1.Start(timeinmicroseconds)

Is that anything available for serial attach interrupt?

i need to do serial communication faster. instead of polling, i need to go for serial interrupt.but i am not getting how to use serial interrupt in arduino Micro.

Thanks

Have you read this?

i need to do serial communication faster.

Maybe your sketch is slowing this down by the way it is written.

alagappan:
I need to do serial communication faster. instead of polling, I need to go for serial interrupt.but I am not getting how to use serial interrupt in Arduino Micro.

It is most improbable that you can perform some task faster than polling Serial.available (unless you propose to code your own in raw assembler). You may not realise that the serial driver is already buffered.

Here we go again - the "XY problem". :roll_eyes: You might do better if you explain what you are actually trying to do and - show your present code attempts to do this.

I hope you realise that serial handling is already interrupt-driven?

Buffering is performed by serial interrupts.

The serial interrupt is used internally to fill the rx buffer. This is what you're looking at when you use Serial.available, and what you're reading from when you do Serial.read().

As a consequence, you cannot add an interrupt onto that without removing or rewriting the Serial class so that it didn't use the interrupt itself, since you can only have one ISR for any given interrupt.

Also, in light of that, I can't think of any reason to want to do that, since the time-critical stuff is already being handled by the interrupt.

Unless your loop is running slowly because you're abusing delay, but in that case the fix is to fix your code - loop() should be running hundreds or thousands of times per second under normal circumstances.

alagappan:
<…>
i need to do serial communication faster. instead of polling, i need to go for serial interrupt.but i am not getting how to use serial interrupt in arduino Micro.

Thanks

@alagappan:

You have 2 basic choices:

If you are already fairly certain that your sketch is working optimally as written, move up the Arduino line of boards to a faster, more powerful platform.

Ray