209
8025I–AVR–02/09
ATmega48P/88P/168P/328P
Note:
1.
See ”Code Examples” on page 7.
18.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.
18.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
sbis
UCSRnA, 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:
sbis
UCSRnA, 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;
}