How to Master STM32 and 51 Microcontrollers?

Personal Insights The best way to learn microcontrollers is to start programming them directly in C language, which saves time, is easier to learn, and allows for rapid progress. Let’s talk about microcontrollers. The STM32 and 51 microcontrollers are commonly used today, with abundant resources and a large market. The study of microcontrollers is a subject that emphasizes hands-on practice; you cannot just read books. However, it is essential to read first to gain a general understanding of the various functional registers of the microcontroller. To put it simply, using a microcontroller means controlling its various functional registers through software, which means controlling when the voltage levels on its pins are set high or low. The changes in these high and low voltage levels control your system board, enabling the various functions we need. As for reading, you only need to understand what each pin of the microcontroller does and what functions it can achieve. The first or second time you read it, you may not fully understand, but that’s okay because you still lack practical experience. Therefore, I always say that reading about microcontrollers for two or three days is sufficient. You can read five or six novels in a day, but you only need to read about microcontrollers two or three times in two or three days without needing to read in detail. If you don’t practice while learning about microcontrollers, it’s impossible to master them. There are two methods you can choose for practice.Method One Buy a microcontroller learning board. It doesn’t need to have too many functions. For beginners, buying a board with too many features is unnecessary; you will never use many of them in your lifetime. I recommend a board with a running light, seven-segment display, standalone keyboard, matrix keyboard, AD or DA (the principle is the same), LCD, and buzzer. If you can skillfully use these components, you can say you have entered the world of microcontroller hardware. The rest is to practice designing circuits and continuously accumulate experience.Method Two If you have an expert in microcontrollers nearby, ask them for help to set up a simple minimal system board for you. For an expert, creating a minimal system board for a microcontroller only takes a minute, but it can be much more challenging for a beginner because you need to understand the hardware to use it proficiently. If you don’t have such an expert nearby and can’t find anyone to help you, I suggest you buy one yourself. Having your own board is much more convenient, and you can use it for small experiments with microcontrollers in the future, saving you trouble. Once you have the microcontroller learning board, you need to practice more. Connect the learning board to your computer, open the debugging software, and learn how to use the debugging software. I recommend checking out related materials. Start with the simplest running light experiment. Once you can make those eight running lights flow according to your wishes, you have already entered the field; you will find microcontrollers are very fun.Driven by Interest People who do electronic design can really get addicted. Then make the seven-segment display light up. Once you master these two tasks, you will be hooked, and you will start considering which career path to take. Interest is the best teacher. Recommended article: Sharing Embedded Development Experience, Treating Learning as a Hobby. Additionally, I would like to quote a line from the Analects:

When it comes to a person, he is so focused on his studies that he forgets to eat, and he is so happy that he forgets his worries, not even realizing that old age is approaching.

