Communication Protocols | PIC Microcontroller
A PIC microcontroller system has many peripherals connected and an essential activity of these systems to work properly is to effectively transfer data between the microcontroller and the various peripherals. Broadly speaking, there are two ways of transferring the data. In parallel transfer, all the bits of the word are transmitted at the same time, each bit over its own connection. The alternative is to send each bit in turn, over a single connection. This is called serial communication. At first glance, it is easy to observe that parallel takes more wires and connections, but is faster. Serial needs fewer wires, is slower, and generally requires more complex hardware to transmit and receive. This blog explains about communication protocols.
In a microcontroller-based system, it is usually better to stick to established standards for the cabling so that other instruments and circuits can have proper communication and be connected with a minimum amount of hassle.
The standards produced by Centrionics, among the several different standards is the most widely used for parallel connection. The Centronics system sends eight bits at a time and employs a 36 plug and socket system. To send data, there are four basic control signals as well as the eight data lines. It also stipulates a variety of other control wires that can be used if required. This is one form of connection to establish communication protocols.
To understand how data can be sent serially, it is helpful to explore the underlying hardware. Data within a PIC microcontroller or memory is still likely to be used and formatted in parallel. Therefore, a serial transmitter needs to be able to accept data in parallel format, but then transmit it serially; a serial receiver needs to be able to do the reverse. This is usually done with a shift register.
A simple 8 bit shift register is shown below. It is made up of eight flip-flops connected together so that the Q-output of one becomes the data input of the next. All are driven from the same clock, and on every clock cycle the data is moved one flip-flop to the right. If a new bit of data appears at the DIN input on every clock cycle, then in eight clock cycles 1 byte will be clocked through such that it can be read as a parallel word from outputs QA to QH. This simple circuit can act as a receiver of serial data.
Multiple shift registers can be connected together with a common clock source to increase the bit size of the register. This kind of link is called synchronous link as the data transfer is synchronised by the same clock source.
This is a synchronous communication protocols. Four I/O pins are used for SPI communication with an external device:
- MISO: Master In/Slave Out data. In general case, this pin is used to transmit data in slave mode and receive data in master mode.
- MOSI: Master Out/Slave In data. This pin is used to transmit data in master mode and receive data in slave mode.
- SCK: Serial Clock Output pin for master in SPI and input for slave
- SS: Slave Select pin. This pin can be used to select an individual slave device for communication.
It a full-duplex communication because it can send and receive data using a separate bus, although under specific conditions we can choose to not use some pins and operate it in half duplex or simplex mode. Click here to learn more about SPI Protocol.
IIC stands for Inter Inter-Integrated Circuits. Similar to SPI, this is also a synchronous communication protocol but only uses two lines to share data. It is also possible to connect multiple slaves and masters as shown in the figure.
Both the SDA and the SCL lines are bidirectional and are connected to the positive supply voltage via pull-up resistors. When the bus is free these lines are held high. In I2C protocol, the master talks to the slave devices using it’s address. Click here to learn more about I2c protocol.
Universal Asynchronous Receiver Transmitter or UART for short is one of the simplest form of asynchronous communication protocol. Unlike SPI and I2C, it is not a communication protocol but a physical circuit integrated on the microcontroller. UART only requires two lines, the transmitter Tx and the receiver Rx, for transmission of data between microcontrollers. The Tx of one microcontroller is connected to the Rx of the other and vice versa. As no clock is present for asynchronous communication, we establish certain serial standards and rules so that the receiver can extract all the timing information from the signal itself.
This is done by:
- Presetting the transmitter and receiver to have the same data transmission rate.
- Each byte or word is framed with a Start and Stop bit. These allow synchronisation to be initiated before the data starts to flow.
Refere wikipedia for detailed info about communication protocols.