芯片破解H32V103配置有3个串口,适用于需要同时使用多个串口工作的环境,例如用在一个采用串口屏来显示工作界面并绘制数据波形曲线、一个串口用来控制数据记录仪来存储原始数据、一个串口来控制MP3音频播放模块来播报数据或发出语音提示等。
那么这3个串行通讯口都使用哪些引脚呢?
其使用的引脚情况如表1所示:
其中,USART1主要供打印输出之用,其接口电路如图1所示。
图1 串口1接口电路
芯片破解|
USART1执行老本行,来完成信息输出的工作;而将USART2和USART3组成一个模拟双方收发数据的终端。
那完成这一任务都需要哪些器件呢?
一条杜邦线,一个USB转TTL通信串口模块及导线,具体的连接形式如图2所示。
杜邦线的作用是将USART2的TX连接到USART3的RX,这样就用一条杜邦线连接起了模拟通信的收发双发。
USB转TTL通信串口模块大的作用,则是将USART1的输出信息传输到电脑,并通过串口助手等工具软件来显示信息。
当然了,如果你要想令USART2和USART3的地位平等,那也很容易,无非是再添加一条杜邦线,将空置的2个通讯引脚连接起来便是了!
u8 TxBuffer[] = "Buffer Send fromUSART2 to USART3 by polling!";
然后通过USARTx_CFG函数对USART2和USART3进行初始化,其内容如下:
- 芯片破解|void USARTx_CFG(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB1Periph_USART3, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB , ENABLE);
- /* USART2 TX-->A.2 RX-->A.3 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* USART3 TX-->B.10 RX-->B.11 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- USART_InitStructure.USART_BaudRate = 115200;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No;
- USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
- USART_Init(USART2, &USART_InitStructure);
- USART_Cmd(USART2, ENABLE);
- USART_Init(USART3, &USART_InitStructure);
- USART_Cmd(USART3, ENABLE);
- }