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.
Previous article:Use VB programming language to realize the communication between PC and AVR microcontroller
Next article:Keyboard subroutine (AVR)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- [Raspberry Pi Pico Review] On-chip temperature detection
- STM32F407 simple vision board (recognition of QR codes, data matrix codes, apriltags, round and square shape detection)
- 【ST NUCLEO-G071RB Review】PWR
- There are many tricks for salary cuts and layoffs. What should you do if you encounter such a situation?
- 280049Solution to the problem of LaunchPad emulator not being able to connect
- Tips for Powering FPGAs
- [TI recommended course] #[High Precision Laboratory] Interface: 1 RS-485#
- What is the use of connecting Schottky diodes in parallel at both ends of the MOS tube used as a switch at the power input?
- Friends in Xi'an, please get out of this pit as soon as possible.
- Xianyu low-cost wireless digital microphone disassembly (Jerry solution)