211
8271D–AVR–05/11
ATmega48A/PA/88A/PA/168A/PA/328/P
Note:
1.
See ”About Code Examples” on page 8.
21.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.
21.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.
Assembly Code Example
USART_MSPIM_Transfer:
; Wait for empty transmit buffer
in r16, UCSRnA
sbrs
r16, UDREn
rjmp
USART_MSPIM_Transfer
; Put data (r16) into buffer, sends the data
out
UDRn,r16
; Wait for data to be received
USART_MSPIM_Wait_RXCn:
in r16, UCSRnA
sbrs
r16, RXCn
rjmp
USART_MSPIM_Wait_RXCn
; Get and return received data from buffer
in
r16, UDRn
ret
C Code Example
unsigned char
USART_Receive(
void
)
{
/* 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;
}