Solution to the AVR serial port multi-machine communication process

Publisher:TranquilSoulLatest update time:2013-12-09 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Netizen NE5532 asked:
The serial port of AVR says that it has a multi-machine communication function, which means that the address of the slave is sent in the first frame, and then the data is sent. So, where is the address of the slave written? Does the slave itself contain the address (hardware) or is it assigned to the slave in the software? It seems that it is not written in the DATASHEET.
--------------------------------------------------------------------------------
Teacher Ma Chao's answer:
According to your question, you are not clear about the process of serial multi-machine communication. You should first have a deep understanding and master the process of multi-machine communication.
In the process of multi-machine communication, the RS232 interfaces of all devices are connected to the communication line, and only one device can be the host, and the others are slaves. The communication is initiated by the host. The data frame generally uses 1 start bit and 9 data bits, among which the 9th bit (RXB8) is used to indicate whether the frame is an address frame or a data frame. When the frame type indication bit is "1", it means that the frame data is an address frame; when the frame type indication bit is "0", it means that this frame is a data frame.

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

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

For the host MCU in a multi-machine communication system, you can set it to use a 9-bit data frame structure (UCSZ=7). When sending an address frame, set the 9th bit to "1"; when sending a data frame, set the 9th bit 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 is as follows:

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

2) Communication starts with the host sending an address frame. For example, if the 8-bit data is 0X01 (slave address No. 1), the 9th bit = "1", calling slave No. 1.

3) All slaves receive and read the address frame sent by the master. In the MCUs of all slaves, the RXC flag is set, indicating that the address frame has been received.

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

A) The processing process of the MCU as slave No. 1 is as follows: after receiving the address frame, it determines that the read UDR data 0X01 is its own address, sets the MPCM position to "0", and receives all subsequent data frames sent by the host until the next address frame.

B) The processing process of other slave MCUs: After receiving the address frame, they determine that the read UDR data 0X01 is not their own address, and set the MPCM position to "1". In this way, they will ignore the data frames subsequently sent by the host until the host sends the address frame again.

5) After the addressed slave MCU receives the last data frame, it sets the MPCM bit and waits for the next address frame to appear (this step should also be processed and implemented by the user software), and then repeats from step 2.

Reference address:Solution to the AVR serial port multi-machine communication process

Previous article:Use VB programming language to realize the communication between PC and AVR microcontroller
Next article:Keyboard subroutine (AVR) 

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号