Protocol Converter For Transmission Of Data Computer Science Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

CAN bus is increasingly used in wide range of applications for its superiority, but it couldn't communicate with computer directly. The paper describes the design of RS232 and CAN bus protocol converter depending on PIC Microcontroller, which solves the problem that CAN networks can not directly communicate with PC. Considering cost and converter size, the paper will talk about PIC18F4580 with integrated CAN microcontroller designed for RS232 and CAN protocol converters to facilitate the direct communication between computers and CAN bus. Measurement & transmission of pressure on CAN bus to PC is taken as one of the application. In model system two PIC controllers are employed as two different nodes, first node measures the physical (Pressure) parameter, then transmits digital packets on CAN bus and another node receives & sends it to computer. Sensor basically measures pressure in the analog domain and PIC controller built-in 10 bit ADC converts the analog data from sensor into digital number. This is processed and encoded by the same controller and sent the digital code to another PIC controller through a coaxial cable. The receiving controller can be used for analysis, display and or control purpose. Transmission and reception of data is performed by a pair of CAN transceivers. PIC controller supports CAN transceiver. The research intends to develop a data transmission system in the textile industries , Automobile etc. where pressure is to be Measured In Noisy Environment.

Introduction: CAN bus are being used more and more widely in the areas of automotive, machinery, CNC machine tools, medical devices, smart sensors for its high-performance, high reliability and flexible design features. However, data on CAN bus could not directly communicate with computer. At present there are more and more MCU with internal CAN controller integration. In this paper, CAN bus and RS232 protocol converter is designed based on Microchip's PIC18F4580 MCU, so that computer can read data on CAN bus directly and also send control commands to CAN bus through the RS232 interface.The Controller Area Network (CAN) is a high-integrity serial data communication bus for real-time applications for networking "intelligent" devices as well as sensors within a system or sub-system, which operates at baud rates up to 1 Mbps. The CANbus was originally developed by the German company Robert Bosch GmbH for use in the car industry to provide a cost effective communication bus[3]. In car electronics CAN bus is as an alternative to expensive and cumbersome wiring looms in the mid 1980s. Nowadays CAN is being used in an increasing number of applications in the automotive industry and in many other industrial applications where noise is the major problem.

This paper will explain the overview of CAN bus ,system design using CAN bus protocol,system hardware,software & result.

Keywords: RS232, CAN Protocol Converter, PIC MCU, Pressure

CAN bus Features:

(1) Good real-time. CAN bus, which uses CSMA / CD media access method, is a multi-master field bus. This approach is similar with Peer to Peer approach of large-scale network, thus coincides with the open structure. Regardless of master-slave, information can be sent to free bus by any node at any time, which is a flexible means of communication, and this feature can also be used to constitute a (fault-tolerant) multi-machine backup system easily. Each node of the CAN receives all the information in the bus. Packet filtering and shielding mechanism enable each node quickly & decide whether current packet enters into the receive buffer or not so as to reduce the information processing time which has nothing to do with the node.

(2) Fault isolation is good. CAN uses non-destructive arbitration, when two or more nodes simultaneously send data to the network, the identifier of data frame determines the priority of the data frame, that small identifier means high-priority, large identifier equals to lowpriority. Nodes which send high-priority information continue to send data, and nodes which send low-priority information take the initiative to exit the bus. For a serious fault node, it will automatically turn off the bus function, which does not affect the work of other nodes but avoids network conflicts or a decrease of arbitration time. In the case of multi-transmission, lost information can be made up for through data fusiotechnology, which is caused by transmission or equipment failures

(3) Long distance communication. The largest rate of CAN communication can be achieved 1Mbps/40m, the maximum transmission distance can reach lOKm/50Kbps.

(4) Good anti-mistake transmission design. CAN with short-frame structure (8 effective bytes for each frame) allows short data transmission time, low probability of interference and short re-sending time. And each frame of information has CRC error checking and other measures to ensure the low error rate of data transmission.

(5) Theoretically CAN bus can connect 2000 nodes.In fact less than 110 is appropriate; it can satisfy the needs of majority users. CAN bus can transmit and receive data in several ways such as point-to-point, point-to-multipoint and overall broadcast. CAN bus transmission uses twisted pair and has no special requirement for the transmission medium.

The CAN protocol Supports two message frame formats. The

CAN base frame supports 11 bits for the identifier,and CAN extended frame supports a length of 29bits for identifier[4].

Fig. 2 CAN Standard 11 bit identifier

System Hardware:

PIC18F4580CAN module introduction:

The Controller Area Network (CAN) module is a serial interface which is useful for communicating with other peripherals or microcontroller devices. This interface, or protocol, was designed to allow communications within noisy environments.The CAN module in 18F4580 is a communication controller, which is the topic involved in this paper. It implementing the CAN 2.0A or B protocol as defined in the BOSCH specification. The module will support CAN 1.2, CAN 2.0A,CAN 2.0B Passive and CAN 2.0B Active versions of the protocol. [3]

