1

It might be an obvious answer to this, but I can't find it via a quick google search. To give my question a bit of more context, I'm writing an application which simulates a communication with Arduino via serial port, therefore I need to know how it is implemented internally.

From my previous experience with micro-controllers, the serial port is normally presented in micro-controller as two separate queues, one for TX and another for RX. For transmit out of MC, my software writes a byte to the end of transmit queue, and MC hardware reads byte from the beginning of the queue, converts it to bits, and toggles the pin to transmit data/parity/stop bits. And it keep doing that until queue is exhausted. The opposite happens for receive queue.

Am I right in assuming that Arduino has similar implementation with two separate queues? In particular, I want to read and write to serial port simultaneously.

zmechanic
  • 121
  • 5

2 Answers2

1

Yes. Arduino has two buffers. See the HardwareSerial.h and HardwareSerial.cpp

Gerben
  • 11,332
  • 3
  • 22
  • 34
0

I have a lengthy post about Arduino serial communications: How does serial communications work on the Arduino?

In short, the hardware (on an Atmega328 like on the Uno) has a two-byte receive queue (so you can be putting one byte into memory while the next byte is being received). It has a one-byte send queue.

Lengthier queues are implemented in software using interrupts to move data from the RAM queues in/out of the hardware queues.

Nick Gammon
  • 38,901
  • 13
  • 69
  • 125