CAN bus/RS232 interface design

Source: Internet
Author: User

CAN bus/RS232 interface design
[Date:] Source: foreign electronic components by Zhao Jie, Liu weijing, Sun Huijia, Li Nan [Font:Large Medium Small]

 

1 Introduction
CAN is called "Controller Area Network", that is, Controller LAN, is an international standard, high-price Field Bus, plays an important role in the field of automatic control. CAN is a multi-master serial communication bus with high real-time performance. Therefore, it is widely used in automobile industry, aviation industry, industrial control, security protection, and other fields.
Because the PC does not have the CAN interface, the CAN bus system consists of a PC and a smart node, which CAN be connected through RS232/CAN, parallel port/CAN, USB/CAN, ISA card/CAN, and PCI Card/CAN. When RS232/CAN is used for access, the CAN/RS232 interface must be used for standard conversion. To solve this problem, a CAN/RS232 smart level converter design scheme is proposed. SJAl000 is used as an independent CAN controller to complete the CAN communication protocol. The SJAl000 is connected with the driver to achieve electrical isolation between each point of the bus.

2 hardware circuit design
The hardware circuit of the CAN/RS232 smart level converter is mainly composed of a microprocessor, the microprocessor, the independent CAN communication controller SJAl000, the CAN bus driver 82C250, the high-speed Photoelectric Coupler 6N136, the TTL level and the RS232 level converter icl133, And the LED digital tube. the display circuit and the dialing Circuit that provides the initial address for SJAl000, the structure diagram 1 is shown in.

3 CAN controller SJAlOOO
SJAl000 is an independent CAN controller used in the field of mobile target and Industrial Area Network Control. This device is an alternative product of Philips CAN controller PCA82C200. SJAl000 has two working modes. This design adopts the PeliCAN working mode.
Design of interfaces between 3.1 SJAl000 and
The interface circuit 2 of sjal000 is shown in. In service. Sjal000 ADO ~ AD7 is connected to the P0 port of the c53. CS is connected to p3.4 of the c53. (the timer t0 does not work ). When p3.4 is 0, the system selects sjal000 and accesses the external Ram low-address area to implement read/write operations on the P0 port, so as to perform read/write operations on the corresponding register of sjal000. The RD, wR, and ale pins of sjal000 are connected to the corresponding pins of 192.168.0.0 respectively, and the int pins of sjal000 are connected to the into pins of AT89S52. The client can also access sjal000 through interruption. In order to enhance the stability of the system, the dual crystal oscillator is used. The 11.059 2 MHz crystal oscillator is used for the system, and the 16 MHz crystal oscillator is used for the sjal000. Dsl133 can be used for the reset circuit. The output pins Ares and SRES are respectively connected to the reset pins of AT89C51 5l and the reset pins of sjal000.

3.2 SJAl000 connection to drive
The tx0 and rx0 pins of sjal000 are not directly connected to the txd and rxd pins of 82C250, but are connected to 82C250 through high-speed optical coupling 6n136, which enhances the anti-interference capability of CAN bus nodes, this achieves electrical isolation between nodes of the bus. High-speed optical coupling 6n136 is used to protect sjal000 type CAN bus controller, which adopts 5 V DC-DC power supply on both sides. the VCC and vccl of the device can be completely isolated to improve the system's anti-interference capability and node stability and security. Figure 3 shows the connection circuit between sjal000 and can drive 82C250.

4 software programming
System software program design includes: main program, CAN node initialization subroutine, RS232 packet sending subroutine, RS232 packet receiving subroutine, can packet receiving subroutine and can packet sending subroutine. The main program flowchart 4 is shown.

4.1 CAN node Initialization
The independent CAN controller sjal000 must be enabled for CAN communication after power-on or hardware reset. After power-on, the 17 pin of sjal000 gets a reset level (low level), enabling it to enter the reset mode. Initialization includes setting the working mode, receiving and filtering mode, receiving and shielding registers and receiving code registers, baud rate parameters, and interrupt permitted registers. After the initialization is complete, sjal000 enters the working state and starts to execute the communication task.
To initialize the SJAl000 register, you must first set the position of the mode register (MOD) to l, then select the PeliCAN working mode through the clock division register (CDR), and disable the clock output (CLOCKOUT ); enable sending interrupt, overflow interrupt, and error warning interrupt through the interrupt enable register (IER); assign initial values to the receiving shield register (AMR) and receiving code (ACR) registers; set the baud rate through the bus timing register 0 (BTR0) and bus timing register 1 (BTRl); assign the initial value to the output control register (OCR); receive the buffer starting Address Register (RBSA) to set the start address of the receiver buffer limit 0; clear the TXERR; clear the error code capture register (ECC); then select the mode register (MOD) Again, and set the single filter, and return the working status.
4.2 send RS232 messages
The system contains a full-duplex serial transmission interface that can receive or transmit external data at the same time. The signal is TTL level. Because it is not compatible with the standard RS232 interface, it is necessary to power up the quasi-conversion IC to be connected with RS232. The serial transmission and receiving of data by using the special feature SBUF. After setting the communication protocol mode, run the command "mov subf, A "can be used to transmit data stored in the SBUF temporarily memory by TXD serial transmission.
4.3 RS232 message reception
The serial transmission control latencies of the Microcomputer 9th are controlled by the scon of the special control latches. The SCON sets the serial transmission mode, which is bits for sending and receiving, and interrupt the instruction during sending and receiving. The command "mov a, SBUF" reads external serial signals through the RXD pin and converts them into parallel data and saves them to the temporary storage.
4.4 CAN message transmission
According to the CAN protocol, packet transmission is completed by the independent CAN controller SJAl000. The master controller must combine the data to be sent into a frame of message in a specific format to transmit the data to the sending buffer, set "Send request" in the command register to 1, and then start SJAl000 to send the data.
4.5 CAN message reception
The CAN message receiving subroutine is responsible for receiving messages from nodes and handling other situations. The structure of the receiving subroutine is more complex than that of the sending subroutine, because when receiving a message, it must handle the same situation, such as bus shutdown, error alarms, and receiving overflow. There are two ways to receive and send SJAl000 packets: interrupt and query. The query method should prohibit reception of interruption enabling, while the interruption method is generally used in scenarios with high real-time requirements.
In the interrupt mode, if the SJAl000 has received a packet and the packet passes the acceptance filter and is saved to the receiving FIFO, a receiving interruption occurs. Therefore, the master controller immediately works, sends the received packets to the message memory, and then sends a release receiving buffer command through the corresponding mark "RRB" of the SET command register. Receiving more messages in limit 0 will lead to a new reception interruption. Therefore, you cannot read all valid messages in limit 0 within one interruption period. After the receiving buffer is released, SJAl000 checks whether there are more packets in the receiving buffer status (RBS) in the Status Register. All valid messages are read cyclically.

5 conclusion
In this system, SJAl000 is used as the CAN independent controller, and CAN/RS232 intelligent level converter is used as an example. The interface connection between CAN bus and single chip microcomputer is discussed, it has some reference value for the practical application of CAN bus.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.