The module features are as follows:(1) consistent with the ISO model; (2) Implementation of the CAN protocol CAN 1.2, CAN 2.0A and CAN 2.0B; (3) The CAN module supports the following frame types: Standard Data Frame; Extended Data Frame; Remote Frame; Error Frame; overload Frame and so on (4) with two priority receive buffer and three priority send buffer; (5) 6 to accept filter: 2 high priority receive buffers, and the remaining 4 low priority receive buffers; (6) with 2 shielding filters, corresponding to two different receiver buffer; (7) with six kinds of operating mode settings: Request Configuration mode; Request Listen Only mode; Request Loop mode; Request Disable mode; Request Normal mode; (8)supporting short-frame structure, Standard and extended data frames, 0-8 bytes data length; (9) Programmable wake-up functionality with integrated low-pass filter; (10)Signaling via interrupt capabilities for all CAN receiver and transmitter error states; (11)Programmable Loop mode supports self-test operation; (12)Programmable clock source; (13) Programmable link to timer module for time-stamping and network synchronization;(14)Low-power Sleep mode. The CAN bus module consists of a protocol engine and message buffering and control. The CAN protocol engine automatically handles all functions for receiving and transmitting messages on the CAN bus. Messages are transmitted by first loading the appropriate data registers. Status and errors can be checked by reading the appropriate registers. Any message detected on the CAN bus is checked for errors and then matched against filters to see if it should be received and stored in one of the two receive registers. The CAN module uses the RB2/CANTX and RB3/CANRX pins to interface with the CAN bus. In normal mode, the CAN module automatically overrides TRISB<2>. The user must ensure that TRISB<3> is set. CAN module of PIC18F4580 is configured with three send buffers. If needed, TXBnCON (n is 0, 1, 2) TXPR1, TXPR0 bit can be modified to set 4 different priorities. If the two send buffers have the same priority, then the send buffer with a bigger number has the higher priority.Messages will be sent in order according to the level of priority. You can start sending messages by sending data to TXBnDm (n is 0, 1, 2, m is 0-8) and then set TXREG bit of TXBnCON. You can determine whether the messages are sent successfully through TXB0IF bit of PIR3. CAN module of PIC18F4580 is configured of the 2 receive buffers, 6 receive filters and 2 receiver shielding filter. RXB0 corresponds to the receiving filter RXF0, RXF1; shielding filters RXM0, RXB1 correspond to the receiving filter RXF2, RXF3, RXF4, RXF5, shielding filters RXM1. In addition to these two receive buffers; PIC18F2580 is also equipped with a MAB (Memory Allocation Block) which receive all messages from the bus. When the node detects the messages on bus, the messages will be transmitted to MAB and will take its own arbitration and receive filters for comparison. If met, messages will be transmitted to the corresponding receive buffer. Shielding filter will decide which receive filter bit is effective.[7]

Pressure sensors:

Pressure sensors are used for control and monitoring in thousands of everyday applications. Pressure sensors can also be used to indirectly measure other variables such as fluid/gas flow, speed, water level, and altitude. The MPX series piezoresistive transducer is a state-of-the-art monolithic silicon pressure sensor designed for a wide range of applications, but particularly those employing a microcontroller with A/D inputs. This patented, single element transducer combines advanced micromachining techniques, thin-film metallization, and bipolar processing to provide an accurate, high level analog output signal that is proportional to the applied pressure. This is employed in the system as a pressure transducer[2].

Universal Synchronous Asynchronous Receiver Transmitter(USART):

The Universal Synchronous Asynchronous Receiver Transmitter (USART) module is one of the three serial I/O modules. (USART is also known as a Serial Communications Interface or SCI.) The USART can be configured as a full-duplex asynchronous system that can communicate with peripheral devices, such as CRT terminals and personal computers. It can also be configured as a half-duplex synchronous system that can communicate with peripheral devices, such as A/D or D/A integrated circuits, serial EEPROMs and so on.[6]


RS232 has been widely applied as a standard computer serial communication interface.. However, the transmission distance is short with a maximum 15M. Transfer rate is also relatively low with a maximum of 20Kb/s.. The serial ports TX and RX of PIC18F2580 are connected with MAX232 which can carry out full-duplex asynchronous communication with other RS232 interfaces


ADC stands for Analog to digital converter.PIC18f4580 has inbuilt 10 bit ADC.So it can measure from 0 to 1023.

Figure 4: System Hardware Diagram

System Software:

A] Transmitter Side

The appropriate algorithm required for sensing the analog input from sensor, converting it to digital equivalent data and then transmitting the same is shown in the proceeding section. In transmitter section, two main subroutines are used. One subroutine is to initialize CAN as transmitter and the ADC module[2]. The microcontroller software selects the rate of transmission as 100 kbps. This is sufficient for this pressure measurement. The other subroutine is to transmit the data using CAN through CAN transceiver MCP2551. In this subroutine, before transmitting, the digital data is obtained

from ADC module of the PIC 18F4580. Fig. 4 depicts the main transmitter flow chart.

B] Receiver Side

The main program calls two subroutines, one for initializing CAN module of PIC controller 18F4580, which acts as receiver. Here also the baud rate of 100 kbps is selected. The other subroutine is used to receive the transmitted data, manipulate it in to the pressure value and then display it as pressure on the computer. Fig. 5 depicts the main receiver flow chart.

Fig.5 Main Receiver

Results of experiment

This system use serial port of personal computer to receive and transfer data on RS232, and connected to the CAN network through the PIC MCU and the CAN communication module in the MCU. Converters can be two-way communication: On one hand it can receive data from the CAN bus and transfer it to the computer in standard RS232 format; On the other hand it can be put the data flow that is

received in RS-232 format into the data flow that compliance with CAN protocol and sent it to the CAN bus. By using this system with variety of sensors & CAN nodes we can collect

data on PC from each area of automobile in low cost as compared to other CAN protocol converters with lowest error.