Single-wire half-duplex communication official information
Singlet semi-duplex mode by setting USART_CR3 register HDSEL bit. In this mode, the following bits must be kept cleared:
● USART_CR2 register LINEN and CLKEN bit
● USART_CR3 register SCEN and IREN bits
USART can be configured to follow the single-wire half-duplex protocol. In the single-wire half-duplex mode, TX and RX pins interconnected in a chip. Using the control bit "HALF DUPLEX SEL" (HDSEL bits in USART_CR3) selected half-duplex and full-duplex communication.
When HDSEL to '1'
● is no longer used the RX
● When no data transmission, TX always released. Therefore, it behaves as a standard I / O port in the idle state or a reception state. This means that I / O is not driven when the USART, must be configured as a floating input (or a high open-drain output).
In addition, the normal communication mode similar USART. Online conflict management by software (e.g., by using a central arbiter). In particular, it will not be sent from the hardware hindered. When the TE bit is set whenever data is written on a data register, transmission continues.
About registers and the corresponding bits mentioned above
1. First is CR3:
code corresponding to: USART1-> CR3 | = <<. 1. 3;
USART1-> CR3 & = ~ (<<. 1. 1);
USART1-> CR3 & = ~ (<<. 1. 5);
2. then CR2:
code corresponding to:
USART1-> CR2 is & = ~ (<< 14. 1);
USART1-> CR2 is & = ~ (<<. 1. 11);
Modify the code (serial experiment to experiment 4 as a template)
uart_init () partially modified as follows:
1. Remove the PA10 GPIO_Init portion
2. Add several relevant code register
interruptions I added the "If the microcontroller receives the data, the lights" code.
I changed the main function button to send:
Precautions
Since the single-wire half-duplex communication is set, the original TXD and RXD are now connected together, so that when the transmission data TXD use, can also be triggered interrupts (i.e. serial data port will receive the transmission itself), it is necessary software set up relevant content.
Hardware connection
Final verification, the data is transmitted KEY0, PA9 then the U-serial RXD, or directly onboard USB interface, when data is received, then U turn string PA9 TXD.