 Hello and welcome to this video session on peak microcontrollers serial communication module MS-SP in that we will try to cover serial peripheral interface SPI protocol myself Mr. Vipul Kondekar from Walchand Institute of Technology, Sholapur. These are the learning outcomes of this video session. So at the end student will be able to describe the SPI module and various features various operating modes of it as well student will be able to describe how exactly transmission and reception takes place with the help of internal hardware present related to the SPI. So these are the contents of this presentation. We will have small introduction to SPI module then various special function registers related to the serial communication SPI module then we will go for understanding how we can have interconnection between the two devices using this SPI communication. At the end we will go through the block diagram with which we will try to understand how exactly peak microcontroller can support this SPI communication protocol. Now let us have brief introduction to this SPI. Peak microcontroller has got MS-SP module MS-SP stands for master synchronous serial port module. This particular module is used for serial communication where one microcontroller can communicate with another microcontroller or some peripherals. Few examples are like serial e-square prompts are available, shift registers, display drivers serial ADCs are available. So when you want to have the communication between these serial devices which are supporting this SPI protocol we can use this MS-SP module in SPI mode for the peak microcontroller. So basically this MS-SP module works in two different modes either you can make its use in SPI or I2C and in SPI as well as I2C they can work in two modes master and slave. Now can you tell what is the difference between master and slave mode operation? Master and slave mode operation comes into the picture whenever you are talking about the synchronous communication only and in synchronous communication you know that you need to send the clock signal along with the data. So whenever two devices are communicating the device which sends its clock is called as master and definitely another device will make use of the clock sent by the master for having synchronization in the serial communication. So this is basic difference between master and slave. Now let us concentrate on SPI protocol SPI mode operation of MS-SP. So peak microcontroller allows 8 bit synchronous transmission as well as reception simultaneously it indicates it supports full duplex communication. So to accomplish this particular full duplex communication via SPI what are the pins available in microcontroller? So basically three important pins SDO serial data out, SDI serial data in and SEK are the three important pins along with that you may you can have use of one more pin called as slave select. So if you observe these are the port C pins as well this is one pin from port A for peak microcontroller and these are the four pins used for SPI protocol communication. Now along with these pins you will be taking the help of spatial function registers related to this MS-SP mode. So when you want to use SPI mode operation of MS-SP what are the different spatial function registers required? So there are four spatial function registers out of that these are the two control and state this is MS-SP control register called as SS-PCON, MS-SP status register is there which is SS-SP STAT as well as two more registers SS-SP BUFF which is used to transmit the data as well as receive data is available in this particular buffer register and one shift register is there MS-SP shift register. So these are the four important registers used for serial communication in SPI mode. Now this is how these are the details of the two important spatial function registers for configuration or initialization of the peak microcontroller in SPI mode. So one register is SS-SP STAT which is SS-SP status register as well as another register is SS-SP CON 1. Now each and every bit present in this particular register has also got some significance. Details of all these bits are available in the data sheet of peak microcontroller as well as user manual. Because of timing constraint we will not go in depth about understanding here the significance of these bits. If you refer the data sheet you will find that the bit format significance of each and every bit is available you can go through the data sheet for the significance of these two spatial function registers. Just we will concentrate on what are the important functions performed by these control bits. So the important functions performed by the control bits are you can have the master mode or slave mode selection. Now as we discussed master mode means you are sending the clock so SCK will be the clock output if you are using slave then SCK will be the clock input you will be using the clock of the another master if you are working in the slave mode so this mode selection can be done clock polarity can be decided so what can be the idle state of SCK so when the communication will start so that can be decided data input sample when you are sampling the data when you are receiving the data when you are going to sample whether it will be sample at the middle or end of the data output time clock age so the synchronization clock is used so which clock is used for the synchronization clock rate what will be the clock rate and slave mode select mode slave select mode when multiple slaves are present in one network one master is connected to multiple slaves so then this is one important use this is slave select mode so these are the different what we can say operations or the modes in which the SPI module can be configured by taking the help of these control registers and status register. Now if you concentrate basically SSPcon and SSPstat are the control and status registers as we discussed. Now SSPSR is one shift register so which is used for shifting the data when you are transmitting the data data is available to you in the parallel format now that parallel data has to be converted into serial so this shift register will do that serial conversion and will transmit that data on to the SDO line as well if you are receiving the data so serial data will be received serial to parallel conversion will be done SSP buff is one buffer register so which data byte is returned to or read from so when you want to write the data when you want to send the data serially write that data to the SSP buff if you are reading the data serially that serial data read that data 8 bit data received will be available to you in the SSP buff register so these are the two registers as well as when SSP SR receives complete byte it transfers it is transferred so shift register is receiving the data when the byte is completely received it will be transferred to the SSP buff register as well as it can result into the setting of this interrupt of the serial communication during the transmission when you are doing the transmission SSP buff SSP buff is not double buffered so a write to SSP buff will write to both SSP buff as well as SSP SR so this will be cleared when we will go through the block diagram of SPI module so how I can have the connection now here we will try to understand if I have two devices this processor one this is processor two or this may be some another peripheral how I can have the interconnection between these two devices so first you have to decide which is going to be the master so let us say this is the master device so this will be the SCK this will generate the clock that clock will be given to the slave and then what you can have as we said it is supporting full-duplex communication so serial data output line is connected here as the SDI serial data input for the processor two and SDO of processor two is connected to SDI and then internally they will be taking the help of this SSP shift register as well as buffer register for serial communication so this how basically you can have interconnection between the two devices which supports SPI protocol now let us try to understand how exactly this hardware available inside the peak microcontroller related to the MSSP SPI mode operation supports this serial communication protocol now remember whenever you are transmitting let us assume that you are transmitting the data so whenever data you are known to transmit that data is available in some memory in file register so that data available to you is in the parallel format so get that data onto the internal bus if you are writing that data so that data will be written to SSP buff so this is a buffer register the instant you write that data the same data will be available to the SSP shift register and now you can have transmission of the data this 8 bit data will get converted into serial data and that can be sent onto this particular pin called as SDO but when you are sending that data clock should be used now it depends on when you are doing the transmission whether you are master of slave if your slave device then whatever the shift register clock you get that shift register clock you will get onto this particular pin and that will be sent by some another master so that clock will be available to you for the shift register when your slave device now when you are master device if you are master device so you will be generating that clock signal so for a generation of that clock signal this is the clock select so either you will be receiving the clock from another master or if you are master then you are generating the clock so this is the hardware related to the clock generation the timer to is used for clock generation purpose if your master timer to is used for the clock generation that clock can have different frequencies so for that pre-scalars are available you can select these pre-scalars and then you can generate the clock and then that clock can be used for a clock signal for transmission of the data as well not necessarily you are transmitting sometimes you are receiving the data remember if you are master you can send the data receive the data if you are slave then also you can send the data receive the data just we have seen that how you can transmit the data if you are master if you are slave if you are master you will be generating the clock and then you will be sending that data serially onto this SDO pin if you are slave you are receiving a clock generated by some another master and that clock is only used here for sending the data now just if you are receiving the data then this particular serial data input pin will come into the picture so here sdi data will be available to you and then again the clock will be used so that will be either sent by another master or if you are master you will generate that clock and then serial data received will be available in the buffer register then it will it will be available in the shift register then it will go to the buffer and then you can read this ssp buff to understand what data is received so this is how this particular hardware module works for the peak microcontroller so that it can support this serial communication protocol called as spi so these are the references used for this video presentation thank you