A self-identification control method based on single-chip microcomputer CAN bus and USB bus
By using a microcontroller-based self-identification control method to detect the bus type and initialize the corresponding functions, the problem of redundant USB-to-CAN bus design is solved, and interface sharing and efficiency improvement are achieved.
Patent Information
- Application Number
- CN202111060578.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-10
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2041-09-10
AI Technical Summary
Existing USB-to-CAN bus designs are cumbersome, inefficient, have inadequate communication schemes, and lack convenient high-speed connection interface technologies.
A microcontroller-based self-identification control method for CAN and USB buses is adopted. By detecting the specific pin level of the microcontroller, the bus type of the master device is determined, and the corresponding functions are initialized according to different bus protocols, so as to realize that CAN bus and USB bus can share the same interface.
This allows CAN bus and USB bus to share the same interface, saving the number of interfaces, reducing the control board area, and improving the convenience and efficiency of connection.
Smart Images

Figure CN115793506B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of single-chip microcomputer control, and in particular to a self-identification control method based on CAN bus and USB bus of single-chip microcomputer. BACKGROUND
[0002] CAN is the abbreviation of Controller Area Network (hereinafter referred to as CAN), which is an ISO international standardized serial communication protocol. In the automobile industry, various electronic control systems have been developed for the requirements of safety, comfort, convenience, low pollution, and low cost. Since the data types and reliability requirements for communication between these systems are different, many buses are used, and the number of wire harnesses increases. In order to meet the needs of "reducing the number of wire harnesses" and "high-speed communication of large amounts of data through multiple LANs", the CAN communication protocol for automobiles was developed by Bosch, a German electrical company, in 1986. Since then, CAN has been standardized through ISO 11898 and ISO 11519, and has become a standard protocol for automobile networks in Europe.
[0003] Currently, the connection of CAN bus and host computer is very inconvenient, and traditional interface technologies such as RS232, RS485 and ISA are commonly used. There has been a lack of interface technology for high-speed and convenient connection with the host computer.
[0004] USB bus is a general serial bus technology, which has the advantages of fast transmission speed, flexibility (four transmission types: control, block, interrupt, and isochronous transmission, and three transmission speeds, which can be applied to various peripherals), easy to use (automatic configuration, plug and play, hot plugging), bidirectional, synchronous transmission, etc. It allows peripherals to be hot-plugged in the on state, and up to 127 peripherals can be connected in series, with a transmission rate of up to 480Mb / S. It can provide 5-volt power supply to low-voltage devices, while reducing the number of PC I / O interfaces. With the development of PCs, USB bus has become the main interface standard of PCs, and will gradually replace other traditional interfaces.
[0005] The existing USB-to-CAN bus design is complex, inefficient, and the communication scheme is not reasonable. SUMMARY
[0006] The present application relates to the field of single-chip microcomputer control, and in particular to a self-identification control method based on CAN bus and USB bus of single-chip microcomputer.
[0007] In order to achieve the above-mentioned purpose, the present application adopts the following technical solutions:
[0008] The application discloses a self-identification control method based on a single-chip microcomputer CAN bus and USB bus, which comprises a single-chip microcomputer module, a CAN chip and a USB interface, wherein the single-chip microcomputer module comprises a single-chip microcomputer; the CAN chip and the USB interface are connected with the single-chip microcomputer, and the CAN chip is connected with the USB interface; the self-identification control method comprises the following steps:
[0009] S1, the thirty-second pin, the thirty-third pin, the forty-fifth pin and the forty-sixth pin of the single-chip microcomputer are set as inputs, the forty-third pin is set as an output, and a high level is output; after the equipment is powered on, whether the master device adopts a USB bus or a CAN bus is judged by detecting the levels of the thirty-second pin and the thirty-third pin;
[0010] S11, if the levels of the thirty-second pin and the thirty-third pin of the single-chip microcomputer are high and low respectively, it is known from a USB protocol that the master device adopts a USB bus protocol;
[0011] S12, if the levels of the thirty-second pin and the thirty-third pin of the single-chip microcomputer are both high, it is known from a CAN manual that the master device adopts a CAN bus protocol.
[0012] Preferably, the single-chip microcomputer module further comprises a second capacitor, a third capacitor, a fourth capacitor, a crystal oscillator, a second resistor, a switch and a power supply; the crystal oscillator is connected in parallel between the fifth pin and the sixth pin of the single-chip microcomputer; the fifth pin of the single-chip microcomputer is connected with the second capacitor and grounded, and the sixth pin of the single-chip microcomputer is connected with the third capacitor and grounded; the seventh pin of the single-chip microcomputer is connected with one end of the second resistor, one end of the switch and one end of the fourth capacitor respectively; the other end of the second resistor is connected with the power supply; the other end of the switch is connected with the other end of the fourth capacitor and grounded.
[0013] Preferably, the CAN chip comprises eight pins; the first pin of the CAN chip is connected with the forty-sixth pin of the single-chip microcomputer; the second pin of the CAN chip is grounded; the third pin of the CAN chip is connected with a power supply and one end of a first capacitor, and the other end of the first capacitor is grounded; the fourth pin of the CAN chip is connected with the forty-fifth pin of the single-chip microcomputer; the eighth pin of the CAN chip is connected with the forty-third pin of the single-chip microcomputer.
[0014] Preferably, the USB interface includes six pins; a first pin of the USB interface is connected with one end of a safety tube, the other end of the safety tube is connected with the power supply; a second pin of the USB interface is connected with a sixth pin of the CAN chip and a thirty-second pin of the single-chip microcomputer respectively; a third pin of the USB interface is connected with a seventh pin of the CAN chip and a thirty-third pin of the single-chip microcomputer respectively; a fifth pin of the USB interface is grounded, and a sixth pin of the USB interface is connected with the earth.
[0015] Preferably, the single-chip microcomputer can adopt an STM32 series single-chip microcomputer.
[0016] Preferably, the CAN chip can adopt an SN65HVD230DR type chip.
[0017] Compared with the prior art, the present application has the following beneficial effects:
[0018] The present application designs a self-identification control method based on a CAN bus and a USB bus of a single-chip microcomputer, and realizes that the CAN bus and the USB bus can share the same interface, which is beneficial to save the interface and reduce the area of the control board. BRIEF DESCRIPTION OF DRAWINGS
[0019] Fig. 1 The present application provides a method flow diagram;
[0020] Fig. 2 The present application provides a circuit diagram of a single-chip microcomputer module;
[0021] Fig. 3 The present application provides a connection circuit diagram of a CAN chip and a USB interface;
[0022] Fig. 4 The present application provides a schematic diagram of a USB signal transmission waveform.
[0023] LEGEND:
[0024] U1, CAN chip, U2, single-chip microcomputer,
[0025] CN1, USB interface, C1, first capacitor,
[0026] C2, second capacitor, C3, third capacitor,
[0027] C4, fourth capacitor, R1, first resistor,
[0028] R2, second resistor, Y1, crystal oscillator,
[0029] S1, switch, F1, safety tube,
[0030] FG, earth. DETAILED DESCRIPTION
[0031] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative effort belong to the scope of protection of the present application.
[0032] In the description of the present application, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer" and the like indicate the orientation or positional relationship shown in the drawings, and are only for the purpose of facilitating the description of the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as a limitation on the present application; the terms "first", "second", "third" are only for the purpose of description, and cannot be understood as indicating or implying relative importance; in addition, unless otherwise explicitly specified and limited, the terms "mounting", "connecting", "connecting" should be understood in a broad sense, for example, it can be fixedly connected, or it can be detachably connected, or integrally connected; it can be mechanically connected, or it can be electrically connected; it can be directly connected, or it can be indirectly connected through an intermediate medium; it can be the communication inside two elements. For a person of ordinary skill in the art, the specific meaning of the above terms in the present application can be understood according to the specific circumstances.
[0033] Reference Figs. 1 to 4 A self-identification control method based on a single-chip microcomputer CAN bus and USB bus, comprising a single-chip microcomputer module, a CAN chip U1 and a USB interface CN1, the single-chip microcomputer module comprising a single-chip microcomputer U2; the CAN chip U1 and the USB interface CN1 are connected with the single-chip microcomputer, and the CAN chip U1 is connected with the USB interface CN1; the self-identification control method comprises:
[0034] S1, setting the thirty-second pin (PA12_USBDP), the thirty-third pin (PA12_USBDP), the forty-fifth pin (PB8_CANRX) and the forty-sixth pin (PB9_CANRX) of the single-chip microcomputer U2 as input, setting the forty-third pin (PB7_CANRS) as output, and outputting high level;
[0035] S2, inserting a host device;
[0036] S3, detecting the level of the thirty-second pin (PA11_USBDP) and the thirty-third pin (PA12_USBDP);
[0037] S31, if the levels of the thirty-second pin (PA11_USBDP) and the thirty-third pin (PA12_USBDP) of the single-chip microcomputer U2 are high and low respectively; according to the USB protocol, the master device adopts the USB bus protocol;
[0038] S32, if the levels of the thirty-second pin (PA11_USBDP) and the thirty-third pin (PA12_USBDP) of the single-chip microcomputer U2 are high; according to the CAN manual, the master device adopts the CAN bus protocol.
[0039] The master device adopts the USB bus protocol: the single-chip microcomputer U2 initializes the port as the USB function, at this time, the thirty-second pin (PA11_USBDP) and the thirty-third pin (PA12_USBDP) are the read and write signal lines of the USB bus protocol of the single-chip microcomputer U2; the forty-third pin (PB7_CANRS) is output, and outputs a high level, so that the CAN chip U1 is in a low-power mode and does not interfere with the signal line.
[0040] The maximum value of the standard I / O low level voltage of the STM32 series single-chip microcomputer U2 is:
[0041] 0.28*(VDD-2 V)+0.8 V = 0.28*(3.3V-2 V) + 0.8 V = 1.164V;
[0042] The minimum value of the standard I / O high level voltage of the STM32 series single-chip microcomputer U2 is:
[0043] 0.41*(VDD-2 V)+1.3 V = 0.41*(3.3V-2 V) + 1.3 V = 1.833V;
[0044] Therefore, the IO port of the STM32 series single-chip microcomputer U2 is less than 1.164V for low level, and greater than 1.833V for high level.
[0045] From the maximum waveform of the USB signal sent, the maximum high level is 4.6V, and the minimum low level is -1V; therefore, when the levels of the two signal lines are high and low respectively, the master device adopts the USB bus protocol.
[0046] The master device adopts the CAN bus protocol: the single-chip microcomputer U2 initializes the port as the CAN function, the forty-third pin (PB7_CANRS) of the single-chip microcomputer U2 outputs a low level, and the CAN chip U1 is in a high-speed mode; the CAN bus protocol is adopted between the slave device and the master device.
[0047] The single-chip microcomputer module further includes a second capacitor C2, a third capacitor C3, a fourth capacitor C4, a crystal oscillator Y1, a second resistor R2, a switch S1 and a power supply; the crystal oscillator Y1 is connected in parallel between the fifth pin and the sixth pin of the single-chip microcomputer U2; the fifth pin of the single-chip microcomputer U2 is connected to the second capacitor C2 and grounded, and the sixth pin of the single-chip microcomputer U2 is connected to the third capacitor C3 and grounded; the seventh pin of the single-chip microcomputer U2 is connected to one end of the second resistor R2, one end of the switch S1 and one end of the fourth capacitor C4, respectively; the other end of the second resistor R2 is connected to the power supply; the other end of the switch S1 is connected to the other end of the fourth capacitor C4 and grounded.
[0048] The CAN chip U1 includes eight pins; the first pin of the CAN chip U1 is connected to the forty-sixth pin (PB9_CANRX) of the single-chip microcomputer U2; the second pin of the CAN chip U1 is grounded; the third pin of the CAN chip U1 is connected to the power supply and one end of the first capacitor C1, and the other end of the first capacitor C1 is grounded; the fourth pin of the CAN chip U1 is connected to the forty-fifth pin (PB8_CANRX) of the single-chip microcomputer U2; the eighth pin of the CAN chip U1 is connected to the forty-third pin (PB7_CANRS) of the single-chip microcomputer U2.
[0049] The first pin (D) of the CAN chip U1 functions as CAN sending data input (low level in dominant bus state and high level in recessive bus state), also known as TXD, driver input; the second pin (GND) of the CAN chip U1 functions as ground connection; the third pin of the CAN chip U1 functions as a 3.3V power supply voltage of the transceiver; the fourth pin of the CAN chip U1 functions as CAN receiving data output (low level in dominant bus state and high level in recessive bus state), also known as RXD, driver output; the fifth pin of the CAN chip U1 is a VCC / 2 reference output pin; the sixth pin of the CAN chip U1 is a low-level CAN bus; the seventh pin of the CAN chip U1 is a high-level CAN bus; and the eighth pin of the CAN chip U1 is a mode selection pin: strong pull-down to GND for high-speed mode; strong pull-up to VCC for low-power mode; and pull-down to GND through a 10kΩ to 100kΩ resistor for slope control mode.
[0050] The USB interface CN1 includes six pins; the first pin of the USB interface CN1 is connected to one end of a fuse F1, and the other end of the fuse F1 is connected to the power supply; the second pin of the USB interface CN1 is connected to the sixth pin of the CAN chip U1 and the thirty-second pin (PA11_USBDP) of the single-chip microcomputer U2, respectively; the third pin of the USB interface CN1 is connected to the seventh pin of the CAN chip U1 and the thirty-third pin (PA12_USBDP) of the single-chip microcomputer U2, respectively; the fifth pin of the USB interface CN1 is grounded, and the sixth pin of the USB interface CN1 is connected to the ground.
[0051] The single-chip microcomputer U2 can adopt an STM32 series single-chip microcomputer, for example, an STM32F103RC8T6 single-chip microcomputer; and the CAN chip U1 can adopt an SN65HVD230DR type chip.
[0052] The CAN bus and the USB bus are each provided with a power line, a ground line, a first differential signal line and a second differential signal line.
[0053] The above is only a preferred specific embodiment of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can make equivalent replacement or change according to the technical scheme and the inventive concept of the present application within the technical range disclosed by the present application, which should be covered in the protection scope of the present application.
Claims
1. A self-identification control method based on a microcontroller's CAN bus and USB bus, characterized in that, The system includes a microcontroller module, a CAN bus, and a USB bus. The microcontroller module includes a microcontroller. Both the CAN bus and the USB bus are connected to the microcontroller, and the CAN bus is connected to the USB bus. The second pin of the USB interface is connected to the sixth pin of the CAN chip and the thirty-second pin of the microcontroller, respectively. The third pin of the USB interface is connected to the seventh pin of the CAN chip and the thirty-third pin of the microcontroller, respectively. The self-identification control method includes the following steps: S1 sets pins 32, 33, 45, and 46 of the microcontroller as inputs, and pin 43 as an output, outputting a high level. S2, Insert the master device; S3 detects the voltage levels of pins 32 and 33; S31. If the voltage levels of pins 32 and 33 of the microcontroller are detected to be one high and one low, according to the USB protocol, the microcontroller U2 initializes the port to USB function. At this time, pins 32 and 33 are the read and write signal lines of the USB bus protocol of the microcontroller U2. Pin 43 is the output, outputting a high level, so that the CAN chip U1 is in low power mode and the master device uses the USB bus protocol. S32, if the levels of pins 32 and 33 of the microcontroller are both high, according to the CAN manual, the microcontroller U2 initializes the port to CAN function, the pin 43 of the microcontroller U2 outputs a low level, the CAN chip U1 is in high-speed mode, and the master device uses the CAN bus protocol.
2. The self-identification control method based on a microcontroller-based CAN bus and USB bus according to claim 1, characterized in that, The microcontroller module further includes a second capacitor, a third capacitor, a fourth capacitor, a crystal oscillator, a second resistor, a switch, and a power supply; the crystal oscillator is connected in parallel between the fifth and sixth pins of the microcontroller; the fifth pin of the microcontroller is connected to the second capacitor and grounded, and the sixth pin of the microcontroller is connected to the third capacitor and grounded; the seventh pin of the microcontroller is connected to one end of the second resistor, one end of the switch, and one end of the fourth capacitor; the other end of the second resistor is connected to the power supply; and the other end of the switch is connected to the other end of the fourth capacitor and grounded.
3. The self-identification control method based on a microcontroller-based CAN bus and USB bus according to claim 1, characterized in that, The CAN chip includes eight pins; the first pin of the CAN chip is connected to the forty-sixth pin of the microcontroller; the second pin of the CAN chip is grounded; the third pin of the CAN chip is connected to the power supply and to one end of a first capacitor, the other end of which is grounded; the fourth pin of the CAN chip is connected to the forty-fifth pin of the microcontroller; and the eighth pin of the CAN chip is connected to the forty-third pin of the microcontroller.
4. The self-identification control method based on a microcontroller-based CAN bus and USB bus according to claim 2, characterized in that, The USB interface includes six pins; the first pin of the USB interface is connected to one end of a fuse, and the other end of the fuse is connected to the power supply; the fifth pin of the USB interface is grounded, and the sixth pin of the USB interface is connected to earth.
5. The self-identification control method based on a microcontroller-based CAN bus and USB bus according to claim 1, characterized in that, The microcontroller can be an STM32 series microcontroller.
6. The self-identification control method based on a microcontroller-based CAN bus and USB bus according to claim 1, characterized in that, The CAN chip can be the SN65HVD230DR model chip.
Citation Information
Patent Citations
USB and CAN multiplex circuit based on STM32F103
CN205563547U