Unit Ii
Unit Ii
Unit Ii
EMBEDDED NETWORKING
I/O Devices:
Input and output devices are used in parallel with other embedded system components
such as the processing element, such as a CPU, and memory. Together, they allow the
system to collect certain data to execute a specific task and also allows users to easily
control and interact with the embedded system.
Ports:
In embedded systems, I/O (Input/Output) ports are essential components that allow the
microcontroller or microprocessor to interact with the external world, including sensors,
actuators, and other devices.
Bus:
A bus is a subsystem that is used to connect computer components and transfer data
between them. For example, an internal bus connects computer internals to the
motherboard. A “bus topology” or design can also be used in other ways to describe
digital connections. A bus may be parallel or serial.
The system bus carries address, data and control information. It is comprised of three
types of buses to do this function, the Address Bus, the Data Bus, and Control Bus.
There are three types of bus lines: Data bus, Address bus, and Control bus.
Communication over each bus line is performed in cooperation with another. The data
bus is a signal line for exchanging the data between the CPU and the memory, and
between the CPU and I/O and handles the data stored in the specified location.
Serial communication Protocols:
Serial communication is a communication method that uses one (or) two transmission
lines to send and receive data, and that data is continuously sent and received one bit at
a time. The transmission mode can be classified into simplex, half-duplex, and full-
duplex. Each transmission mode contains the source, also known as sender or
transmitter, and destination, also known as the receiver.
There are two broad types of serial communication: synchronous and asynchronous.
There are a very large number of different standards and protocols for serial
communication, ranging from the very simple to the seriously complicated. It is
important to match the right protocol with the right application.
Serial communication – you are shooting a target using machine guns, where bullets
reach one by one to the target.
Parallel communication- you are shooting a target using a shotgun, where many
number of the bullets reach at the same time.
Asynchronous Data Transfer – The mode in which the bits of data are not
synchronized by a clock pulse. Clock pulse is a signal used for synchronization of
operation in an electronic system.
Synchronous Data Transfer – The mode in which the bits of data are
synchronized by a clock pulse.
RS232 is a standard communication protocol that defines the electrical and physical
characteristics of a serial communication system. It is used for data transfer between
two devices and is typically used for short-distance communications.
RS232 is a standard protocol used for serial communication, it is used for connecting
computer and its peripheral devices to allow serial data exchange between them. As it
obtains the voltage for the path used for the data exchange between the devices. It is
used in serial communication up to 50 feet with the rate of 1.492kbps. As EIA defines,
the RS232 is used for connecting Data Transmission Equipment (DTE) and Data
Communication Equipment (DCE).
Universal Asynchronous Data Receiver &Transmitter (UART) used in connection
with RS232 for transferring data between printer and computer. The microcontrollers are
not able to handle such kind of voltage levels, connectors are connected between RS232
signals. These connectors are known as the DB-9 Connector as a serial port and they
are of two type’s Male connector (DTE) & Female connector (DCE).
Electrical Specifications
Let us discuss the electrical specifications of RS232 given below:
Voltage Levels: RS232 also used as ground & 5V level. Binary 0 works with
voltages up to +5V to +15Vdc. It is called as ‘ON’ or spacing (high voltage level)
whereas Binary 1 works with voltages up to -5V to -15Vdc. It is called as ‘OFF’ or
marking (low voltage level).
Received signal voltage level: Binary 0 works on the received signal voltages
up to +3V to +13 Vdc & Binary 1 works with voltages up to -3V to -13 Vdc.
Slew Rate: The rate of change of signal levels is termed as Slew Rate. With its
slew rate is up to 30 V/microsecond and the maximum bitrate will be 20 kbps.
The ratings and specification changes with the change in equipment model.
TXD TRANSMITTER
RXD RECEIVER
GND GROUND
For example: The signals set to logic 1, i.e., -12V. The data transmission starts from
next bit and to inform this, DTE sends start bit to DCE. The start bit is always ‘0’, i.e.,
+12 V & next 5 to 9 characters is data bits. If we use parity bit, then 8 bits data can be
transmitted whereas if parity doesn’t use, then 9 bits are being transmitted. The stop
bits are sent by the transmitter whose values are 1, 1.5 or 2 bits after the data
transmission.
Mechanical Specification
For mechanical specifications, we have to study about two types of connectors that
is DB-25 and DB-9. In DB-25, there are 25 pins available which are used for many of
the applications, but some of the applications didn’t use the whole 25 pins. So, the 9 pin
connector is made for the convenience of the devices and equipments.
Now, here we are discussing the DB-9 pin connector which is used for connection
between microcontrollers and connector. These are of two types: Male Connector
(DTE) & Female Connector (DCE). There are 5 pins on the top row and 4 pins in the
bottom row. It is often called DE-9 or D-type connector.
What is Handshaking?
How can a transmitter, transmits and the receiver receives data successfully. So, the
Handshaking defines, for this reason.
Handshaking is the process which is used to transfer the signal from DTE to DCE to make
the connection before the actual transfer of data. The messaging between transmitter &
receiver can be done by handshaking.
No Handshaking:
If there is no handshaking, then DCE reads the already received data while DTE
transmits the next data. All the received data stored in a memory location known as
receiver’s buffer. This buffer can only store one bit so receiver must read the memory
buffer before the next bit arrives. If the receiver is not able to read the stored bit in the
buffer and next bit arrives then the stored bit will be lost.
As shown in below diagram, a receiver was unable to read the 4 th bit till the 5th bit arrival
and this result overriding of 4th bit by 5th bit and 4th bit is lost.
Hardware Handshaking:
It uses specific serial ports, i.e., RTS & CTS to control data flow.
In this process, transmitter asks the receiver that it is ready to receive data then
receiver checks the buffer that it is empty, if it is empty then it will give signal to
the transmitter that I am ready to receive data.
The receiver gives the signal to transmitter not to send any data while already
received data cannot be read.
Software Handshaking:
In this process, there are two forms, i.e., X-ON & X-OFF. Here, ‘X’ is the
transmitter.
It is used to control the data flow and prevent loss during transmission.
RS232 serial communication is used in old generation PCs for connecting the
peripheral devices like mouse, printers, modem etc.
It is also used in PLC machines, CNC machines, and servo controllers because it is
far cheaper.
RS-485
In industrial environments, RS-485 is very popular because of its ability to
communicate over long distances, its multidrop capability, and its immunity to
noise. Multidrop means there can be multiple controlling devices with multiple
receivers on a single bus. With RS-485, there can be at least 32 receivers (and up
to 256 depending on the unit load) on one bus.
Like RS-232, there are many USB to RS-485 adapters available today, but the
pinouts do vary from manufacturer to manufacturer. This is because there is no
specified pinout by the standard, so it is important to check the pinouts of each
device to ensure compatibility.
RS-485 is typically two-wire and half-duplex, but it can also be a four-wire with
full-duplex. Mensor’s transducers are offered in four-wire with full-duplex. There
are benefits and drawbacks to both configurations. Half-duplex is easier to setup
because it has only two wires compared to four. On the other hand, half-duplex is
more difficult to program. This is because only one device can communicate at
once, so timing can become an issue. If two devices attempt to communicate at
the same time, a data collision will occur.
Another benefit of full-duplex is it allows the controller to continue sending
commands to the transducer if the transducer is in a continuous output mode.
With a half-duplex setup, continuous output would clog the transmission lines,
and not allow the controller to send commands reliably.
A four-wire device can be converted into a two-wire device, but this will void the
full-duplex features. This can be done by connecting RX+ with TX+ (A with Y),
and RX- with TX- (B with Z). This flexibility gives the user control over using
either configuration.
RS-422
RS-422 is the predecessor to RS-485, and the two are often a source of
confusion.
RS-422 is similar to RS-485 because they both use differential signalling,
communicate over long distances, and allow for multidrop. However, RS-422
multidrop allows for only one driver and a maximum of 10 receivers.
RS-422 is usually four-wire and full duplex. Because of this, it is common for RS-
422 ports to be used to communicate with full-duplex RS-485 devices.
RS-485 has more or less replaced RS-422 as the serial multidrop standard in the
industry.
Below is a table summarizing the key features of the three protocols:
Controlled Area Network:
CAN stands for Controller Area Network protocol. It is a protocol that was developed by
Robert Bosch in around 1986. The CAN protocol is a standard designed to allow the
microcontroller and other devices to communicate with each other without any host
computer.
CAN simplified the process, whereby different electronic modules could communicate
with each other by using a common cable.
A vehicle contains a network of electronic devices that share data and information with
one another. A spark-ignition engine, for instance, requires a spark to initiate the
combustion chamber. Timing is important here. To ensure this occurs accurately, it
“communicates” with the vehicle’s engine control unit, which chooses the ideal time for
the ignition to provide the power and fuel efficiency.
However, for two or more devices to interact, they must be equipped with hardware and
software to properly communicate. Before CAN was used in vehicles, each electronic
device was connected to another via wires (or, more specifically, point-to-point wiring).
This worked effectively enough when the functions were basic. But one of the major
problems for automotive engineers as electronics advanced was linking the ECUs of
different devices so that real-time information could be exchanged. The CAN protocol
was designed to address this problem.
An algorithmic diagram that shows the connectivity between devices using the CAN protocol.
The electronic devices in a vehicle can be classified under different domains and CAN
facilitates multi-domain communication, which is a great help to auto engineers.
A vehicle’s multi-domain communication, supported by the CAN protocol.
The CAN protocol is a set of rules for transmitting and receiving messages in a network
of electronic devices. It defines how data is transferred from one device to another in a
network.
Interestingly, CAN was developed with a specific focus on the auto industry but its
architecture and advantages have led several other industries (such as the railway,
aircraft, and medical sectors) to adopt the protocol as well.
The CAN controller converts messages from the nodes per the CAN protocols, which are
then transmitted via the CAN transceiver over the serial bus — and vice versa. The
controller is a chip that’s embedded inside the host controller of the node or added
separately.
The CAN protocol does not follow the master-slave architecture, which means every
nodes has access to read and write data on the CAN bus. When the node is ready to
send data, it checks the availability of the bus and writes a CAN frame onto the network.
A frame is a structure that carries a meaningful sequence of bit or bytes of data within
the network.
All nodes using the CAN protocol receive a frame and depending on the node’s ID, the
CAN “decides” whether or not to accept it. If multiple nodes send the message at the
same time, the node with the highest priority (so, the lowest arbitration ID) receives the
bus access. Lower priority nodes must wait until the bus is available.
Benefits
Low cost: Since a CAN serial bus uses two wires (with high-volume and
low-cost production), it offers a good price-to-performance ratio.
Reliable: CAN offers excellent error-detection and error-handling
mechanisms, which provides highly reliable transmission. It’s also largely
immune to electromagnetic interference.
Flexible: CAN nodes are not limited by the protocol and can be easily
connected or disconnected.
Fast: CAN supports a data rate of 1 MBit/s @ 40m bus length.
Multi-master communication: Any node can access the bus
Fault confinement: Faulty nodes do not disturb the communication.
Broadcast capabilities: Messages can be sent to one /many/all nodes.
Standardized: ISO has standardized the CAN protocol via ISO-DIS 11898
(for high-speed applications) and ISO-DIS 11519-2 (for low-speed
applications). The CAN protocol is also standardized by industry
organizations, such as the SAE-Society of Automotive Engineers.
CAN architecture
The CAN protocol uses the existing OSI reference model to transfer data between
the nodes connected in a network. The OSI reference model represents a set of
seven layers where data passes through during communication between
connected devices. The seven-layered structure of the OSI model is reliable and
widely used in several communication protocols.
· Presentation layer
The most important function of this layer is defining data formats such as ASCII text,
EBCDIC text BINARY, BCD and JPEG. It acts as a translator for data into a format
used by the application layer at the receiving end of the station.
· Session layer
It allows to establishing, communicating and terminating sessions between processes
running on two different devices performing security, name recognition and logging.
· Transport layer
The transport layer ensures that messages are delivered error-free, in sequence, and
without loss or duplication. It relieves the higher layer from any concern with the
transfer of data between them and their peers.
· Network layer
It provides end to end logical addressing system so that a packet of data can be
routed across several layers and establishes, connects and terminates network
connections.
{C1. MAC (Medium Access Control) layer: It performs frame coding, error
detection, signaling, serialization and de-serialization.
LLC (Logical Link Control) layer: The LLC sub layer
provides multiplexing mechanisms that make it possible for several network
protocols (IP, Decnet and Appletalk) to coexist within a multipoint network and to
be transported over the same network medium. It performs the function of
multiplexing protocols transmitted by MAC layer while transmitting and decoding
when receiving and providing node-to-node flow and error control.
· Physical layer
The physical layer transmits bit from one device to another and regulates the
transmission of bit streams. It defines the specific voltage and the type of cable to be
used for transmission protocols. It provides the hardware means of sending and
receiving data on a carrier defining cables, cards and physical aspects.
CAN protocol uses lower two layers of OSI i.e. physical layer and data link layer. The
remaining five layers that are communication layers are left out by BOSCH CAN
specification for system designers to optimize and adapt according to their needs.
Fig. 7: Block Diagram Showing Various Layers of a Nework Using CAN Protocol
The concept of the CAN protocol can be understood using the figure above.
Every node has a Host controller also known as micro-controller which is a small
and low-cost computer .Host controller implements application layer of OSI
model. Micro-controller gathers information from other electronic control units
like braking, steering, power windows etc. to communicate with other nodes and
transfers it to CAN controller. CAN controller incorporate logical link control and
MAC medium access control of data link layer. LLC allows filtering of messages by
using unique ID on each message then MAC sub layer frames the message.
Once, framing is done it is followed by arbitration, error detection and
acknowledgement that all comes under MAC sub layer of data link. The frame is
transferred to CAN trans-receiver, for encoding and decoding. Finally CAN trans-
receiver synchronizes with the CAN bus to send the message to anther node.
Terms associated with CAN protocol.
BUS VALUES
Binary values in CAN protocol are termed as dominant and recessive bits.
Message Framing
Messages in CAN are sent in a format called frames. A frame is defined structure,
carrying meaningful sequence of bit or bytes of data within the
network. Framing of message is done by MAC sub layer of Data Link Layer .There are
two type of frames standard or extended .These frames can be differentiated on the
basis of identifier fields. A CAN frame with 11 bit identifier fields called Standard
CAN and with 29 bit identifier field is called extended frame.
Standard frame
Fig. 10: Figure Showing How Message Is Framed in A Standard CAN Frame
{C· SOF – Start of Frame bit. It indicates start of message and used to
synchronize the nodes on a bus. A dominant bit in the field marks the start of
frame.
· IDENTIFIER – It serves dual purpose one, to determine which node has access
to the bus and second to identify the type of message.
· RTR – Remote Transmission Request. It identifies whether it’s a data frame or a
remote frame .RTR is dominant when it is a data frame and recessive when it is a
remote frame.
{C}{· IDE – Identifier Extension. It is used to specify the frame format.
Dominant bit is for standard frame and recessive for extended frame.
{C}· R0 – Reversed bit. Not used currently and kept for future use.
{C· DLC – Data Length Code. It is 4 bit data length code that contains the
number of bytes being transmitted.
{· DATA– Used to store up to 64 data bits of application data to be transmitted.
{C}· CRC– Cyclic Redundancy Check. The 16-bit (15 bits plus delimiter) cyclic
redundancy check (CRC) contains the checksum of the preceding application data
for error detection.
{· ACK – Acknowledge (ACK) field. It compromises of the ACK slot and the ACK
delimiter. When the data is received correctly the recessive bit in ACK slot is
overwritten as dominant bit by the receiver.
{C}· EOF– End of Frame (EOF). The 7-bit field marks the end of a CAN frame
(message) and disables
Bit – stuffing, indicating a stuffing error when dominant.
{C}· IFS – Inter Frame Space that specifies minimum number of bits separating
consecutive messages. It provides the intermission between two frames
and consists of three recessive bits known as intermission bits. This time allows
nodes for internal processing before the start of next frame.
EXTENDED CAN
{C· SRR- Substitute Reverse Request. The SRR bit is always transmitted as a
recessive bit to ensure that, in the case of arbitration between a Standard Data
Frame and an Extended Data Frame, the Standard Data Frame will always have
priority if both messages have the same base (11 bit) identifier.
{· R1- It is another bit not used currently and kept for future use.
Message frame
There are four different frames which can be used on the bus.
Data frames– These are most commonly used frame and used when a node transmits
information to any or all other nodes in the system. Data Frames consist of fields that
provide additional information about the message as defined by the CAN specification.
Embedded in the Data Frames are Arbitration Fields, Control Fields, Data Fields, CRC
Fields, a 2-bit Acknowledge Field and an End of Frame.
Fig. 12: Data Frames Used In A CAN Network
· Overload frame-It is similar to error frame but used for providing extra
delay between the messages. An Overload frame is generated by a node when it
becomes too busy and is not ready to receive.
Fig. 14: Overload Frame Present in A CAN Network
Arbitration
It is a mechanism which resolves the conflict when two or more nodes try to
send the message at the same time. In this technique whenever the bus is free any
unit can transmit a message. If two or more units starts transmitting at the same time
access to the bus is conflicted, but this problem can be solved by arbitration using
identifier. During arbitration every transmitter compares the value of transmitted bit with
bit value on the bus. If the bit value is same, the node continues to send the bits. But at
any time if transmitted bit value is different from bus value the dominant bit overwrites
the recessive bits. The arbitration field of the CAN message consists of an 11- or 29-bit
identifier and a remote transmission (RTR) bit. The identifier having lowest numerical
value has the highest priority. RTR simply distinguishes between remote frame for which
RTR is recessive and data frame for which RTR is dominant. If both data frame and
remote frame with the same identifier is initiated at the same time data frame will
prevail over remote frame. With the concept of arbitration neither information nor time is
lost.
This is one of the attributes of CAN that makes it robust. CAN protocol has five methods
of error checking, out of which three are at message level while other two are at bit
level. Every frame is simultaneously accepted or rejected by every node in the network.
If a node detects an error it transmits an error flag to every node and destroys the
transmitted frame and the transmitting node resends the frame
Message level
CRC check
In this stage a 15-bit cyclic redundancy check value is calculated by transmitting node
and is transmitted in the CRC field. This value is received by all nodes. Then all the
nodes calculate CRC value and matches the results with the transmitted value. If values
differ than an Error Frame is generated. Since one of the nodes did not receive the
message properly it is resent.
ACK slots
Form Error
End of frame, Inter-frame space, Acknowledge Delimiter are fields that are always
recessive, if any node detects dominant bit in one of these fields than CAN protocol calls
it a violation and a Form Frame is generated and original message is resent after certain
period.
Bit level
Stuff error
Bit error
A node that is sending the bit always monitors the bus. If the bit sent by transmitter
differs from the bit value on the bus then error frame is generated. But there is an
exception in case of arbitration field or Acknowledge slot where a recessive bit is sent
and a dominant bit is received. Then no Bit Error is occurs when dominant bit is
monitored.
Conclusion
CAN protocol initially developed for in-vehicle networking of automobiles has expanded
its applications in various other industries. The application started for luxurious cars is
now being used in heavy duty vehicles like trucks, buses, trains and rail vehicles. The
unique feature of CAN that allows various electronic units to communicate with each
other made it important in healthcare domain. For example intensive care units and
operating rooms where time and communication is of utmost importance. Entertainment
industry also used CAN protocols to improve features in studios to control lights and door
system and to control stage of theatres, event halls etc. Gambling machines and toys
are other examples in entertainment field. In the field of science the high energy
experiments and astronomical telescope use CAN in embedded network.
Inter-Integrated Circuit:
I2C stands for Inter-Integrated Circuit. It is a bus interface connection protocol
incorporated into devices for serial communication. It was originally designed by Philips
Semiconductor in 1982. Recently, it is a widely used protocol for short-distance
communication. It is also known as Two Wired Interface(TWI).
Working of I2C Communication Protocol :
It uses only 2 bi-directional open-drain lines for data communication called SDA and
SCL. Both these lines are pulled high.
Serial Data (SDA) – Transfer of data takes place through this pin.
Serial Clock (SCL) – It carries the clock signal.
I2C operates in 2 modes –
Master mode
Slave mode
Each data bit transferred on SDA line is synchronized by a high to the low pulse of each
clock on the SCL line.
According to I2C protocols, the data line can not change when the clock line is high, it
can change only when the clock line is low. The 2 lines are open drain, hence a pull-up
resistor is required so that the lines are high since the devices on the I2C bus are
active low. The data is transmitted in the form of packets which comprises 9 bits. The
sequence of these bits are –
Read/Write Bit :
A high Read/Write bit indicates that the master is sending the data to the slave,
whereas a low Read/Write bit indicates that the master is receiving data from the
slave.
ACK/NACK Bit :
After every data frame, follows an ACK/NACK bit. If the data frame is received
successfully then ACK bit is sent to the sender by the receiver.
Addressing :
The address frame is the first frame after the start bit. The address of the slave with
which the master wants to communicate is sent by the master to every slave
connected with it. The slave then compares its own address with this address and
sends ACK.
START condition plus address packet plus one more data packet plus STOP
condition collectively form a complete Data transfer.
Advantages :
Can be configured in multi-master mode.
Complexity is reduced because it uses only 2 bi-directional lines (unlike SPI
Communication).
Cost-efficient.
It uses ACK/NACK feature due to which it has improved error handling
capabilities.
Limitations :
Slower speed.
Half-duplex communication is used in the I2C communication protocol.
Comparison between I2C and SPI Communication Protocols
Improved due to
Error handling Not as robust
ACK/NACK feature
Multi-master
Yes Yes
configuration
Synchronous
Yes Yes
communication
Arbitration Yes No
The Local Interconnect Network (LIN):
It offers lower performance and reliability - but also drastically lower costs. Below we
provide a quick overview of LIN bus and a comparison of LIN bus vs. CAN bus.
1999: LIN 1.0 released by the LIN Consortium (BMW, VW, Audi, Volvo, Mercedes-
Benz, Volcano Automotive & Motorola)
2000: The LIN protocol was updated (LIN 1.1, LIN 1.2)
2002: LIN 1.3 released, mainly changing the physical layer
2003: LIN 2.0 released, adding major changes (widely used)
2006: LIN 2.1 specification released
2010: LIN 2.2A released, now widely implemented versions
2010-12: SAE standardized LIN as SAE J2602, based on LIN 2.0
2016: CAN in Automation standardized LIN (ISO 17987:2016)
As such, LIN bus has exploded in popularity in the last decade with >700 million nodes
expected in automotives by 2020 vs ~200 million in 2010.