CH 7 AVR Peripherals - Serial
CH 7 AVR Peripherals - Serial
SERIAL COMMUNICATION
DR T WALINGO
• THE RS232.
• USART.
– POLLING BASED.
– INTERRUPT BASED.
Stop 0 0 0 0 0 1 Start
1 0
bit bit
D7 D0 Space Mark
Stop
Start
RxD
Data bus
Transmit data
put here
Received data UDR UDR
read from here (Rx buffer) (Tx buffer)
To Transmit:
• Poll UDRE bit in USCRA
until set.
• Place character to be
written in UDR.
• Repeat.
To Receive:
• Poll RXC bit in UCSRA
until set.
• Received char in UDR.
• Repeat.
rjmp RECEIVE
;***********************************************
• When configured as a Slave, the SPI interface will remain sleeping with
MISO tri-stated as long as the SS pin is driven high. In this state,
software may update the contents of the SPI Data Register, SPDR, but
the data will not be shifted out by incoming clock pulses on the SCK pin
until the SS pin is driven low.
• After shifting one byte of data, the end of Transmission Flag (SPIF) is
set. If the SPI Interrupt Enable bit (SPIE) in the SPCR Register is set, an
interrupt is requested.
• The Slave may continue to place new data to be sent into SPDR before
reading the incoming data. The last incoming byte will be kept in the
Buffer Register for later use.
The WCOL bit is set if the SPI Data Register (SPDR) is written
during a data transfer. The WCOL bit (and the SPIF bit) are cleared
by first reading the SPI Status Register with WCOL set, and then
accessing the SPI Data Register.
SPI flag set when a serial transfer is complete. An interrupt is generated if SPIE
in SPCR is set and global interrupts are enabled.
• The SPI Data Register is a read/write register used for data transfer
between the Register File and the SPI Shift Register.
• Reading the register causes the Shift Register Receive buffer to be read.
MULTI-BYTE WRITE
MULTI-BYTE READ
.equ MIS0 = 6 ; According to the MCU pins ldi Temp, ‘G’ ;Temp =‘G’
; ************************************************ out SPDR, Temp ;transmit
;CONFIGURATION SECTION
WAIT:
Init: ldi Temp, 0xFF
out DDRA, Temp ;PORTA is output sbis SPSR, SPIF ;wait for transmission
rjmp WAIT ;to complete
ldi Temp, (1<<MISO) ; in Temp1, SPDR ;read received data
out DDRB, Temp ; Pins defined as output out PORTA, Temp1