Datasheet

in r16, UDRn
ret
Example 25-4. C Code Example
{
/* Wait for empty transmit buffer */
while ( !( UCSRnA & (1<<UDREn)) );
/* Put data into buffer, sends the data */
UDRn = data;
/* Wait for data to be received */
while ( !(UCSRnA & (1<<RXCn)) );
/* Get and return received data from buffer */
return UDRn;
}
Related Links
9. About Code Examples
25.6.1 Transmitter and Receiver Flags and Interrupts
The RXCn, TXCn, and UDREn flags and corresponding interrupts in USART in MSPIM mode are
identical in function to the normal USART operation. However, the receiver error status flags (FE, DOR,
and PE) are not in use and is always read as zero.
25.6.2 Disabling the Transmitter or Receiver
The disabling of the transmitter or receiver in USART in MSPIM mode is identical in function to the normal
USART operation.
25.7 AVR USART MSPIM vs. AVR SPI
The USART in MSPIM mode is fully compatible with the AVR SPI regarding:
Master mode timing diagram
The UCPOLn bit functionality is identical to the SPI CPOL bit
The UCPHAn bit functionality is identical to the SPI CPHA bit
The UDORDn bit functionality is identical to the SPI DORD bit
However, since the USART in MSPIM mode reuses the USART resources, the use of the USART in
MSPIM mode is somewhat different compared to the SPI. There are differences in the Control Register
bits and only the master operation is supported by the USART in MSPIM mode. Additionally, the following
features differ between the two modules:
The USART in MSPIM mode includes (double) buffering of the transmitter. The SPI has no buffer.
The USART in MSPIM mode receiver includes an additional buffer level
The SPI WCOL (Write Collision) bit is not included in USART in MSPIM mode
The SPI double speed mode (SPI2X) bit is not included. However, the same effect is achieved by
setting UBRRn accordingly.
Interrupt timing is not compatible
Pin control differs due to the master only operation of the USART in MSPIM mode
A comparison of the USART in MSPIM mode and the SPI pins is shown in the table below.
ATmega48PA/88PA/168PA
USART in SPI (USARTSPI) Mode
© 2018 Microchip Technology Inc.
Datasheet Complete
DS40002011A-page 269