Analects · Shu Er The general meaning is: when a person encounters something he cannot understand, he must study it thoroughly, to the point of forgetting to eat; he enjoys it so much that he forgets all his worries, even not realizing that old age is coming.How to Master STM32 and 51 Microcontrollers? When writing programs, you will definitely encounter many problems. At that time, you can flip through books or ask others for help. When you get the answers, you will remember them for a lifetime. Knowledge must be applied in real life to solve practical problems; only then can it play its role. I can tell you that once you learn microcontrollers, you will never forget them. As a college student, you can learn microcontrollers while learning C language, which is also quite simple; it is just a tool. I advise you to learn it well, as you will definitely need it in the future. If you don’t learn it, you will have a hard time later. It doesn’t matter if you don’t know assembly language at all, but if you don’t know any C language, you will suffer in the future. Writing code in assembly is efficient, but it is relatively difficult and verbose, especially when encountering algorithmic problems, which can be quite troublesome. Nowadays, the main frequency of microcontrollers is constantly increasing, and we no longer need such high-efficiency code because of the high-frequency clock. The ROM of microcontrollers is also continuously increasing, which is sufficient to accommodate any code you write in C language. The resources for C language are abundant and easy to find, and its portability is excellent. You only need to change an IO port to write a temperature sensor program, and it can be used anywhere, so I advise everyone to use C language. In summary, as long as you have confidence, can persist in your work, and have a strong will not to give up in the face of failure, learning microcontrollers will be a very easy task.Learning Practice Improving in microcontrollers relies heavily on practice. To master microcontrollers, software programming is essential. However, being familiar with hardware is also very important for mastering microcontrollers. To learn hardware well, hands-on practice is indispensable. We can improve our understanding and proficiency with certain chips by creating our own electronic projects. This way, we can gain a better understanding of the structure of the chips. I believe that once you complete your own electronic project, your level of microcontroller knowledge will qualitatively improve. This is my experience and insights on learning microcontrollers, and I hope it helps enthusiasts learn microcontrollers well. Using microcontrollers means understanding their hardware structure and the application of internal resources, learning various functional initialization settings in assembly or C language, and programming to achieve various functions.Step One: Using Digital I/O Use button input signals and light-emitting diodes to display output levels, which allows you to learn the digital I/O functions of the pins. When a certain button is pressed, a light-emitting diode lights up; this is the function of combinational logic in digital circuits. Although it is very simple, it allows you to learn the general programming ideas of microcontrollers. For example, many registers must be set to initialize the pins to enable digital input and output functions. Every time you use a function of the microcontroller, you must set the registers that control that function. This is a characteristic of microcontroller programming; do not be afraid of the trouble; all microcontrollers work this way.Step Two: Using Timers Learning to use timers allows you to implement sequential circuits with microcontrollers. The functionality of sequential circuits is powerful and has many applications in industrial and household electrical equipment control. For example, you can use a microcontroller to implement a corridor light switch with one button, which turns on the light for three minutes after pressing the button once and keeps the light on if the button is pressed twice in succession. If the button is pressed for more than 2 seconds, the light turns off. Digital integrated circuits can implement sequential circuits, programmable logic devices (PLD) can implement sequential circuits, and programmable controllers (PLC) can also implement sequential circuits, but only microcontrollers can do it most simply and at the lowest cost. The use of timers is very important; logical time control is the foundation of microcontroller usage.Step Three: Interrupts The characteristic of microcontrollers is that a segment of the program is executed repeatedly, and each instruction in the program requires a certain execution time. If the program does not execute a certain instruction, the action of that instruction will not occur, which can delay many rapid events, such as the falling edge when a button is pressed. To enable the microcontroller to respond to rapid actions during normal program execution, it is necessary to use the interrupt function of the microcontroller. This function interrupts the normal running program of the microcontroller when a rapid action occurs, processes the rapid action, and then returns to execute the normal program. The difficulty in using interrupts is knowing precisely when interrupts should not occur (masking interrupts) and when they should be allowed (enabling interrupts), which registers need to be set for a certain interrupt to take effect, what the program should do at the start of the interrupt, and what it should do after the interrupt is completed, etc. Once you learn interrupts, you can write more complex structured programs that can monitor one thing while doing another. Once the monitored event occurs, it interrupts the current task to handle the monitored event. Of course, you can also monitor multiple events. A vivid metaphor is that the interrupt function allows the microcontroller to eat from the bowl while watching the pot. Mastering the above three steps is equivalent to learning three moves of the Dragon Subduing Palm; you can barely protect yourself.Step Four: RS232 Communication with PC Microcontrollers all have USART interfaces, especially many models in the MSP430 series, which have two USART interfaces. The USART interface cannot be directly connected to the RS232 interface of a PC because their logic levels are different; a MAX3232 chip is needed for level conversion. The use of the USART interface is very important because it allows for the exchange of information between the microcontroller and the PC. Although RS232 communication is not advanced, it is crucial for learning about interfaces. To use the USART interface correctly, you need to learn about communication protocols, programming for the RS232 interface of the PC, and so on. Imagine how interesting it would be if the data displayed on the microcontroller experiment board could be shown on the PC monitor, and the keyboard signals from the PC could be displayed on the microcontroller experiment board!Step Five: Learning A/D Conversion The MAP430 microcontroller has a multi-channel 12-bit A/D converter, which allows the microcontroller to operate on analog quantities, displaying and detecting voltage, current, and other signals. When learning, pay attention to concepts such as analog ground and digital ground, reference voltage, sampling time, conversion rate, and conversion error. A simple example of using the A/D conversion function is designing a voltmeter.Step Six: Learning PCI, I2C Interfaces, and LCD Interfaces The use of these interfaces makes it easier for microcontrollers to connect to external devices, which is very important for expanding the functionality of microcontrollers.Step Seven: Learning Comparison, Capture, and PWM Functions These functions enable the microcontroller to control motors, detect speed signals, and implement motor speed controllers. If you master the above seven steps, you can design general application systems, equivalent to learning ten moves of the Dragon Subduing Palm, and you can start attacking.Step Eight: Learning USB Interfaces, TCP/IP Interfaces, and Various Industrial Bus Designs Learning the hardware and software design of USB interfaces, TCP/IP interfaces, and various industrial buses is very important because this is the direction of current product development. By this point, you may not yet be invincible, but you can be considered a microcontroller expert! The following text introduces the path to becoming a microcontroller expert through three plans.The Path to Becoming a Microcontroller Expert: Three Plans First of all, microcontrollers are not omnipotent, but without them, nothing can be done. The demand for this in society is increasing. So what are you worried about? Are you afraid you won’t have a place to use your skills? Are you worried that your salary won’t be high enough? I have been working in microcontrollers and my familiar industry for nearly ten years. Whether my skills are good or not, I should be humble and continue to learn. After all, microcontrollers are always a system engineering project, and you cannot be familiar with and master every aspect of it. The results of microcontroller work are just components. Because they are “components,” you need to provide corresponding physical dimensions, heat dissipation for the microcontroller system, installation conditions, and installation methods, which need to be coordinated with the environment provided by your upstream and downstream partners. It’s not enough to just complete the functions of the microcontroller and think everything is fine.Regarding project development, I recommend the article: Organizing Microcontroller Learning Methods and Product Development Processes Just considering the functions that need to be implemented by the microcontroller, if you can’t even achieve the functions, what use do you have—this is just basic work. In fact, the environment provided by upstream and downstream partners often tests your design, and you may need to change various plans to achieve better results.Clearly, such upstream and downstream environments are a great resource for you, but some people may overlook them. Familiarizing yourself with the things you develop and their usage and value in this industry is a great reference for your future development.Unlike C or C++ programmers, who may feel frustrated when they don’t have a platform to showcase their skills.On the contrary, for microcontrollers, we can establish a platform for ourselves to showcase and develop our skills. From my understanding, microcontrollers are quite “low-level” and “hardware-oriented.” There are not many complex data structures or programming algorithms that require skills. As long as we understand and program from the perspective of microcontroller execution, it’s sufficient. A microcontroller can constitute an electronic system or just an intelligent node. There’s not much complex stuff to study because we are merely users of microcontrollers; we shouldn’t elevate ourselves to the height of “research.” We only operate at the height of “application.” Familiarizing yourself with the upstream and downstream environments and conditions of microcontrollers is not very difficult. I hope that my understanding of these things can help newcomers and provide some food for thought.Planning Level One: When you have a certain age and human resources, you can start your own business and become a so-called half-boss.But saying it’s easy to be your own boss is also easy, and saying it’s not easy is also not easy.At first, I was apprehensive but jumped in.Many projects were taken on, and the cycles I set for myself were often short. I was often working on maintenance for previous projects during the day and developing new projects until one or two in the morning. I don’t need to mention how tiring it is; sometimes I think I’m risking my life to make money! My wife didn’t quite agree with me starting my own business, so I told her that I might not be able to provide a stable income every month, but I guarantee that the average monthly income for the year will not be lower than what I currently earn. Thus, I began to walk my own path.I’m not afraid of hardship or suffering, nor am I afraid of not reaping rewards for my efforts.What I fear is not overcoming my psychological barriers and the so-called “face” in certain situations. At the very least, we should use the “least cost” to pay for our “tuition.”It’s not embarrassing to say that I’ve paid quite a bit for my “tuition.” A successful project is not about how good or strong your functions are, but how much profit your successful development brings to your project partner; that is true success, even if you only earned a small development fee. When doing projects, don’t think too much about yourself; think from the perspective of the project partner.They trust you to hand over the project to you, so you should consider it from their perspective—sometimes their requirements may be a bit excessive, but as the saying goes, “Those who do not know should not blame.”Planning Level Two: Be a competent electronic engineer, both in software and hardware.There’s no need to learn too much; just learn some basics, and don’t follow trends; that’s unnecessary.Sometimes, even if you learn, if there are no corresponding development tasks, you will only learn the surface. However, even if it’s just the surface, that’s fine. When you really need it, you can pick it up quickly; it’s a form of preparation. But you should at least be proficient in one relatively narrow system, right?! Don’t be embarrassed; I only know the 51 microcontroller. Let me talk about myself; I work in the industrial automation field of machine tool equipment: Proficient in 51, STM32, etc., familiar with other microcontrollers, proficient in 51 assembly, proficient in CPLD, semi-proficient in C51 (only used for some human-machine interface work), and roughly familiar with FPGA (wanting to master my own 51 IP core).

  • Roughly familiar with ARM DSP, roughly familiar with ARM and DSP assembly, and understand C programming.
  • Proficient in 3D modeling software SOLIDWORKS (can model my own circuit boards and mechanical devices).
  • Roughly familiar with most machining processes.
  • Proficient in sheet metal and welding.
  • Familiar with solutions for CNC equipment and machine tools.

