Is it possible to connect the Rx and Tx pins of the same USART or on two different USARTs on an STM32 discovery board to make a loopback and test the USART?
-
Yes, as long as you make sure only one device is writing on every line, I believe. There should not be two devices talking on the same line. – Mar 21 '13 at 09:43
-
What do you mean with same line ? I am only using the Tx and Rx pins by the USART (no GPIO) – rxjsisfine Mar 21 '13 at 09:47
-
BTW one of 1-wire implementation works exactly like this: you connect together RX and TX of same USART. – Eddy_Em Mar 21 '13 at 09:57
-
I just tested it now on 2 different USARTs and it worked perfectly. Moving on to same USART :) – rxjsisfine Mar 21 '13 at 10:11
-
You should ask @camil-staps to form his comment as an answer so that you can officially accept it. Despite the miscommunication about multiple USARTS, he did take the time to answer your question. – Joe Hass Mar 21 '13 at 10:40
1 Answers
You can do anything with USART lines as long as you stick to one basic rule. To understand this rule, you have to understand how the protocol works.
Basically, we have two lines: Rx and Tx. Let's consider these from the device A point of view. Rx is A receives, Tx is A transmits. This means Rx is B transmits, and Tx is B receives. You can now see that these two data lines are one-directional: it's in the circuit who writes and who reads.
It's possible to 'hack' a USART communication: sending data to device X and listening with device Y. Actually, it's a great idea. For example:
simulate this circuit – Schematic created using CircuitLab
In this case, I wanted to read data from A with B, but A sent way too much data. So I added a filter in C. Device A doesn't even notice this change.
You can do really anything with USART lines: listening with multiple devices on one line, et cetera. Just make sure there aren't two devices that have Tx and Tx connected. They will interfere.
-
1This is interesting, but seems to answer a question substantially different than the one that was asked... – Chris Stratton Mar 21 '13 at 15:12
-
@ChrisStratton I tried to give a general explanation of the USART which shows the answer ('yes'). You have to see the different USART modules as different devices and I believe this answer is valid then. Or am I misunderstanding something? – Mar 21 '13 at 15:30