Based on the underlying configuration of STMicroelectronics MCU STM32
[Copy link]
STMicroelectronics MCU is the world's leading semiconductor supplier, and STM32 MCU is widely used in a variety of different industries. For this reason, this article will introduce the relevant technologies related to the underlying configuration of STM32.
This article introduces the main underlying configuration of STM32, and explains the details and precautions of realizing data transmission through the introduction of the program source code of the key steps. This method has certain implementation value and reference value for other projects or chips, and it is simple, reliable, universal and general.
1. STM32 underlying configuration
In order to realize the transmission of data commands between the STM32 microcontroller and the SIM900A module, this article takes the serial port as an example, first builds a development platform, adds corresponding library functions and configuration files to the project, and then configures the clock and the corresponding input and output GPIO interface of the serial port. At the same time as the configuration, it is necessary to write for its own schematic diagram to ensure that the configuration is correct. In this way, the basic development platform is built.
1.1. Serial port configuration
After the development platform is built, the serial port can be configured. Configure the rate to 115200b/s, the word length to 8bit, 1bit stop bit, the serial port mode to input and output mode, and finally initialize the corresponding serial port. After initializing the serial port, open the interrupt response function of the serial port, that is, USART_ITConfig (USART2, USART_IT_RXNE, ENABLE) (taking serial port 2 as an example), and then enable the corresponding serial port, so that the serial port function is basically configured. It should be noted that some programs may lose the first bit during transmission. This problem involves the mechanism of USART. After the hardware is reset, the status bit of USART is set (set to 1, indicating that it has been sent), and the data can be sent normally at this time. When a frame of data is sent, the hardware sets the bit. Clearing the TC bit (setting to 0) is done by software, by reading USART_SR first and then writing USART_DR to clear the bit. However, when the program sends the first frame of data, it does not read USART_SR, but directly writes USART_DR, so the TC flag is still set to 1 and is not cleared. After sending the first frame of data, if the status returned by USART_GetFlagStatus() is that the data has been sent, the program will immediately send the next frame of data, so the first frame of data will be overwritten by the second frame of data, so that the first data cannot be seen. According to this situation, the transmission completion flag can be cleared before or after each transmission, that is, USART_ClearFlag (USART2, USART_FLAG_TC).
1.2. Interrupt configuration
After configuring the serial port, NVIC will be configured. First configure the interrupt grouping, and then select the interrupt of the serial port, that is, NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn (based on the definition of the firmware library used).
Then set the preemptive interrupt priority and the responsive interrupt priority, and then enable the interrupt and initialize. The above configuration must be combined with its own situation to design the optimal interrupt grouping and priority to ensure the speed of the program responding to the interrupt. The content after the interrupt is configured in the stm32f10x_it.c file. MCU is extremely widely used. In order to no longer rely on imported chips, domestic local companies have devoted themselves to the research and development of domestic chips. Hundreds of MCU products have been provided to the market. For example, Lingdong Microelectronics, its MM32F series products are replaceable and compatible with the STM32F series.
|