For everyone, applying what you learn is essential. In the past, I wanted to learn everything but couldn’t use anything well. When I was learning, I didn’t have a platform to apply my knowledge; it was all for the sake of learning. But at least when you need to use it, you can pick it up quickly. Take ARM as an example; I worked hard to learn it, from its principles to implementation, and did many experiments, but now I use it less, and I’m left with only some conceptual knowledge. Therefore, there’s no need to be proficient in everything; just be proficient in one thing. For example, the 51 microcontroller, from design, board production, procurement, soldering, to debugging into a finished product, if you have thought it through and mastered it, what are you afraid of? Even if you don’t get a high salary, you should still be able to earn a good annual salary. You should understand the saying, “It’s hard to find a good boss.”Planning Level Three: Be a qualified novice electronic engineer.For novices, my advice is:Don’t start with a five or ten-year plan; we are ordinary people, and such plans are not suitable for ordinary people.If we can make a good plan for the next year or two, that would be impressive. Every day is a new idea, every month is a change, let alone every year. As long as you are working hard and doing things steadily.Don’t make yourself too busy; leave half an hour each day to think about your “heart matters.”Do one thing well, then expand outwards. For electronics, ARM, DSP, and 51 are all interconnected.If you master one system, then other electronic systems are interconnected.What’s scary is that you don’t understand anything and are only half-knowledgeable.Wandering around with half a bucket of water is a bit frustrating and sad!

Leave a Comment