System: Linux Mint 18.3 xfce 64bit
Software:
STM32CubeMX 4.24
SW4STM32 2.4
Development board chip: STM32F103RCT6, STM32F407VET6
Implementation effect: Open two serial port assistant windows, one for USART1 and one for USART2. Data sent from any serial port (serial port 1 or serial port 2) will be immediately returned through this serial port
.
Advantages of using STM32CubeMX and SW4STM32:
(1) Advantage of cross-platform development, there are ready-made installation packages for both Windows and Linux systems, and the installation process of sw4stm32 will automatically install the STLINK driver
(2) Version upgrades are active, which I think is a good phenomenon, indicating that developers attach great importance to it
(3) The most important thing is free! ! ! No need to look for crack activation everywhere
(1) Use STM32CubeMX to configure TIM3, PA8, PD2 (LED light), USART1, USART2 in Pinout.
(2) Keep the clock configuration as default
(3) Set the TIM1 clock to interrupt once every 1s
(4) Keep the baud rates of USART1 and USART2 unchanged, set NVIC as shown below, pay attention to the priority
(5) and then generate the SW4STM32 project
(6) Use sw4stm32 to open the project and
add three codes in main.c. Please refer to the prompts for the specific locations. The entire main.c file is too long to post.
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
uint8_t aTxBuffer[]="*********Serial port sends data ××××××××××××\r\n";
uint8_t aRxBuffer1[1]; // used to receive data sent by serial port 1
uint8_t aRxBuffer2[1]; // used to receive data sent by serial port 2
/* USER CODE END PV */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
HAL_UART_Receive_IT(&huart1,aRxBuffer1,1); // Enable the USART1 Interrupt
HAL_UART_Receive_IT(&huart2,aRxBuffer2,1); // Enable the USART2 Interrupt
HAL_UART_Transmit(&huart1,aTxBuffer,sizeof(aTxBuffer),100);
HAL_UART_Transmit(&huart2,aTxBuffer,sizeof(aTxBuffer),100);
HAL_TIM_Base_Start_IT(&htim3); // Start timer 3
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance == USART1) // Determine which serial port triggered the interrupt
{
HAL_UART_Transmit(&huart1,aRxBuffer1,1,100); // Send the received data immediately using serial port 1
HAL_UART_Receive_IT(&huart1,aRxBuffer1,1); // Re-enable serial port 1 receive interrupt
}
if(huart->Instance == USART2)
{
HAL_UART_Transmit(&huart2,aRxBuffer2,1,100); // Send the received data immediately using serial port 1
HAL_UART_Receive_IT(&huart2,aRxBuffer2,1); // Re-enable serial port 2 receive interrupt
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim->Instance == TIM3) // Determine which timer triggered the interrupt
{
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_8);
}
}
/* USER CODE END 4 */
If you find that the effect cannot be achieved, please check whether your hardware connection is correct, and whether the USB to TTL converter is normal. I encountered that my USB to TTL converter could receive data from STM32 but could not send data. I tossed it all night and changed the serial port line the next day to test it. It was normal
Previous article:Detailed explanation of STM32CubeMX clock configuration
Next article:STM32 serial port obtains ammonia sensor data
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications