0

So Arduino Mega has Serial, Serial1, Serial2, Serial3.

However, does those Serial lines use the same buffer? or four independent ones? i.e. are they truly receive single independently, or actually some sort of software sharing? How will that affect the coding?

3
  • 1
    what problems have you encountered?
    – jsotola
    Commented Feb 5, 2020 at 3:02
  • @jsotola Not yet, but I'm trying to use UART to do a fast control system with distributive components. So there would be lots of data in ms circles in multiple ports at once. Basically, I'm trying to use over flow of data to establish fast and reliable processing... and it's kind of good to know how that buffer was working. Commented Feb 5, 2020 at 3:19
  • makes sense to be proactive .... you could run a test by feeding the same data to all three ports and read the data at varying speeds from the three ports .... you could connect the three receive pins together .... read in random sized chunks
    – jsotola
    Commented Feb 5, 2020 at 3:27

2 Answers 2

2

Actually there are 2 buffers per Serial hardware interface: The hardware buffer, that is 1 byte (per direction of data transfer). The Serial library then transfers this byte in an extra buffer (64 bytes big) from an ISR. Every hardware Serial interface (Serial and Serial1 to 3 on the Mega) has it's own hardware buffer.

Then the Serial library is implemented as a class. Every hardware Serial interface get's it's own instance of this class, including the 64 byte buffer.

So the hardware and the memory is completely seperated. The only thing, what they share, is the CPU time for servicing the interrupts, which is no problem, until you are doing somehting very wrong with interrupts.

1

Every instance of class HardwareSerial has own buffers. Here you can see it in source code. The instances are declared/definded at the end of the HardwareSerial.h/.cpp.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.