ATmega88PA Automotive Atmel Corporation, ATmega88PA Automotive Datasheet - Page 187

no-image

ATmega88PA Automotive

Manufacturer Part Number
ATmega88PA Automotive
Description
Manufacturer
Atmel Corporation
9223B–AVR–09/11
The receive function example reads all the I/O Registers into the Register File before any
computation is done. This gives an optimal receive buffer utilization since the buffer location
read will be free to accept new data as early as possible.
Assembly Code Example
C Code Example
Note:
Atmel ATmega48PA/88PA/168PA [Preliminary]
USART_Receive:
USART_ReceiveNoError:
unsigned int USART_Receive( void )
{
}
; Wait for data to be received
in r16, UCSRnA
sbrs r16, RXCn
rjmp USART_Receive
; Get status and 9th bit, then data from buffer
in
in
in
; If error, return -1
andi r18,(1<<FEn)|(1<<DORn)|(1<<UPEn)
breq USART_ReceiveNoError
ldi
ldi
; Filter the 9th bit, then return
lsr
andi r17, 0x01
ret
unsigned char status, resh, resl;
/* Wait for data to be received */
while ( !(UCSRnA & (1<<RXCn)) )
/* Get status and 9th bit, then data */
/* from buffer */
status = UCSRnA;
resh = UCSRnB;
resl = UDRn;
/* If error, return -1 */
if ( status & (1<<FEn)|(1<<DORn)|(1<<UPEn) )
/* Filter the 9th bit, then return */
resh = (resh >> 1) & 0x01;
return ((resh << 8) | resl);
return -1;
1. See
For I/O Registers located in extended I/O map, “IN”, “OUT”, “SBIS”, “SBIC”, “CBI”, and
“SBI” instructions must be replaced with instructions that allow access to extended I/O. Typ-
ically “LDS” and “STS” combined with “SBRS”, “SBRC”, “SBR”, and “CBR”.
r18, UCSRnA
r17, UCSRnB
r16, UDRn
r17, HIGH(-1)
r16, LOW(-1)
r17
;
Section 6. “About Code Examples” on page 7
(1)
(1)
187

Related parts for ATmega88PA Automotive