How to realize the multi-machine communication technology between the MCUs

In addition to the combination of SM2 and RB8 to achieve multi-machine communication, the multi-machine communication of MCU often uses the method of data address in the data frame to distinguish different slaves to realize multi-machine communication between MCUs. The data frame sent by the host contains the address information. After the host sends it, all the slaves can receive it. Each slave compares its own address with the address contained in the received data frame. If it is the same as its own address, Then the corresponding processing is performed. Otherwise the frame data is discarded and the serial port continues to wait for data to be received. Of course, according to the actual function requirements, some slaves can also decide whether to receive data frames according to the address information of the data frame, and realize the function of the host "broadcasting" to some slaves.

Since the communication method uses the address byte information in the data frame to distinguish the slaves, it is only related to the software, and the hardware interface is exactly the same as the multi-machine communication method.

The host and the slave send data at a time as a data frame composed of multiple data, and the data frame includes a start and end flag, an address, a response message, and the like, and after receiving the data frame by the master or the slave, according to the flag in the data frame And the address determines whether to save. After receiving the saved data, the function byte of the data frame is used to describe the meaning of the data byte or the next operation.

In the multi-machine communication method of the one-chip computer, the status of the master and the slave are clearly distinguished, and the tasks of the master slave are different. However, the method described in this section, the boundary of the master slave is not very obvious, as long as the data frame is marked and When the address byte is changed, the data frame can be sent to the host or slave of the specified address, and the slave receiving the data can decide whether to save the frame data as needed.

According to the principle of multi-machine communication introduced in this section, the bytes of the data frame in Figure 10-12 are defined as follows.

• The data frame is based on octets and is in hexadecimal.

· Start byte: 0XAA.

• Master-slave flag: 0X0F indicates that this is the data frame sent by the host; 0XF0 indicates that this is the data frame sent by the slave. In fact, the address can be used to distinguish whether the data frame is sent by the slave or the host.

· Function: The function of the data byte. If there is no data byte, the function byte is 0x00, which uses the compressed BCD data format.

• Checksum: The checksum of this data frame, including the start and end bytes, excluding the check byte itself.

· The verification algorithm used: adding one frame of data not including the checksum, discarding the carry, and using the calculated value as the check byte.

Frame length: The length of the data byte.

Address: If the host is sent to the slave, this byte is the slave address to receive data. If it is sent from the slave to the host, this byte is the address of the slave that sent the data, usually in hexadecimal.

End byte: 0XDD.

For example, if the host sends data 0x12, 0x34 to the slave whose address is Oxl0 and the function byte is 0x55, the data of one frame sent is as shown in the following figure.

The following is a slave microcontroller program that uses this data frame format. Both the transmit and receive modes are interrupted. The crystal frequency of the single-chip microcomputer is 11.059 2MHz, the baud rate of communication is 9 600bit/s, and the serial port of the master and slave adopts mode 1.

In the program sending part, first prepare the data frame header according to the communication protocol, then add the data to be sent, calculate the checksum, and finally send the entire data frame, as shown in the following figure.

How to realize the multi-machine communication technology between the MCUs

The serial port receiving part of the program is more complicated, and the flow chart is shown in the figure below.

How to realize the multi-machine communication technology between the MCUs

DC Immune Single Iron Core

Anyang Kayo amorphous Technology Co., Ltd., founded in 2011 with a registered capital of RMB 5 million that is a technology-based manufacture. We specialize in the production of nano&amorphous iron core and amorphous&Nano Ribbon, CT, electric component(including comon mode choke coil, Filter Inductance, high frequency transformer,etc.).Our main products are amorphous and nanocrystalline iron cores which are widely used in communication, house appliances, electric power, automobile, new energy and other fields.

Our DC immune single Cores have high permeability,low coercivity and loss,excellent performance on DC immue and temperature stability that can be widely used to the leakage protection switch.



Dc Immune Single Iron Core,Magnetic Core You Want,Excellent Magnetic Iron Core,Resisting Dc Iron Core

Anyang Kayo Amorphous Technology Co.,Ltd. , https://www.kayoamotech.com