If I'm reading data from multiple channels (UART) of a microprocessor, but I want it to be continuously read, I imagine the logical thing to do would be to cycle through the channels and output data, while, similarly, cycling through the inputs on the software-side of the receiving computer and reading them and inputting them into separate buffers. But, I find it hard to believe that the computer and the microprocessor send and and receive data in perfect synchronicity, thus it would make sense that each data might be attached to some sort of "tag" to identify its source channel as it comes through to the computer.

How would one go about doing that, because I imagine attaching tags as I surmised above would slow down performance on the computer's ability to read a large volume of signals as it then has to parse the data for these tags? This is just a logical guess on my part as to how this effect would be achieved though, so maybe there is a better way to do this that is totally different.

  • 1
    \$\begingroup\$ What do you mean by channels? If they are UART, answer would be completely different from if they are TCP ports, for example. And (at least) one of these examples is off-topic. \$\endgroup\$ – dim Jun 24 '16 at 17:58
  • \$\begingroup\$ Thanks, that was my bad, I mean UART. I'll edit the question \$\endgroup\$ – Scorch Jun 24 '16 at 18:02
  • \$\begingroup\$ Doesn't the 'A' in UART mean "asynchronous"? By definition they won't be "in perfect synchronicity". \$\endgroup\$ – Transistor Jun 24 '16 at 18:15
  • \$\begingroup\$ The only thing that the computer and the microprocessor have in common is the baud rate configured. The data is not in perfect sync as pointed out by @transistor. If you want to read data from multiple UART modules of a microcontroller (if that's what you mean), I'd suggest using different serial cables and USB ports to do that. Yes if you want to use one serial interface, you can format it such that the data from one channel contains a preamble info (like 'channel' number), but you can never get rid of collisions unless you really develop a protocol for that in the microcontroller firmware. \$\endgroup\$ – U. Muneeb Jun 24 '16 at 19:01
  • \$\begingroup\$ Your question is ambiguous and confusing. If your PC is receiving data from several serial ports then each one should be serviced separately and there would be no need for 'tagging' to identify them. But you talk about 'cycling through channels'. Do you have multiple serial cables ('channels') between the MCU(s) and PC, or are you actually trying to receive data from several input channels on the MCU via a single serial port on the PC? \$\endgroup\$ – Bruce Abbott Jun 24 '16 at 23:54


  • There is no need for such tagging. There is simply one buffer for each "channel", at predetermined locations (or dynamically allocated by the OS, but it doesn't matter). So we know where the data received by each channel is in RAM.
  • The processor can indeed send and receive data simultaneously (if this was what you meant by "synchronicity").
  • Throughput performances can be guaranteed.

The question is a bit confused, so I'm not sure I can identify the level of what you understand and the point where you start being lost. So I'll try to explain from the beginning.

So, first, what's in a microprocessor? There is a lot of sub-blocks in there, not just a CPU. Each UART is another block, for example. And each block can work independantly from the others. They can all work in parallel.

Now, what happens when a byte arrives to an UART? The UART reads the byte, bit per bit, and when the complete byte has been read, places it in a hardware register. It also notifies the CPU (through an interrupt) to tell it that there is a byte available. From there, the UART doesn't care what happens to this byte anymore. The next UART job is to be ready for the following byte that is coming.

The CPU, however, has been notified, so, hopefully, the firmware has been made in order to trigger an appropriate routine when the UART interrupt is triggered. This routine will get the byte from the register (located at a specific address, decided by the chip manufacturer) and copy it in a buffer somewhere in RAM (located at an address, within the RAM space, decided by the firmware developer: you). The CPU will then, maybe, update some variables in the program to know how many bytes have been read, eventually switch to a new buffer if it's full, etc, ... and go on with the other tasks he has to do.

What happens when multiple UART are working in parallel? First, bytes don't have to be synchronized between all UARTs, because each UART is independant. So the bytes can arrive when they want. When a byte arrives, the UART will trigger its own interrupt, so the CPU will know which UART has received a byte (on some MCUs, multiple UART can share the same interrupt, but there is always a way to check which UART has actually received the byte, through some control registers). Then, the interrupt routine, once the UART has been determined, will read the appropriate register, because each UART has its own receive register. So the CPU will get the byte, knowing from which UART it comes. Then it will copy the byte in the appropriate buffer, because each "channel" should have its own buffer. So you see that there is at no point a need for "tagging". It's just that the bytes from each channel end up in different predetermined locations in memory.

Then, maybe, once enough bytes have been grabbed, you need to output it to some other UART. It works the same. The CPU will tell the output UART to send a byte by placing the byte value in a specific hardware register. And the UART will warn the CPU through an interrupt when the transmit has completed, so the CPU can ask the UART to send the next byte.

All in all, the CPU doesn't have many things to do here. Just getting the bytes as soon as the input UARTs receive them, and give them back to the appropriate output UART. This is all done through read/writes of specific hardware registers at the right time. The CPU doesn't actually do the transmit/receive operations. And all UARTs and the CPU work concurrently. So, with CPUs with reasonable performance, you can guarantee maximum throughput. Moreover, using DMA, the load of the CPU can decrease even more... But DMA will be for the next chapter.

  • \$\begingroup\$ Thanks, this is a good explanation and does indeed answer my admittedly ambiguous question. I'll edit the question for anybody else who might later stumble on this to make it more understandable, but for now I'll accept your answer. Thanks again. \$\endgroup\$ – Scorch Jun 25 '16 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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