24.3.1 Initialization
For setting the USART in Full-Duplex mode, the following initialization sequence is recommended:
- Set the TxD pin value high, and optionally set the XCK pin low (OUT[n] in PORTx.OUT).
- Set the TxD and optionally the XCK pin as an output (DIR[n] in PORTx.DIR).
- Set the baud rate (in the USARTn.BAUD register) and frame format.
- Set the mode of operation (enables XCK pin output in Synchronous mode).
- Enable the transmitter or the receiver, depending on the usage.
For interrupt-driven USART operation, global interrupts should be disabled during the initialization.
Before doing a re-initialization with a changed baud rate or frame format, be sure that there are no ongoing transmissions while the registers are changed.
For setting the USART in One-Wire mode, the following initialization sequence is recommended:
- Set the TxD/RxD pin value high, and optionally set the XCK pin low.
- Optionally, write the ODME bit in the USARTn.CTRLB register to '1' for Wired-AND functionality.
- Set the TxD/RxD and optionally the XCK pin as an output.
- Select the baud rate and frame format.
- Select the mode of operation (enables XCK pin output in Synchronous mode).
- Enable the transmitter or the receiver, depending on the usage.
For interrupt-driven USART operation, global interrupts should be disabled during the initialization.
Before doing a re-initialization with a changed baud rate or frame format, be sure that there are no ongoing transmissions while the registers are changed.