Communication methods with MCU

House of Elevators Australia - Elevator parts, Lift parts & accessories,

Communication methods with MCU

Firstly, the concepts of serial communication and parallel communication as well as serial communication and parallel communication are understood.

  1. Serial traffic: it is a concept, it is the exponential transmission from one to one, its characteristic is the communication line is simple, as long as a pair of transmission lines can realize two-way communication, suitable for long-distance communication, but the transmission speed is slow.
  2. It includes common serial communication I2C,SPI,UART…
  3. Serial communication: Is a practical way of communication, but we can almost see it the same way.
  4. Serial interface: serial port, or serial communication interface, or serial communication interface (usually com interface).
  5. Parallel communication: When bits of a set of data are transmitted simultaneously on multiple lines, it is called parallel communication.
  6. Parallel interface: it is a kind of interface, each data bit is transmitted at the same time, the transmission speed is fast, the efficiency is high, one side can be used for MCU.

Serial communication can be divided into simplex, half duplex and full duplex

  • Simplex: Messages can only be sent in one direction.
  • Half duplex: Messages can be sent in both directions but not simultaneously.
  • Full duplex: Information can be sent in both directions simultaneously.

Serial communication can also be divided into synchronous communication and asynchronous communication

  1. Synchronous communication: (two wires) : The formation of a group of many characters so that they may be transmitted one after another, but the synchronization character is added at the beginning of each group of messages (often called information frames) and the blanks are filled when there is no information to be transmitted, because a gap is not allowed in the synchronous transmission.

In the synchronous mode, the sender not only sends data, but also transmits synchronous clock signal. Both parties of information transmission use the same clock signal to determine the position of each bit in the transmission process

  1. Asynchronous communication (one signal line, no clock line) is a very common mode of communication.

When sending characters by asynchronous communication, the time interval between the characters sent can be arbitrary. Of course, the receiver must always be ready to receive.

The sender can start sending characters at any time, so it is necessary to mark the beginning and end of each character with a start and a stop bit so that the receiver can receive each character correctly.

The advantage of asynchronous communication is that the communication equipment is simple and inexpensive, but the transmission efficiency is low (because the start and stop bits account for a large proportion of the overhead).

The difference between synchronous communication and asynchronous communication:

  1. Synchronous communication requires that the clock frequency of the receiving end is consistent with that of the sending end, and the sending end sends continuous bitstreams;

Asynchronous communication does not require that the clock on the receiving end and the clock on the sending end synchronize. After the sending end sends a byte, it can send the next byte after any long time interval.

  1. High synchronous communication efficiency;

Asynchronous communication is inefficient.

  1. The synchronous communication is complex, and the allowable error of the clocks on both sides is small;

Asynchronous communication is simple, both clocks can allow a certain error.

  1. Synchronous communication can be used for point-to-multi-point;

Asynchronous communication works only point-to-point.

SPI, UART, I2C in MCU

MCU has properties that are stronger than the CPU, including the PERFORMANCE of the CPU, and features that the CPU does not have.

  • SPI

SPI allows high-speed synchronous data transmission between MCU and peripheral devices or between MCU. SPI can have the choice of host and slave modes. The master and slave of communication can exchange data simultaneously through shift registers.

At present, I use the host mode in the majority.

SPI requires four lines: SS,MISO,MOSI,SCK.

Communication process: After setting the WORKING mode of SPI, it includes SCK frequency (data transmission rate), working speed, master-slave mode, and clock polarity corresponding to data receiving and sending.

In the main mode, the SS is pulled down to indicate the beginning of communication, and then a communication is started by automatically starting the clock SCK after writing a byte of data to the SPI data register. After the communication is completed, the corresponding interrupt flag is generated to indicate that the transmission of a byte of data is completed.

After the communication is completed, pull the SS foot up to indicate that the communication process has ended.

Note the setting of SS pin: When set to slave mode, SS pin should be set as input. SPI can only work when pulling down, and it is negative SPI mode when pulling up.

In host mode, SS pins can be set and should generally be set to output. If set to input, it should be kept high, otherwise normal host mode operation will not be possible.

  • USART

The operation of USART is relatively simple, mainly including setting baud rate, data format, and interrupt allowed bit, etc. It is worth noting that its USART IN SPI MODE is similar to SPI operation, mainly including setting Clock and sending data through THE interrupt of USART

  • I2C

I2C interface is a simple and powerful communication interface. Only two bidirectional buses (clock and data line), SCL and SDA are needed to realize the communication between a host and up to 128 slaves.

The process of simulating I2C interface: start I2C and generally send SDA low startup data when SCL is high. SDA can only be effective when SCL is low. SDA is only used to stop starting I2C communication when SCL is high.

The I2C bus is an internal bus used to connect the chips within the internal system.

Serial communication is used to communicate with devices outside the system.

Such as device to device communication.

SPI,UAR and I2C are all serial communication modes, while parallel communication mode is generally used less, because it is only suitable for short distance, and generally used more for MCU, because MCU has requirements on data transmission speed, and the chips connected with it are generally close to each other.Communication methods with MCU

Share this post