 Hello and welcome to this second video on PIC microcontroller serial communication module USART. Here we will go for understanding asynchronous transmission and reception using USART module. Myself Mr. Vipul Kondekar from Walton Institute of Technology, Sholapur. These are the learning outcomes of this video. Students will be able to describe the module for transmission reception in asynchronous way and then student will be able to implement the steps either in assembly language or C programming language for asynchronous reception as well as transmission. And at the end student will be able to simulate asynchronous transmission using Proteus simulation software. So these are the contents of this presentation. So we will go for introduction steps for transmission reception and then we will go for one sample program written in assembly language and then we will see the result of simulation of it. So when you are doing the transmission in asynchronous mode, so what steps you need to follow. So if you recall in the previous video we have seen asynchronous module. How that module is controlled by two special function registers RC XTA and TX XTA special function registers. As well we have seen how we can have bordered selection in the asynchronous mode. So what steps we need to follow if I want to do the transmission. So first thing is when you are doing the transmission you have to make sure that you are selecting proper bordered and we know that that bordered selection is done by SPBRG register. So you have to load the value in SPBRG according to the required bordered. As well that BRGH bit plays important role. So if you want to double the bordered if you want to change the bordered so this BRGH will play important role. So if we have seen in the previous video that BRGH value if it is said then division factor is getting reduced it is becoming 16. So the bordered gets increased. So for high bit transmission you said BRGH bit. Then next step you have to follow is enable the transmission. So there are two bits go for this clearing SYNC because you are going for the asynchronous transmission and then set this SPEN bit. So this serial peripheral communication module you have to enable. And after that if you want interrupt because of the transmission so what you can do is if you want interrupt then just enable that interrupt. So TXIFI has to be set globally that interrupt has to be enabled as well as this peripheral interrupt bit has to be also enabled. So if all these three bits are enabled. So then the serial transmission will also result into interrupt. Sometimes instead of transmitting 8 bit data you may go for 9 bit transmission. And that 9th bit which you want to transmit so that you have to load in first you have to say that TX9 bit means you have to enable the 9 bit transmission. And if this particular TX transmission 9 bit is enabled. So then what you can do is this TX90 value what you load. So that value will be transmitted as the 9 bit. So if you are desired to transmit 9 bit so say TX9 as well as whatever 9 bit you want to transmit that has to be there in TX90 bit location. And after this after setting all after following these steps now whatever data you want to transmit. So a byte you want to transmit. So that byte you have to load in TXREG register. And this will start the transmission. So with the help of block diagram now let us try to understand how exactly the transmission takes place. So this is the block diagram of the user transmitter for asynchronous transmission. So here very first thing what you have to do is you have to select this board rate. So by setting a particular value in SPBRG so you will select a board rate. After selecting board rate what next you have to do is you have to enable this communication module. So this module has to be enabled then only the transmission can take place. Now sometimes if you want interrupt so if interrupt is desired one more requirement is this TXIE has to be enabled. So if this TXIE is enabled GIE is enabled and PEIE are enabled these are all these bits are enabled then this serial communication module may also result into interrupt. Now if you go for 9 bit transmission as we have discussed that 9th bit that TX9 bit has to be set and whatever 9 data you want to transmit that TX90 should carry that particular bit value. So that will be a 9 bit for the transmission. Now once this what we can say settings are done now actually data you want to transmit so whatever data you want to transmit may be available in some file register may be available in working register you have to load that data into TXREG. So that data will go to TXREG register once you load that data into TXREG register it will go to a shift register TXR transmission shift register. So that data gets converted parallel data received gets converted into serial data and then that data will get transmitted onto the PIN. This is not exact data along with this start bit stop bit and if you are transmitting that 9 bit that 9 bit will be there so actually what gets transmitted is a frame. Remember that when you are transmitting the data what which bit gets transmitted first is the least significant bit of your data. And then how you will come to know the transmission of the data is over. So this is the provision that TRMT is one flag bit as well as TXIF so it can these are the two flag bits which can be used to understand or to get the information whether the transmission of the byte is over. So when the transmission shift register is empty this particular flag bit is one as well as it will say this TXIF flag bit also. So this is how this particular transmission module can be used for the transmission. On the same lines if you are receiving the data certain steps has to be followed. So let us try to understand what steps you need to follow if you are doing the reception of the data. So if you are receiving the data again you have to make sure that the board rate of the receiver is matching with the board rate of the transmitter. So again ESPBRG and BRGH bit will be used. Again you are doing asynchronous communication so hence sync bit has to be cleared as well as you have to set this ESPN. Again if interrupt is desired at the receiver side RCIE flag has to be GIE as well as PEIE. So these are the interrupt enable flag bits so all these bits has to be enabled. Again if the sender is doing the transmission with the 9 bit data receiver also should be configured to receive 9 bits. So RX9 bit has to be enabled if you are receiving 9 bit data as well as you have to decide this whether you want to enable this continuous reception or not. So based on your requirement this flag bit also should be set or cleared. And then when you are receiving the data how you will come to know that reception of the byte is over. So RCIF flag bit will be set when reception is complete. And if the interrupt is enabled for the reception then this RCIE flag bit if it is set so then it will result into interrupt also. So whatever reception is done then it will be available to you in RCSTA register as well as the 9 bit of the data received so that is available in RCSTA register. So what you have to do is when the reception is complete so just what you have to do is you have to read the receive register. So receive register will have that 8 bit data whatever 9th receive data bit that is available in RCSTA. And as well this UART module for peak microcontroller supports error control so if error occurs in the reception so that gets identified and then you have to clear that particular error by clearing this particular bit CREN. So this is how you will come to know the error has occurred. So you have to deal with that error either you have to ask for retransmission and then this CREN bit has to be cleared. So these are the steps we need to follow when you are doing the asynchronous reception. Now let us try to understand with the help of one simple program. So this is one assembly language sample program written for transmission of the data. So what we are going to transmit. So here we are going to transmit three characters three characters you want to transmit. Now let us look at what this particular code is. So these are the some standard things already we have discussed. So CLRF3C because I want to deal with the transmission and transmission pin is the part of port C. So I am enabling I am configuring the port as output ports port C pins will be configured as output port. Now very first step we have seen that you have to decide the board rate. So this 25 value is to be loaded in SPBRG to get the standard board rate of 9600 when the clock frequency is 4 MHz. So board rate is selected and then you have to configure the TXSTA and RCSTA register. So this is how TXSTA and RCSTA are configured for asynchronous transmission. And then once these TXSTA, RCSTA are configured now your responsibilities or your duty is just to whatever byte whatever data you want to transfer that data you will be writing in TXREG. So just write that character in TXREG. So in the simulation you will find instead of ETC it is WIT these are the three characters transferred. So if it is W so it is transmitted here and how I can come to know that transmission of W is over. So just poll for this TXIF. So this is one important instruction bit test file skip if set. So what you have to test you have to test TXIF bit in file register PIR1 and if that particular bit is set then skip this next instruction. If the interrupt is not means inter flag is not set so just go for polling just check for whether it is set and once it is set just go for transmission of the second character. So this is how three characters are transferred and then at the end what is written is the infinite loop so this is the end of your program. So if you built a hex file for this particular program what you will find is if you run that so in the Proteus if you run this virtual microcontroller is taken and then virtual terminal you have to make sure that the board rate of the sender and receiver are matched. So for the board rate 9600 we have assumed that this microcontroller's clock frequency is 4Mhz so that setting has to be done. And once you make that setting if you run the simulation you will find that that program will result into transmission of three characters W, I, T on to the virtual terminal. So this is how the transmission in asynchronous mode takes place. Now just think what will be the received data if the board rate of sender and receiver are not matching whether some data will be received. If yes what will be that data these are the references used for this presentation. Thank you.