If you are just starting to learn microcontrollers, will you be happy because you can use a program to light up an LED? Will you be happy because you can use a program to light up a digital tube? This is a good thing, and it is also the motivation to continue learning.
But when it comes to data-related experiments, it feels difficult to make progress. Sometimes, after writing the driver and downloading it to the microcontroller, there is no response at all, but I don't know where the problem lies. Data communication is not like LED, where you can use a multimeter to test whether there is power.
This is a hurdle for learning microcontrollers and STM32. In other words, this is a river, a river blocking your way. What will you do if there is a river? There were many methods in the past, but I think the faster way is to use the original tools to get through it. After passing by, you will find that there is a different world on the other side of the river.
So what is this original tool? That is "serial communication".
Introduction to serial communication
Serial communication refers to a communication method that transmits data bit by bit between peripherals and computers through data signal lines, ground lines, control lines, etc. This is too theoretical and seems to make sense. But I don’t understand. Let me use my own words as the author.
Serial communication is a communication method that can send the results of the program running in the microcontroller or STM32 chip to the computer. How to use serial communication, you need to know several important knowledge points:
1. Baud rate. (The speed of data transmission must be set to the same speed when the two devices communicate, otherwise garbled characters will appear).
2. Hardware connection. Serial communication is a kind of asynchronous communication, generally TX->RX, RX->TX.
3. Stop bit.
4. Parity check.
5. Hardware data flow.
3, 4, and 5 generally do not need to be changed, so there is no need to say more here.
Serial port function
What can the serial port be used for?
Anyone who has learned C language knows that program development requires constant debugging and verification. Many language programming software have complete program debugging functions. It is very convenient to use. Although we also use C language for development, the environment in which our program ultimately runs is not on our development platform but on a real hardware system. At this time, it is not as convenient as programming software to view the running process or results of the program.
To solve this problem, we can use serial communication to send the results we need to know or the key steps of the program to the computer. Then we will know whether there is a problem running the program in the hardware system. The 51 microcontroller can be debugged using the serial port, and the STM32 can be debugged using the serial port. More advanced LINUX development boards also use the serial port for debugging.
Learn what serial communication can do
When you learn serial communication, you can start playing with WIFI modules, GSM modules, Bluetooth modules, GPS modules, and various sensors that use serial communication, etc. If you have the ability, you can also write host computer software to control the device through serial communication.
What is needed for serial communication
If you only have an STM32 core board, then you also need a serial port to USB module, a serial port data receiving software and a few DuPont cables. If yours is a relatively complete development board, it usually comes with a serial port to USB module, which makes it easier to use. If you are smart, you may find that something is missing, right? That's right because the most important program is missing. If you want to use serial communication, of course you also need to write a serial communication program. The following will teach you how to use it instead of writing it.
Serial port experiment
When doing an experiment, it is best to divide the experiment into several key steps. The advantage of this is that you can clearly know what you need to do and what you have completed. What else has not been done yet. Below, the author divides the serial port experiment into several key steps:
1) GPIO pin configuration used for serial communication.
STM32F103 series chips generally have more than three serial ports. The serial port used for debugging generally uses USART1. Other serial port configurations are the same.
The following section is the serial port configuration program:
The GPIO ports used by the serial port are PA9 and PA10, so you only need to configure the input and output modes of these two IO ports.
2) Setting the main parameters of the serial port (see the program directly)
Serial port parameter configuration can only configure the baud rate, data format, stop bits, parity, hardware stream, and transceiver mode of the serial port. Except for the baud rate that needs to be changed, other parameters do not need to be controlled. Just copy and use.
3) Serial port interrupt configuration
If the serial port uses interrupt reception, then you need to configure the interrupt parameters of the serial port. The configuration item cannot be just to configure the interrupt source and interrupt priority.
4) Serial port enable
It is an original function when you need to start using the serial port function.
5) Write serial port interrupt processing function
When developing using library functions, all interrupt functions already exist, but nothing is processed in the interrupt function. The interrupt function is as follows:
Complete serial port interrupt function:
The functions for receiving and sending serial port data are all provided by library functions. When you want to use them, you only need to find it and use it directly.
The above completes the simplest serial port experiment. Compile and program the program to STM32 and then use the serial port to USB module to connect to the computer. Use the serial port data receiving software SSCOM or other data receiving software to set the baud rate and open the serial port. If it is normal, what is sent to the STM32 will be received. To what. That's it.
That’s all for this time. If there is a supporting routine for the development board, you can use it first. After using it more, you will gradually understand it. This article mainly wants to explain the importance of the serial port. It is really convenient to use the serial port to debug.
Previous article:Microcontroller keyboard detection and application
Next article:Common methods and precautions for microcontroller output PWM
- 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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- [Analog Electronics Course Selection Test] + User Experience
- ECG 12-lead
- What is the relationship between baud rate and USB or network bit rate? For example, 900 (Baud, symbol/s) is used in some places...
- IoT indoor environment monitor based on ESP32-S2-Kaluga-1] Reading svm40 sensor module data
- 01.GD32L233C-START, the energy-saving "core" era!
- Implementation of SDRAM controller in high-speed image storage system.pdf
- [Sipeed LicheeRV 86 Panel Review] IX. lvgl Reuse
- Common mistakes made by C language beginners | 22 points of summary
- PWM pulses generated by ecap
- 【Goodbye 2021, Hello 2022】Busy and fulfilling