1 Introduction

Can, fully known as “controller area network”, is an international standard field bus with high price, which 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 automotive industry, aviation industry, industrial control, safety protection and other fields.

Because the PC has no can interface, the CAN bus system composed of PC and intelligent node can be accessed by RS232 / can, parallel port / can, USB / can, ISA card / can and PCI card / can. When RS232 / can is used, can / RS232 interface standard conversion is needed. To solve this problem, a design scheme of can / RS232 intelligent level converter is proposed. Sjal000 is used as an independent can controller to complete can communication protocol. A high-speed optocoupler is connected between sjal000 and the driver to realize the electrical isolation between the bus points.

2 hardware circuit design

The hardware circuit of can / RS232 intelligent level converter is mainly composed of microprocessor AT89C52, independent can communication controller sjal000, can bus driver 82C250, high-speed optocoupler 6N136, TTL level and RS232 level converter ICL232, LED digital tube display circuit and the dial code circuit which provides initial address for sjal000. Its structure diagram is shown in Fig. 1.

Design of intelligent level converter based on CAN bus system

3 can controller sjalooo

Sjal000 is an independent can controller, which is used in the field of mobile target and industrial LAN control. This device is a substitute of Philips can controller pca82c200. Sjal000 has two working modes, and Pelican mode is adopted in this design.

3.1 interface design between sjal000 and AT89C52

The interface circuit between sjal000 and AT89C52 is shown in Figure 2. AT89C52 is responsible for initializing sjal000 and controlling sjal000 to realize data receiving and sending. ADO ~ Ad7 of sjal000 is connected to port P0 of AT89C52, CS is connected to p3.4 of AT89C52 (timer T0 of AT89C52 does not work). When p3.4 is 0, AT89C52 selects sjal000 and accesses the low address area of external RAM to realize the read / write operation of port P0, so as to perform read / write operation on the corresponding registers of sjal000. The RD, WR and ale pins of sjal000 are respectively connected with the corresponding pins of AT89C52, and the int pin of sjal000 is connected with the into pin of AT89C52. AT89C52 can also access sjal000 by interrupt. In order to enhance the stability of the system, dual crystal oscillator is used, AT89C52 adopts 11.059 2 MHz crystal oscillator, sjal000 uses 16 MHz crystal oscillator. The reset circuit can select dsl232, and its output pins Ares and SREs are respectively connected with the reset pin of at89c5l and the reset pin of sjal000.

Design of intelligent level converter based on CAN bus system

3.2 connection between sjal000 and driver

The tx0 and rx0 pins of sjal000 are not directly connected with the TXD and RXD pins of 82C250, but are connected with 82C250 through high-speed optocoupler 6N136, which can enhance the anti-interference ability of CAN bus nodes and realize the electrical isolation between the bus nodes. High speed optocoupler 6N136 is used to protect sjal000 can bus controller. 5 V DC-DC power supply is used on both sides of the optocoupler. The VCC and VCCL of the device can be completely isolated, and the anti-interference ability of the system and the stability and security of the node can be improved. Figure 3 shows the connection circuit between sjal000 and can driver 82C250.

Design of intelligent level converter based on CAN bus system

4 software programming

The system software program design includes: main program, can node initialization subroutine, RS232 message sending subprogram, RS232 message receiving subprogram, can message receiving subprogram and can message sending subprogram. The main program flow chart is shown in Figure 4.

Design of intelligent level converter based on CAN bus system

4.1 can node initialization

Independent can controller sjal000 must set can communication after power on or hardware reset. After power on, 17 pin of sjal000 gets a reset level (low level) to enter reset mode. Initialization includes setting working mode, receiving filtering mode, receiving mask register and receiving code register, baud rate parameter and interrupt permission register. After the initialization, sjal000 will enter the working state and start to perform communication tasks.

To initialize sjal000 register, firstly, reset the mode register (MOD) to L, then select Pelican working mode through CDR, and turn off clock output (clockout); secondly, enable sending interrupt, overflow interrupt and error warning interrupt through interrupt permission register (IER); The initial values are assigned to receive mask register (AMR) and receive code (ACR) registers, baud rate is set by bus timing register 0 (btr0) and bus timing register 1 (btrl), initial value is assigned to output control register (OCR), and start address of receive buffer fif0 is set by receiving buffer start address register (RBSA); Clear the transmit error count register (txerr), clear the error code capture register (ECC), and finally select the mode register (MOD), set the single filter, and return to the working state.

4.2 RS232 message sending

AT89C52 contains a set of full duplex serial transmission interface, which can receive or transmit external data at the same time, and its signal is TTL level. Because it is not compatible with standard RS232 interface, it is necessary to add level quasi conversion IC to connect with RS232. The serial sending and receiving data of AT89C52 are completed by special function register SBUF. After the communication protocol mode is set, the data stored in SBUF can be transmitted serially by pin TXD through instruction “mov subf, a”.

4.3 RS232 message receiving

AT89C52 serial transmission control register is controlled by special control register scon. Scon sets the working mode of serial transmission. When sending and receiving, its 9th bit and interrupt indication work. Through the instruction “mov a, SBUF” reads the external serial signal through the RXD pin, and converts it into parallel data and stores it in the register a.

4.4 can message sending

According to can protocol, message transmission is completed by sjal000, an independent can controller. The main controller must combine the data to be sent into a frame according to the specific format and transmit it to the sending buffer. Set the “send request” in the command register to 1, and then start sjal000 sending.

4.5 can message receiving

The can message receiving subroutine is responsible for the receiving of messages and the processing of other situations. The structure of receiving subroutine is more complicated than that of sending subroutine, because when receiving message, it has to deal with such situations as bus shutdown, error alarm and receiving overflow. There are two ways to receive and send sjal000 message: interrupt mode and query mode. Query mode should prohibit receiving interrupt enable, while interrupt mode is generally used in the case of high real-time requirement.

In interrupt mode, if sjal000 has received a message and the message passes the acceptance filter and is stored in the receive FIFO, a receiving interrupt is generated. Therefore, the main controller works immediately, sends the received message to the message memory, and then sends a release receive buffer command through the corresponding mark “RRB” of the set command register. More messages in receive fif0 will generate a new receive interrupt, so all valid information in receive fif0 cannot be read out in one interrupt period. After receiving buffer is released, sjal000 will check whether there are more messages in the received buffer state (RBS) in the status register, and all valid information will be read out in a loop.

Conclusion

In this system, sjal000 is used as the can independent controller, and the can / RS232 intelligent level converter is taken as an example to discuss the interface connection between CAN bus and single chip microcomputer, which has certain reference value for the practical application of CAN bus.

Responsible editor

Leave a Reply

Your email address will not be published. Required fields are marked *