Circuit diagram of receiver
The 8 led inside the circuit diagram is to make sure that the data receive from transmitter are correct data.
RCSTA is the receive control register for the microcontroller. This register has to be initializing correctly in order to make the receiver work. By referring to the data sheet, the RCSTA is initialized as B'10010000' which mean that it continuously receive 8 bit data, asynchronous mode. The SPEN Flag bit in RCSTA have to be set to enable the serial port. The baud rate for the receiver has to be the same with the transmitter.
Each bit in RCSTA register
When receiving data from the transmitter, the data is first stall in Receive Shift Register (RSR). After that the received data is transferred to the RCREG register when it is empty. Once the transferring process from the RSR to RCREG is complete, the flag bit RCIF will be set. The RCREG is a double-buffered register which mean that it can store two byte of data. When the 2nd data come in but the 1st data have not been read yet, the data will store in the second slot of the RCREG. When the 1st data is read, the 2nd data will move to the 1st slot and new data can be move into RCREG. However, when the RCREG is full and the 3rd data is store in the RSR, the flag bit OERR will be set and the data in RSR will lost. In addition, all the receive process will be stop. Hence it is a must to clear the flag bit OERR in order to retrieve the receiving process. Flag bit OERR can be clear by first clear the CREN and then set it again. Figure 1.8 shows how the overrun error being detected and how it is solve.
Programming of receiver
Circuit diagram on breadboard
No comments:
Post a Comment