Freescale MC9S12X CAN driver

     Today, I will take you to learn the development of MC9S12XS CAN driver module. First of all, understand what CAN is and its purpose.          

The concept of CAN bus:

       CAN is the abbreviation of Controller Area Network (Controller Area Network), which was developed by BOSCH, a German company known for developing and producing automotive electronic products, and eventually became an international standard (ISO11898).

       CAN (Controller Area Network) is an ISO international standardized serial communication protocol. Widely used in automobiles, ships, etc. Has the high performance and reliability that has been recognized by everyone.

  The CAN controller determines the level of the bus by the potential difference between the two wires (CAN-H and CAN-L) that make up the bus. At any time, there are two levels on the bus: dominant level and recessive level.

       "Dominant" means "priority", as long as one unit outputs a dominant level, the bus is a dominant level, and "recessive" means "inclusive", only all units output the implicit level It is a recessive level on the bus. (Dominant levels are stronger than recessive levels). When the logical line "AND" is performed on the bus, the logic value of the dominant level is "0", and the recessive level is "1".

Purpose of CAN bus:

In the current automobile industry, various electronic control systems have been developed for        the requirements of safety, comfort, convenience, low pollution and low cost . Due to the different data types and reliability requirements for communication between these systems, there are many , and the number of wiring harnesses increases accordingly. In order to meet the needs , in 1986, the German electric company Bosch developed the CAN communication protocol for automobiles. Since then, CAN has and is now the standard protocol for automotive networks in Europe. Now, CAN's high performance and reliability have been recognized and widely used in industrial automation, ships, medical equipment, industrial equipment and so on.

        When each electronic control device on the vehicle does not have CAN function (if it is an electronic control device without CAN communication capability, data communication between it and other electronic control devices cannot be performed, which results in poor electronic control capability of each electronic control device. , single function, poor scalability), when direct communication is not possible, the "CAN module" product can be used to realize the vehicle electronic control network system with CAN function, and each electronic control device can transmit the required power to each other. The control signal makes the electric control system of the vehicle more powerful.

Next, we officially start to learn the development of the MC9S12 CAN driver module.



The overall framework of the MSCAN module is as follows:



Let's take a look at the code together, CAN driver


The CAN initialization function mainly includes: setting the CAN baud rate, setting the CAN receive interrupt enable, CAN filter and so on.


The CAN receiving function mainly includes: after the receiving register flag bit is set, read the corresponding register. Such as CAN identifier CAN data CAN length, save to the specified variable. .

that

The CAN sending function mainly includes setting the CAN identifier, setting the CAN data, setting the CAN length, etc. Before that, there are some logical judgments, such as judging the length, judging whether the register is empty, etc.

To get the CAN driver source code, please pay attention to the WeChat public account "Embedded Software Development Learning Circle". . . . .







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324843885&siteId=291194637