Proteus + VSPD serial port emulation stm32
Tools ready
- stm32 CubeMX
used to create stm32 works, if you do not use the library if Hal can also create firmware library works directly with keil, non-essential, the present study established engineering CubeMX - keil5 / IAR
for programming. - Proteus
circuit simulation diagram for drawing. - VSPD
VSPD is a virtual serial port software , VSPD download link: https://pan.baidu.com/s/126ZXjs6z9E8mnMDLybnfIg
extraction code: xama
After installation open, create virtual serial port. vspd is added in the form of serial port, such as COM1, COM2 in pairs, so the data can only be sent to COM1 COM2, COM2 COM1 will automatically receive the data transmitted.
As shown, we have successfully created a virtual serial port. - Serial debugging assistant
as XCOM can be.
Proteus project
After the new construction Proteus, P shortcut key opening element library, MCU chip select type I herein stm32f103c6, and adding other elements, wherein the reset circuit and the external crystal is not required, can not added.
In addition, we need to use the DB9 serial port, component library search COMPIM. The TX and is connected to a TX COMPIM the stm32, RX and RX is connected, rather than as physical cross-linked (connected TX RX, TX even RX).
COMPIM configuration options:
CubeMX project configuration
Serial Transceiver program
About serial communication reference blog: https://blog.csdn.net/weixin_43116606/article/details/104222528
Here posted only part of the key code:
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart1, (uint8_t *)&aRxBuffer, 1);
user_main_printf("hello,"带火星的小木条!");
/* USER CODE END 2 */
/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
char *pCmd = NULL;
uint8_t len;
switch(aRxBuffer){
case '1':
pCmd = "command 1\r\n";
len = strlen(pCmd);
break;
case '2':
pCmd = "command 2\r\n";
len = strlen(pCmd);
break;
case '3':
pCmd = "command 3\r\n";
len = strlen(pCmd);
break;
case '4':
pCmd = "command 4\r\n";
len = strlen(pCmd);
break;
default:
pCmd = "command cmd\r\n";
len = strlen(pCmd);
break;
}
HAL_UART_Transmit(&huart1, (uint8_t *)pCmd, len,0xFFFF);
HAL_UART_Receive_IT(&huart1, (uint8_t *)&aRxBuffer, 1);
}
/* USER CODE END 4 */
Virtual serial port emulation
Back Proteus, double-click stm32 chip, load the hex file, and set the crystal is 8M.
Open the serial debugging assistant, select COM2, Baud rate the same as 9600.
First open the serial port, and then run Proteus simulation project.
PS: After running out to remember to delete virtual serial port, serial port otherwise would have been occupied yo