ENGLISH 简体中文 日本語 한국어  


APPLICATION NOTE 3553

CAN-to-Ethernet Using the DS80C400

Abstract: This application note shows how to build a CAN-to-Ethernet solution using a DS80C400 microcontroller in a TINIm400/TINIs400 evaluation board. The example code allows the use of a TCP/IP connection to transfer data bidirectionally on the CAN and Ethernet networks. The complete project source is available for compilation in the Keil C environment.

Introduction

The DS80C400 is a highly capable, 8051-based microcontroller with Ethernet and CAN-bus network functionality. A Controller Area Network (CAN) bus is a popular high-reliability bus used in automobiles and industrial applications. Using the CAN bus, the DS80C400 will bridge between heterogeneous, networked manufacturing environments (the Ethernet), and thus ease integration among different tools. Bridging CAN to Ethernet lets the microcontroller monitor remote networks and control systems not designed to interface with the Ethernet.

This application note shows how to build a CAN-to-Ethernet solution using a TINIm400/TINIs400 Evaluation Kit, the Keil C compiler, and a simple C application.

The source code used in this application note is available for download (ZIP).

CAN Bus

The CAN messaging protocol uses frames that conform to the CAN specification. These frames include a CRC and bus arbitration bits to allow high-priority messages to override all others. The bit rate is determined by a combination of a time quantum (tqu) and two time segments (tSEG1 and tSEG2). The DS80C400 incorporates a single CAN controller, which provides operating modes that are fully compliant with the CAN 2.0B specification.

The CAN logical signaling may be placed on several types of busses, including copper and optical. In this example, we will use the differential bus defined by ISO 11898. A transceiver must be used which matches the bus standard; we will use a MAX3051 3.3V CAN transceiver.

TINI/DS80C400

All hardware components necessary for this application note are found on the TINIm400 circuit board and the TINIs400 socket board. The TINIm400 module provides the DS80C400 CPU, SRAM, and flash required for operation; the TINIs400 provides the socket for the module, as well as the Ethernet PHY, CAN transceiver, headers, and connectors for bridging Ethernet and CAN busses. We use the existing 14.7456MHz crystal and the clock multiplier built into the DS80C400 for an effective CPU frequency of 29.4912MHz. The CAN connector, J20, works with a standard DB9 to 5x2 connector, and the 120Ω CAN bus termination is enabled by bridging J19. Two TINIs400 boards can be connected to the same CAN network simply by connecting the corresponding CANH, CANL, and ground between the two boards.

Schematics for the TINIs400 and TINIm400 are available for download (ZIP).

Example

In this example, we use a 50kbps bit rate, which is a common CAN bit rate. The corresponding setup values, given our 29.49MHz clock rate, are a prescaler of 14, tSEG1 of 13, and tSEG2 of 7. Table 1 details standard bit rates available with this setup. Higher bit rates, up to 1Mbps, can be obtained by changing to a different CPU crystal (such as 15MHz). This adaptation would, however, make our example more complex by requiring a board modification. Please see the application note 2935, "Design Considerations for CAN Bus and Asynchronous Serial Interfaces" for more information on setting CAN bit rates on the DS80C400 microcontroller.

Table 1. Common Bit Rates Available Using a 29.4912MHz System Clock
Bit Rate Prescaler tqu tSEG1 tSEG2
10000 59 4.00µs 16 8
20000 41 2.78µs 13 4
50000 14 0.949µs 13 7

On the Ethernet side, we use TCP for communication, as we want guaranteed delivery of the CAN packets over the network. We set up a bidirectional pipe to shuttle data back and forth; data from the Ethernet is packed to the maximum CAN frame size of eight bytes and sent across the CAN bus. The data in frames received from the CAN bus is concatenated and sent across the Ethernet. At 50kbps, the CAN will be the bottleneck in this transfer.

Two processes run on the protocol bridge; one process handles CAN-to-Ethernet and the other Ethernet-to-CAN. This allows simultaneous bidirectional transfers. The main process creates the CAN-to-Ethernet bridge, and then blocks in the accept() function while waiting for an incoming TCP connection. When the connection occurs, the main process awakens the companion process to allow both to work on incoming data. Once a network connection has disconnected, the companion process goes to sleep while the main process waits for the next incoming connection.

Handling error in this application is simplistic. Any adaptation into a reliable system design requires handling of all error and failure modes.

Loading and Running the Example

The source code and a prebuilt HEX file are included in the ZIP file mentioned above. To load the HEX file, one needs the Microcontroller Tool Kit (MTK). Once MTK is installed and running, select TINI/DS80C400 from the selection menu. Then select Options->Configure Serial Port and select the port connected to the development board. Also set the speed to 115200. Then, select TINI->Reset. You should see a prompt similar to this:
DS80C400/DS80C41X Silicon Software - Copyright (C) 2002-2004 Maxim Integrated Products
Detailed product information available at http://www.maxim-ic.com

Welcome to the TINI DS80C400/DS80C41X Auto Boot Loader 1.2.0
Load the HEX file with File->Load HEX. Once the HEX file is loaded, press E to execute the application. You should now see something similar to this:
DS80C400 CAN to Ethernet Example
Built: Aug 8 2005 17:00:26

DS80C400/DS80C41X Silicon Software - Copyright (C) 2002-2004 Maxim Integrated Products
S/N: FB5E70038035DC89 MAC ID: 006035021122
DS80C400 Initialization Library Version 18
DS80C400 Kmem Library Version 6
DS80C400 Sock Library Version 10
DS80C400 Xnetstack Library Version 13
DS80C400 Task Library Version 9
DS80C400 DHCP Library Version 11
DS80C400 CAN Library Version 2
IP    : 192 168 1 2
Subnet: 255 255 255 0
Prefix: 16
Gate  : 192 168 1 1
New task started with task id 146
Bound to port: 4004
Waiting for connection
Now using a simple telnet client, connect to port 4004 at the IP address displayed. Anything typed will be received and transmitted across the CAN bus. If any CAN traffic is received, it will be sent back through the same telnet connection.

Performance

This sample application can be deployed on two Ethernet-to-CAN bridge setups to allow feedback and to measure performance from Ethernet-to-CAN-to-Ethernet. Connect J7 of both boards into an Ethernet hub or switch. Connect pins 3, 4, and 5 of J20 on one board to the same numbered pins on the other. Status can be monitored through a RS-232 serial connection to J12.

Because the DS80C400 at 29.49MHz can push about 160kBps through a TCP/IP connection over Ethernet, we will saturate the 50kbps CAN bus. Using an 11-bit ID and the full 8 bytes of data, we should have a total packet length of 110 bits. The throughput of this application was around 2400Bps, or 290 frames per second as measured in the Ethernet-to-CAN-to-Ethernet setup.

Conclusion

The DS80C400 is a fast microprocessor with I/O options that allow bridging of two popular communication busses. Ethernet-to-CAN allows non-CAN-enabled systems access to CAN-bus-enabled equipment through the common protocols of Ethernet and TCP/IP.



Relevant Links

We Want Your Feedback!


Automatic Updates
Would you like to be automatically notified when new application notes are published in your areas of interest? Sign up for EE-Mail™.



More Information  APP 3553: Jun 20, 2005
DS80C390 Dual CAN High-Speed Microprocessor Full Data Sheet
(PDF, 2MB)
Free Samples
DS80C400 Network Microcontroller Full Data Sheet
(PDF, 2.1MB)
Free Samples
DS80C410 Network Microcontrollers with Ethernet and CAN Full Data Sheet
(PDF, 2.7MB)
Free Samples
DSTINIM400 Networked Microcontroller Evaluation Board Full Data Sheet
(PDF, 876kB)
DSTINIM410 Networked Micro Evaluation Board Full Data Sheet
(PDF, 1.3MB)
 

Download, PDF FormatDownload, PDF Format (28kB)
 AN3553, AN 3553, APP3553, Appnote3553, Appnote 3553



         


      Privacy Policy    Legal Notices

      Copyright © 2008 by Maxim Integrated Products, Dallas Semiconductor