Multi-machine communication solution based on AVR microcontroller

In the multi-machine communication process, the RS232 interface of all devices is on the communication line, and only one device is the host, the other is the slave, and the communication is initiated by the host. The data frame generally uses a 1-bit start bit and a 9-bit data bit, of which the 9th bit (RXB8) is used to characterize whether the frame is an address frame or a data frame. When the frame type representation bit is "1", it indicates that the frame data is an address frame; when the frame type representation bit is "0", it indicates that the frame is a data frame.

In the AVR, the USART receiver can be enabled to filter the received data frames by setting the flag bit MPCM in the UCSRA register of the slave. If the filtering function is enabled, the slave receiver filters the received data frames that are not address information frames and does not put them in the receive buffer. This facilitates the slave MCU in multi-machine communication. Processing the data frame program (compared to the standard 51 structure). The transmitter is not affected by the MPCM bit setting.

Multi-machine communication solution based on AVR microcontroller

The multi-machine communication mode allows multiple slaves to receive data from one host on the communication line. Determining which slave is addressed by the host by decoding the address in the received address frame. If a slave is addressed by the master, it will receive the data frame sent by the next master, while the other slaves will ignore the data frame until an address frame is received again. (The slave address is determined by each slave's own software).

For a host MCU in a multi-machine communication system, a 9-bit data frame structure (UCSZ=7) can be set. When the address frame is transmitted, the 9th bit is set to "1"; when the data frame is transmitted, the 9th bit is set to "0". In this case, the slave must also be set to receive a 9-bit data frame structure.

The data exchange process of multi-machine communication mode is as follows:

1) Set all slaves to work in multi-machine communication mode (MPCM=1).

2) The communication starts by the host sending an address frame first, such as 8-bit data is 0X01 (No. 1 slave address), 9th bit = "1", call No. 1 slave.

3) All slaves receive and read the address frame sent by the host. In all slave MCUs, the RXC flag is set to indicate that an address frame has been received.

4) Each slave MCU reads the UDR register and determines if it is addressed by the host. If addressed, clear the MPCM bit in the UCSAR register and wait to receive data; otherwise, keep MPCM "1" and wait for the next address frame to be received (this step should be handled by user software):

A) As the No. 1 slave MCU processing process: after receiving the address frame, it is determined that the UDR data 0X01 is read as its own address, the MPCM position is “0”, and all the data frames sent by the host are received until the next one. The address frame is up.

B) Processing of other slave MCUs: After receiving the address frame, it is determined that the read UDR data 0X01 is not its own address, and the MPCM bit is set to "1", so they will ignore the data frame sent by the host until the host sends it again. Address frame.

5) After the addressed slave MCU receives the last data frame, the MPCM bit is set, waiting for the next address frame to appear (this step should also be implemented by the user software), and then repeat from step 2.

Stainless Steel Sanitary Pipe

Stainless Steel Sanitary Pipe,Sanitary Pipe Material Stainless Steel Tube,Astm 409 Saintary Stainless Steel Pipe,Ss Seamless Saintary Pipe

ShenZhen Haofa Metal Precision Parts Technology Co., Ltd. , https://www.haofametal.com