Microchip Technology megaAVR 0 Series Manual page 321

Hide thumbs Also See for megaAVR 0 Series:
Table of Contents

Advertisement

After a transfer has completed, the Interrupt Flag will be set in the Interrupt Flags register (IF flag in
SPI.INTFLAGS). This will cause the corresponding interrupt to be executed if this interrupt and the global
interrupts are enabled. Setting the Interrupt Enable (IE) bit in the Interrupt Control register
(SPIn.INTCTRL) will enable the interrupt.
Buffer Mode
The Buffer mode is enabled by setting the BUFEN bit in SPIn.CTRLB. The BUFWR bit in SPIn.CTRLB
has no effect in Master mode. In Buffer mode, the system is double buffered in the transmit direction and
triple buffered in the receive direction. This influences the data handling the following ways:
1.
New bytes to be sent can be written to the Data register (SPIn.DATA) as long as the Data Register
Empty Interrupt Flag (DREIF) in the Interrupt Flag Register (SPIn.INTFLAGS) is set. The first write
will be transmitted right away and the following write will go to the Transmit Buffer register.
2.
A received byte is placed in a two-entry RX FIFO comprised of the First and Second Receive Buffer
registers immediately after the transmission is completed.
3.
The Data register is used to read from the RX FIFO. The RX FIFO must be read at least every
second transfer to avoid any loss of data.
If both the Shift register and the Transmit Buffer register becomes empty, the Transfer Complete Interrupt
Flag (TXCIF) in the Interrupt Flags register (SPIn.INTFLAGS) will be set. This will cause the
corresponding interrupt to be executed if this interrupt and the global interrupts are enabled. Setting the
Transfer Complete Interrupt Enable (TXCIE) in the Interrupt Control register (SPIn.INTCTRL) enables the
Transfer Complete Interrupt.
23.3.2.2 Slave Mode
In Slave mode, the SPI peripheral receives SPI clock and Slave Select from a Master. Slave mode
supports three operational modes: One unbuffered mode and two buffered modes. In Slave mode, the
control logic will sample the incoming signal on the SCK pin. To ensure correct sampling of this clock
signal, the minimum low and high periods must each be longer than two peripheral clock cycles.
SS Pin Functionality in Slave Mode
The Slave Select (SS) pin plays a central role in the operation of the SPI. Depending on the mode the
SPI is in and the configuration of this pin, it can be used to activate or deactivate devices. The SS pin is
used as a Chip Select pin.
In Slave mode, SS, MOSI, and SCK are always inputs. The behavior of the MISO pin depends on the
configured data direction of the pin in the port peripheral and the value of SS: When SS is driven low, the
SPI is activated and will respond to received SCK pulses by clocking data out on MISO if the user has
configured the data direction of the MISO pin as an output. When SS is driven high the SPI is
deactivated, meaning that it will not receive incoming data. If the MISO pin data direction is configured as
an output, the MISO pin will be tristated. The following table shows an overview of the SS pin
functionality.
Table 23-3. Overview of the SS Pin Functionality
SS Configuration
Always Input
©
2018 Microchip Technology Inc.
SS Pin-Level
Description
High
Slave deactivated
(deselected)
Low
Slave activated
(selected)
Datasheet Preliminary
®
megaAVR
Serial Peripheral Interface (SPI)
MISO Pin Mode
Port Direction =
Port Direction =
Output
Input
Tri-stated
Input
Output
Input
DS40002015A-page 321
0-Series

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the megaAVR 0 Series and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Atmega4808Atmega4809Atmega3208Atmega3209

Table of Contents