1 Introduction
CAN, the full name of which is "Controller Area Network", is an international standard, cost-effective fieldbus that 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 the automotive industry, aviation industry, industrial control, safety protection and other fields.
Since PCs do not have CAN interfaces, the CAN bus system composed of PCs and intelligent nodes can be connected in RS232/CAN, parallel port/CAN, USB/CAN, ISA card/CAN and PCI card/CAN. When RS232/CAN is used for access, CAN/RS232 interface standard conversion is required. In response to this problem, a CAN/RS232 intelligent level converter design scheme is proposed, using SJAl000 as an independent CAN controller to complete the CAN communication protocol. A high-speed optocoupler is connected between SJAl000 and the driver to achieve electrical isolation between the bus points.
2 Hardware Circuit Design
The hardware circuit of CAN/RS232 intelligent level converter mainly consists of microprocessor AT89C52, independent CAN communication controller SJAl000, CAN bus driver 82C250, high-speed photocoupler 6N136, TTL level and RS232 level converter ICL232, LED digital tube display circuit and dial circuit that provides the initial address for SJAl000. Its structural block diagram is shown in Figure 1.
3 CAN controller SJAlOOO
SJAl000 is an independent CAN controller, which is used in the field of mobile target and industrial local area network control. This device is a substitute for the CAN controller PCA82C200 of Philips. SJAl000 has two working modes, and this design adopts the PeliCAN working mode.
3.1 Interface design of SJAl000 and AT89C52
The interface circuit of SJAl000 and AT89C52 is shown in Figure 2. AT89C52 is responsible for the initialization of SJAl000 and controls SJAl000 to realize communication tasks such as data reception and transmission. ADO~AD7 of SJAl000 is connected to the P0 port of AT89C52, and CS is connected to P3.4 of AT89C52 (the timer T0 of AT89C52 does not work). When P3.4 is 0, AT89C52 selects SJAl000 and implements the read/write operation of the P0 port by accessing the low address area of the external RAM, thereby performing read/write operations on the corresponding register of SJAl000. The RD, WR, and ALE pins of SJAl000 are connected to the corresponding pins of AT89C52 respectively, and the INT pin of SJAl000 is connected to the INTO pin of AT89C52. AT89C52 can also access SJAl000 through interruption. In order to enhance the stability of the system, a dual crystal oscillator is used. The AT89C52 uses a 11.059 2 MHz crystal oscillator, and the SJAl000 uses a 16 MHz crystal oscillator. The reset circuit can use DS1232, and its output pins ARES and SRES are connected to the RESET pin of AT89C51 and the RESET pin of SJAl000 respectively.
3.2 Connection between SJAl000 and driver
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 optocoupler 6N136, which can enhance the anti-interference ability of CAN bus nodes and realize electrical isolation between bus nodes. High-speed optocoupler 6N136 is used to protect SJAl000 CAN bus controller. The optocoupler uses 5 V DC-DC power supply on both sides. It can completely isolate the VCC and VCCl of the device, improve the anti-interference ability of the system and the stability and safety of the node. Figure 3 shows the connection circuit between SJAl000 and CAN driver 82C250.
4 Software Program Design
The system software program design includes: main program, CAN node initialization subroutine, RS232 message sending subroutine, RS232 message receiving subroutine, CAN message receiving subroutine and CAN message sending subroutine. The main program flow chart is shown in Figure 4.
4.1 CAN Node Initialization
The independent CAN controller SJAl000 must set up CAN communication after power-on or hardware reset. After power-on, the 17th pin of SJAl000 gets a reset level (low level) to put it into reset mode. Initialization includes setting the working mode, receiving filter mode, receiving mask register and receiving code register, baud rate parameters and interrupt enable register. After the initialization setting is completed, SJAl000 enters the working state and starts to perform communication tasks.
To initialize the SJAl000 register, first reset the mode register (MOD) to 1, then select the PeliCAN working mode through the clock divider register (CDR), and turn off the clock output (CLOCKOUT); enable the transmit interrupt, overflow interrupt, and error warning interrupt through the interrupt enable register (IER); assign initial values to the receive mask register (AMR) and receive code (ACR) register; set the baud rate through the bus timing register 0 (BTR0) and bus timing register 1 (BTR1); assign initial values to the output control register (OCR); set the start address of the receive buffer FIF0 through the receive 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) again, set the single filter, and return to the working state.
4.2 RS232 message transmission
AT89C52 contains a set of full-duplex serial transmission interfaces, which can simultaneously receive or transmit external data, and its signal is TTL level. Since it is incompatible with the standard RS232 interface, a level conversion IC must be added to connect to RS232. AT89C52 serial transmission and reception of data are completed through the special function register SBUF. After setting the communication protocol mode, the data stored in the SBUF register can be transmitted serially from the pin TXD through the instruction "MOV SUBF, A".
4.3 RS232 message reception
The AT89C52 serial transmission control register is controlled by the special control register SCON. SCON sets the serial transmission working mode. Its 9th bit and the interrupt indication work during transmission and reception. Through the instruction "MOV A, SBUF", the external serial signal is read in through the RXD pin and converted into parallel data and stored in register A.
4.4 CAN message transmission
According to the CAN protocol, message transmission is completed by the independent CAN controller SJAl000. The main controller must combine the data to be sent into a frame message according to a specific format and transmit it to the send buffer, set the "send request" in the command register to 1, and then start SJAl000 to send.
4.5 CAN message reception
The CAN message reception subroutine is responsible for the node's message reception and other processing. The receiving subroutine is more complex in structure than the sending subroutine, because when receiving a message, it is necessary to handle situations such as bus shutdown, error alarm, and receive overflow. There are two ways to receive and send SJAl000 messages: interrupt mode and query mode. The query mode should prohibit the receive interrupt enable, and the interrupt mode is generally used in situations with high real-time requirements.
In the interrupt mode, if SJAl000 has received a message, and the message passes the acceptance filter and is stored in the receive FIFO, a receive interrupt is generated. Therefore, the main controller works immediately, sends the received message to the message memory, and then sends a receive buffer release command by setting the corresponding flag "RRB" in the command register. Receiving more messages in FIF0 will generate a new receive interrupt, so all valid information in FIF0 cannot be read out in one interrupt cycle. After the receive buffer is released, SJAl000 will check whether there are more messages in the receive buffer status (RBS) in the status register, and all valid information will be read out cyclically.
5 Conclusion
This system design uses SJAl000 as a CAN independent controller, takes CAN/RS232 intelligent level converter as an example, and discusses the interface connection between CAN bus and single-chip microcomputer, which has a certain reference value for the practical application of CAN bus.
Previous article:Realizing High-Speed Analog-to-Digital Converters Using CMOS Technology
Next article:Complete battery pack design for single or dual cell powered portable applications
- Popular Resources
- Popular amplifiers
- MathWorks and NXP Collaborate to Launch Model-Based Design Toolbox for Battery Management Systems
- STMicroelectronics' advanced galvanically isolated gate driver STGAP3S provides flexible protection for IGBTs and SiC MOSFETs
- New diaphragm-free solid-state lithium battery technology is launched: the distance between the positive and negative electrodes is less than 0.000001 meters
- [“Source” Observe the Autumn Series] Application and testing of the next generation of semiconductor gallium oxide device photodetectors
- 采用自主设计封装,绝缘电阻显著提高!ROHM开发出更高电压xEV系统的SiC肖特基势垒二极管
- Will GaN replace SiC? PI's disruptive 1700V InnoMux2 is here to demonstrate
- From Isolation to the Third and a Half Generation: Understanding Naxinwei's Gate Driver IC in One Article
- The appeal of 48 V technology: importance, benefits and key factors in system-level applications
- Important breakthrough in recycling of used lithium-ion batteries
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- An oscilloscope can only measure waveforms? That’s too narrow!
- Questions about System Control Block
- [AB32VG1 Development Board Review] RGB_LED Color Change Display
- Playing with Zynq Serial 2——GPIO peripherals of Zynq PS
- Ask the big guy, about the problem of DS1302
- Why is DS heavily doped in the MOS tube structure?
- The free evaluation Perf-V development board has been successfully ported and run on the Wujian100 platform
- [Goodbye 2021, Hello 2022] Keep a low profile, face reality, and keep moving forward for your dreams
- How to display black text on white background in FPGA?
- EEWORLD University Hall----Application of IoT sensing technology