This post was last edited by dmzdmz666666 on 2023-8-4 21:53
Second article: Hello World! ! ! @dmz 23.08.04
This article mainly introduces the creation of the project and the use of the MCU's serial port, buttons and LEDs.
First of all, as an individual developer, when choosing a microcontroller, whether it is a mixed-signal IC, analog IC, or digital IC, the main focus is on hard power and soft power. Hard power mainly depends on the performance of the chip itself, whether it is good enough and suitable enough; on the other hand, soft power includes ecology. A good ecology allows developers to develop with twice the result with half the effort, without having to repeatedly step on the pitfalls that others have stepped on. Data sheets, user manuals, errata, usage precautions for each part, routines, SDKs, and driver libraries should be complete and easily accessible. In terms of hard power, domestic manufacturers' microcontrollers have gradually moved towards the mid-to-high-end in recent years, with better performance and richer product lines, but there is still a gap from international giants like STMicroelectronics, NXP Semiconductors, and Renesas Semiconductor; in terms of soft power, a typical example is STMicroelectronics' STM32 series, which has done a good job in localization. There are a lot of Chinese materials for the most common STM32F103 series, and many official English materials have Chinese versions. At the same time, we cooperate with domestic development board manufacturers, such as Zhengdian Atom, Wildfire Technology, and Anfulai Electronics, and launched many localized tutorials, which greatly reduced the usage threshold and development difficulty of ordinary individual developers. At the same time, there is a lot of information on the Internet, and there are also many evaluation boards and system boards of various types. Therefore, at least in China, the influence of STM32 is still very large; domestic microcontrollers should have advantages in localization, but the strange thing is that some MCU semiconductor manufacturers either still have information in English (I don’t understand, there is no problem with internationalization, you should also be based on localization, look to internationalization, and you can have one in Chinese and English), or the information is incomplete, or you need to register or leave a message to have a chance to see the information, or they simply don’t give it, and they are mysterious, saying that it is for big customers or companies, and you have to sign some agreement.
Xiaohua Semiconductor and Arteli Technology have done a good job in this regard. Their data sheets, user manuals, and manuals for development tools are all in native Chinese, and they provide a full set of routines and SDKs, driver libraries, and BSPs corresponding to development boards. For me, the manuals look particularly comfortable and intuitive, and do not require translation, and it is also easy to write programs. Moreover, the location of the information is also easy to find and can be downloaded very conveniently. Chips are also easy to buy on Taobao. For individual developers, these points directly make me support them without a second thought.
Back to business, this program needs to use the serial port, LED and button. The examples needed are in HC32F448_DDL_Rev1.0.0\HC32F448_DDL_Rev1.0.0\projects\ev_hc32f448_lqfp80\examples\usart\usart_uart_int .
However, if we take this usart_uart_int out separately, it cannot be compiled because it lacks components, as shown below
So after we take it out separately, we need to copy the drivers in HC32F448_DDL_Rev1.0.0\HC32F448_DDL_Rev1.0.0\drivers to a new folder, and create a subfolder HARDWARE to store our own custom components, as shown below
After entering the project, remember to click the two icons below and modify the corresponding drivers path. I will not go into details here.
The routine usart_uart_int is an interrupt for both RX and TX. Here I want to modify it so that RX is an interrupt and TX is implemented with printf . The serial port selected here is USART 2, because the built-in DAP circuit supports virtual serial port, and it is connected to USART 2, which is convenient for debugging.
I put all USART related functions in USART in the HARDWARE folder, which is clearer.
The first is MY_USART_Init(void) . It is named MY_USART_Init to avoid duplication with the function name in the driver library. The initialization process is the same as that in the routine, which is to configure GPIO, enable the corresponding clock, configure USART parameters, and enable RX TX functions, as shown in the figure below.
Then the RX function is implemented through interrupts. The configuration is shown in the figure below, including an ERROR interrupt and a FULL interrupt, as well as the corresponding callback function. Then in the FULL interrupt, we set the received data to be resent.
TX is sent actively. When USART_GetStatus detects that the TX status of USART is empty, the data to be sent is written to USART through USART_WriteData . At this time, USART will send the data out. At the same time, by redirecting the fputc function, printf can be used normally. Remember to add this "stdio.h" header file
The second thing is the LED and buttons, but in fact the official SDK has already prepared them for you, in the ev_hc32f448_lqfp80 subfolder.
First, the C file ev_hc32f448_lqfp80_tca9539.c contains the initialization of LED0-LED2, because the IO of these three LEDs is expanded by the TCA9539 chip, and then initialized with BSP_LED_Init();
The C file ev_hc32f448_lqfp80.c contains the initialization of the key KEY, which is initialized with BSP_KEY_Init(); and then judged by BSP_KEY_GetStatus(BSP_KEY_1) whether it is pressed. The pressed state is SET.
Because LED3 is directly controlled by the microcontroller through PA2, this involves initializing the GPIO port and setting it to output
Finally, initialize each module. Here I refer to the routine.
The final effect is that when you press the corresponding key, the corresponding LED will flip, and the USART will send "Hello World!!!@DMZ This is KEY_1
Looking at the final effect, the test is successful.
|