Protocoale de Comunicatii: Curs 4
Protocoale de Comunicatii: Curs 4
CURS 4
SPI
SPI-BUS
SPI-BUS
SPI stands for Serial Peripheral Interface. SPI is a synchronous protocol that allows a master device to initiate communication with a slave device. Data is exchanged between these devices. We will look at this more in detail as we progress though this tutorial. SPI is implemented in the PICmicro MCU by a hardware module called the Synchronous Serial Port or the Master Synchronous Serial Port. This module is built into many different PICmicro devices. It allows serial communication between two or more devices at a high speed and is reasonably easy to implement.
3
SPI-BUS
SPI-BUS
SPI-BUS
SPI-BUS
SPI-BUS
SPI is a Data Exchange protocol. As data is being clocked out, new data is also being clocked in. When one transmits data, the incoming data must be read before attempting to transmit again. If the incoming data is not read, then the data will be lost and the SPI module may become disabled as a result. Always read the data after a transfer has taken place, even if the data has no use in your application. Data is always exchanged between devices. No device can just be a transmitter or just a receiver in SPI. Each device has two data lines, one for input and one for output. These data exchanges are controlled by the clock line, SCK, which is controlled by the master device.
SPI-BUS
SPI-BUS
Often a slave select signal will control when a device is accessed. This signal must be used for when more than one slave exists in a system, but can be optional when only one slave exists in the circuit. As a general rule, it should be used. This signal is known as the SS signal and stands for Slave Select. It indicates to a slave that the master wishes to start an SPI data exchange between that slave device and itself. The signal is most often active low, so a low on this line will indicate the SPI is active, while a high will signal inactivity. It is often used to improve noise immunity of the system. Its function is to reset the SPI slave so that it is ready to receive the next byte.
10
SPI-BUS
11
SPI-BUS
12
SPI-BUS
13
SPI-BUS
14
SPI-BUS
15
SPI-BUS
16
SPI-BUS
17
SPI-BUS
18
SPI-BUS
19
SPI-BUS
SPI creates a data loop between two devices. Data leaving the master exits on the SDO (serial data output) line. Data entering the master enters on the serial data input, SDI line. A clock (SCK), is generated by the master device. It controls when and how quickly data is exchanged between the two devices. SS, allows a master device to control when a particular slave is being addressed. This allows the possibility of having more than one slave and simplifies the communications. When the SS signal goes low at a slave device, only that slave is accessed by SPI. SSPSR is the shift register for the SPI module. It shifts data in and out of the device. The data travels in a loop to the next shift register. The data is shifted out the SDO pin of one device and into the SDI pin of the other.
20
SPI-BUS
21
SPI-BUS
22
SPI-BUS
23
SPI-BUS
24
SPI-BUS
25
SPI-BUS
26
SPI-BUS
27