This is a C source code I wrote to do serial read/write on an
Atmel AVR 328p microcontroller.
This is the same processor as the Arduino Uno for example. It is part of a growing collection of
AVR routines.
And since you can set your own limits, you can use this code in place of the usual Serial class, as the default buffers are quite small and they may overflow if you are not processing them fast enough, or if you are sending too much data at once (eg. file copy/paste). Note that some terminals let you set add a small delay automatically after each line is sent, which is the way to go so as to leave enough time for your program to process the incoming flow.