Книга: Advanced PIC Microcontroller Projects in C

7.1.1 The SPI Bus

7.1.1 The SPI Bus

The SPI (Serial Peripheral Interface) bus is a synchronous serial bus standard named by Motorola that operates in full duplex mode. Devices on a SPI bus operate in master-slave mode, where the master device initiates the data transfer, selects a slave, and provides a clock for the slaves. The selected slave responds and sends its data to the master at each clock pulse. The SPI bus can operate with a single master device and one or more slave devices. This simple interface is also called a “four-wire” interface.

The signals in the SPI bus are named as follows:

• MOSI — master output, slave input

• MISO — master input, slave output

• SCLK — serial clock

• SS — slave select

These signals are also named as:

• DO — data out

• DI — data in

• CLK — clock

• CD — chip select

Figure 7.3 shows the basic connection between a master device and a slave device in SPI bus. The master sends out data on line MOSI and receives data on line MISO. The slave must be selected before data transfer can take place.


Figure 7.3: SPI master-slave connection

Figure 7.4 shows an instance where more than one slave device is connected to the SPI bus. Here, each slave is selected individually by the master, and although all the slaves receive the clock pulses, only the selected slave device responds. If an SPI device is not selected, its data output goes into a high-impedance state so it does not interfere with the currently selected device on the bus.


Figure 7.4: Multiple-slave SPI bus

Data transmission normally occurs in and out of the master and slave devices as the master supplies clock pulses. To begin a communication, the master first pulls the slave select line low for the desired slave device. Then the master issues clock pulses, and during each SPI clock cycle, a full duplex data transmission occurs. When there are no more data to be transmitted, the master stops toggling its clock output.

The SPI bus is currently used by microcontroller interface circuits to talk to a variety of devices such as:

• Memory devices (SD cards)

• Sensors

• Real-time clocks

• Communications devices

• Displays

The advantages of the SPI bus are:

• Simple communication protocol

• Full duplex communication

• Very simple hardware interface

Its disadvantages are:

• Requires four pins

• No hardware flow control

• No slave acknowledgment

It is worth remarking that there are no SPI standards governed by an international committee, so there are several versions of SPI bus implementation. In some applications, the MOSI and MISO lines are combined into a single data line, thereby reducing the line requirements to three. Some implementations have two clocks, one to capture (or display) data and the other to clock it into the device. Also, in some implementations the chip select line may be active-high rather than active-low.

Оглавление книги

Оглавление статьи/книги

Генерация: 0.031. Запросов К БД/Cache: 0 / 0
поделиться
Вверх Вниз