STM32-a rough talk about communication interface equipment

In STM32, there are 5 communication interfaces, which are: SPI interface and I2C interface for communication between ICs, CAN bus interface for controlling LAN communication, USB interface for communication with PC, and the most common universal synchronization /Asynchronous serial port USART. Let's introduce in detail the functions of these 5 communication interfaces in STM32.

1. SPI interface for communication between ICs

In STM32, in order to be able to communicate with other ICs, it is equipped with 2 SPI interfaces and provides full-duplex SPI communication up to 18 MHz. Among the two SPI interfaces, one of the SPI device interfaces is located on the APB2 high-speed bus with a full speed of 72 MHz, and the other SPI device interface is located on the APB1 low-speed bus with a full speed of 36 MHz. The user can customize the clock polarity and phase of each SPI device. The length of the data sent can be 8 or 16 bits. You can also choose to send from the highest or lowest bit. Each SPI can act as a master or slave. The computer communicates with other SPI devices.
Insert picture description here
In STM32, in order to better utilize the characteristics of SPI (maximum 18MHz), each SPI device can apply for two DMA transmission channels. In these two transmission channels, data is transmitted and sent separately. With the support of DMA, the SPI interface can easily realize high-speed data bidirectional transmission of pure hardware operation. In addition, the STM32 SPI also contains two hardware CRC (cyclic redundancy check unit) units, one is used for the CRC check during the data transmission process, and the other is used for the CRC check during the data reception process . Each CRC unit can perform CRC8 and CRC16 checks. The CRC check function will play a significant role when STM32 and MMC/SD card communicate with SPI.

2. Two-wire serial bus interface (I2C)

In STM32, in addition to using the SPI interface mentioned above, you can also use the bus interface on I2C to communicate with other ICs, acting as a master or slave on the bus. The I2C interface supports the multi-master arbitration mechanism on the I2C bus, supports the I2C standard 100KHz, also supports high-speed 400KHz, and also supports 7-bit or 10-bit address mode. Using the I2C interface, the data access function can be easily implemented on the I2C bus. If the user wants to realize the communication between I2C and different devices, it is necessary to start the I2C interface through software.

In the I2C interface device, it provides two interrupt sources, whose functions are: transmission error interruption and phase interruption during data transmission. In addition, there are 2 DMA channels connected to the data buffer of the I2C device. When we enable the DMA support of the I2C interface, once the address data on the I2C bus is transferred, the hardware will take over the process of data entering and leaving the STM32.

3. Universal Synchronous/Asynchronous Serial Interface (USART)

Inside the STM32, it is equipped with 3 enhanced USART interfaces, all of which support the latest communication protocols. The maximum communication rate of each USART is 4.5 Mbps. STM32's USART is a fully customizable serial communication port whose data length, stop bit and baud rate can all be set. Among the three USARTs, one is mounted on the APB2 bus, and the other two are mounted on the APB1 bus. The figure below shows the USART of STM32.

Each USART's baud rate generator can generate a baud rate that is accurate to a decimal level, and the accuracy is much higher than that of a simple clock divider. Like other communication interface devices, each USART is equipped with two DMA channels to take over the data in and out between the USART data register and the memory. STM32's USART supports several special communication modes, and it is also possible to use Tx (data output) single wire to realize half-duplex communication. Each USART has additional CTS (modem) and RTS (modem) control channels, which can realize modulation communication and hardware flow control. The half-duplex communication connection mode of USART shown in the figure below.
Insert picture description here

Each USART can also be used as a LIN bus (inline bus) controller. LIN is an automotive standard protocol bus, which is generally used to lay out low-cost controller networks. USART also supports synchronous communication, so that it can better utilize its high communication rate. It can be connected to a 3-wire SPI bus, as shown in the figure below. In this mode, USART acts as the SPI master, and its clock polarity and phase can also be set, so it can communicate with any SPI slave.

4. CAN interface and USB interface

CAN bus interface and full-speed USB interface. CAN and USB interfaces have something in common, and both require a large amount of SRAM space to support the information filtering mechanism. STM32 specifically divides 512 bytes of SRAM space for CAN and USB devices. This 512-byte space can only be used by these two interfaces. For CAN or USB, the 512-byte space is regarded as unique, which means that the two interfaces cannot use this one SRAM byte space at the same time. But in the same application, the two devices of CAN and USB are used alternately, accessing the shared SRAM space respectively.
The CAN interface and the USB interface are not elaborated here. If you want to view the detailed introduction, you can click the link to jump to the CAN interface
USB interface

Guess you like

Origin blog.csdn.net/qq_39530692/article/details/107807646