Microcontrollers in Practice

This chapter contains a detailed description of the SPI of HC11 and AVR microcontrollers, with hardware and software applications examples.
As mentioned in Chap. 3, in synchronous serial communication, both the transmitter and receiver use the same synchronization clock to transfer data. Therefore, the device that generates the transmission clock fully controls the moment and the speed of the transmission, and it is called the MASTER.
The HC11 and AVR families of microcontrollers include a synchronous serial interface, called the Serial Peripheral Interface (SPI), allowing operation either in MASTER mode or in SLAVE mode. The general block diagram of a SPI link is presented in Fig. 4.1.
Four shift registers are involved in this link. All work with the same shift clock, generated by the MASTER device. The transmission and reception processes occur simultaneously. Two data line are provided to this purpose: MOSI (MASTER Out SLAVE In) and MISO (MASTER In SLAVE Out).
When the MASTER writes by software a byte into the transmitter's data register, eight clocks are automatically generated to the SCK line, and the bi-directional transmission begins. Whatever is found at this moment in the SLAVE's Tx Data Register is shifted into the MASTER's Rx Data Register.
When more than one SLAVE device is connected to the SPI bus, only one SLAVE may be enabled at a certain...