So, I am working on a Arduino Mega 2560 for a project that will be making use of 3 of the USART connections. I was originally using the HardwareSerial library. I knew there were certain libraries to avoid such as digitalwrite for time critical programs but I didn't think this applied to the Serial libraries until I was recently told that it is. Is this true? I've been trying to learn the names of all the registers and what they do and trying to write my own library but it's taking up alot more time than I had hoped. Should I keep trying to write my own Serial library or was my friend mistaken and the Arduino Serial libraries are fine. Also I think one of the serial connections will have to be interrupt driven, is this even possible using the Arduino libraries or would that one have to be customized as well for my use? Thanks for any help and sorry if this is posted somewhere else, I couldn't find anything pertaining to this except some tutorial explaining how to start my own.
Avoid Arduino HardwareSerial?
I was recently told ...
Who told you?
How did they justify it?
The hardware serial is actually using interrupt driven ring buffers. It's about the best implementation you could hope for when using UART (guarantees you never miss anything and transmission just occurs "in the background") so I don't know who told you this but like Andy I'd love to hear their justification!
or was my friend mistaken and the Arduino Serial libraries are fine
This.
will have to be interrupt driven, is this even possible using the Arduino libraries
As I say, one of the joys of Arduino is that on this occasion they made the right choice at implementation and decided to already implement it using interrupts for both Tx and Rx. Saves you a LOT of work!
Also think about it - there are 100's of 1,000's of Arduino applications out there - a large proportion will be using the serial. Apart from your mate did you ever here anyone complain? (same cannot be said of pinMode and digitalWrite - we complain about that all the time!).
It really wasn't an argument. It was more of a "I believe it's no good and you should double check that" kind of thing. The only one I was aware of was the pinMode/digitalWrite but I don't have a ton of experience programming microcontrollers. So It made sense that there could be more Arduino libraries to avoid than just those two. Thanks for your help though.
I suggest that you just try a library for yourself. Come to your own conclusions.
Most "core" libraries are very efficient. Likewise third party libraries written for specific Shields can use hard code wiring. e.g. can assume that the SPI pins or I2C pins are connected to your external electronics.
It is when people are determined to use inappropriate pins that third parties have to bit bash GPIO pins instead of using the proper hardware. Convenient yes, efficient no.
David.