Datasheet

169
ATmega48/88/168 Automotive [DATASHEET]
7530K–AVR–07/14
18.3 SPI Data Modes and Timing
There are four combinations of XCKn (SCK) phase and polarity with respect to serial data, which are determined by control
bits UCPHAn and UCPOLn. The data transfer timing diagrams are shown in Figure 18-1. Data bits are shifted out and
latched in on opposite edges of the XCKn signal, ensuring sufficient time for data signals to stabilize. The UCPOLn and
UCPHAn functionality is summarized in Table 18-2. Note that changing the setting of any of these bits will corrupt all ongoing
communication for both the receiver and transmitter.
Figure 18-1. UCPHAn and UCPOLn Data Transfer Timing Diagrams
18.4 Frame Formats
A serial frame for the MSPIM is defined to be one character of 8 data bits. The USART in MSPIM mode has two valid frame
formats:
8-bit data with MSB first
8-bit data with LSB first
A frame starts with the least or most significant data bit. Then the next data bits, up to a total of eight, are succeeding, ending
with the most or least significant bit accordingly. When a complete frame is transmitted, a new frame can directly follow it, or
the communication line can be set to an idle (high) state.
The UDORDn bit in UCSRnC sets the frame format used by the USART in MSPIM mode. The receiver and transmitter use
the same setting. Note that changing the setting of any of these bits will corrupt all ongoing communication for both the
receiver and transmitter.
16-bit data transfer can be achieved by writing two data bytes to UDRn. A UART transmit complete interrupt will then signal
that the 16-bit value has been shifted out.
Table 18-2. UCPOLn and UCPHAn Functionality-
UCPOLn UCPHAn SPI Mode Leading Edge Trailing Edge
0 0 0 Sample (rising) Setup (falling)
0 1 1 Setup (rising) Sample (falling)
1 0 2 Sample (falling) Setup (rising)
1 1 3 Setup (falling) Sample (rising)
XCK
UCPOL = 0 UCPOL = 1
UCPHA = 1UCPHA = 0
Data setup (TXD)
Data sample (RXD)
XCK
Data setup (TXD)
Data sample (RXD)
XCK
Data setup (TXD)
Data sample (RXD)
XCK
Data setup (TXD)
Data sample (RXD)