Code for this project is given below .First Try to understand the code with the help of datasheet of MCP23S08 i/0 expander and ATtiny85 google it you can search this . The complete SPI protocal is shown below the code .
SPI communication protocal is faster than previous i2C or USART communication except it uses more wires then i2C and USART ,But it is most popular and easy to interface protocal and most used communiction protocal like burner of AVR .it is developed by motorola and available in almost all architectures, including 8051, x86, ARM, PIC, AVR, MSP etc., and is thus widely used . This means that there shouldn’t be any portability issues and you can connect devices of two different architectures together as well!
Master and Slave
In SPI, every device connected is either a Master or a Slave.The Master device is the one which initiates the connection and controls it. Once the connection is initiated, then the Master and one or more Slave(s) can transmit and/or receive data. this is a full-duplex connection, which means that Master can send data to Slave(s) and the Slave(s) can also send the data to the Master at the same time.You need address for each slave select or you need a multiplexer to select perticular slave .In device( slave) and microcontroller (master) are seperate pins for SPI protocal which is described below
The SPI typically uses 4 pins for communication, viz. MISO, MOSI, SCK, and SS. These pins are directly related to the SPI bus interface.
- MISO – MISO stands for Master In Slave Out. MISO is the input pin for Master AVR, and output pin for Slave AVR device. Data transfer from Slaveto Master takes place through this channel.
- MOSI – MOSI stands for Master Out Slave In. This pin is the output pin for Master and input pin for Slave. Data transfer from Master to Slavetakes place through this channel.
- SCK – This is the SPI clock line (since SPI is a synchronous communication).
- SS – This stands for Slave Select. This pin would be discussed in detail later in the post.
First all the PINs needed for SPI communication is defined using #define command . After this we defined different functions for initialization and communication . To understand the registers used inside the code you need to follow a datasheet of ATtiny can be download from link below. atmel-2586-avr-8-bit-microcontroller-attiny25-attiny45-attiny85_datasheet