芯片解密,芯片破解,IC解密,单片机解密,MCU解密,STM解密

飞芯科技提供芯片解密,芯片破解,IC解密,单片机解密,MCU解密,STM解密逆向服务

CH32V103的多串口通讯及验证IC解密

IC解密H32V103配置有3个串口,适用于需要同时使用多个串口工作的环境,例如用在一个采用串口屏来显示工作界面并绘制数据波形曲线、一个串口用来控制数据记录仪来存储原始数据、一个串口来控制MP3音频播放模块来播报数据或发出语音提示等。
那么这3个串行通讯口都使用哪些引脚呢?
其使用的引脚情况如表1所示:


  
串口序号
  
TX
RX
USART1
A.9
A.10
USART2
A.2
A.3
USART3
B.10
B.11


其中,USART1主要供打印输出之用,其接口电路如图1所示。


1.jpg
图1 串口1接口电路



  1. void USARTx_CFG(void)
  2. {
  3. GPIO_InitTypeDef GPIO_InitStructure;
  4. USART_InitTypeDef USART_InitStructure;
  5. RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB1Periph_USART3, ENABLE);     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB , ENABLE);
  6. /* USART2 TX-->A.2   RX-->A.3 */
  7. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  8. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  9. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  
  10. GPIO_Init(GPIOA, &GPIO_InitStructure);
  11. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  12. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  13. GPIO_Init(GPIOA, &GPIO_InitStructure);
  14. /* USART3 TX-->B.10  RX-->B.11 */
  15. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  16. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  17. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  
  18. GPIO_Init(GPIOB, &GPIO_InitStructure);
  19. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  20. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  21. GPIO_Init(GPIOB, &GPIO_InitStructure);   
  22. USART_InitStructure.USART_BaudRate = 115200;
  23. USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  24. USART_InitStructure.USART_StopBits = USART_StopBits_1;
  25. USART_InitStructure.USART_Parity = USART_Parity_No;
  26. USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
  27. USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
  28. USART_Init(USART2, &USART_InitStructure);
  29. USART_Cmd(USART2, ENABLE);
  30. USART_Init(USART3, &USART_InitStructure);
  31. USART_Cmd(USART3, ENABLE);
  32. }
复制代码


实现多串口通信测试的主程序如下:
  1. int main(void)
  2. {
  3. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  4. Delay_Init();
  5. USART_Printf_Init(115200);
  6. printf("SystemClk:%d\r\n",SystemCoreClock);
  7. printf("USART Polling TEST\r\n");
  8. USARTx_CFG();
  9. while(TxCnt<TxSize)
  10. {
  11. USART_SendData(USART2, TxBuffer[TxCnt++]);
  12. while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
  13. while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET);
  14. RxBuffer[RxCnt++] = (USART_ReceiveData(USART3));
  15. }
  16. TransferStatus=Buffercmp(TxBuffer,RxBuffer,TxSize);
  17. if(TransferStatus)
  18. {
  19. printf("send success!\r\n");
  20. printf("TXBuffer: %s \r\n",TxBuffer);
  21. printf("RxBuffer: %s \r\n",RxBuffer);
  22. }
  23. else
  24. {
  25. printf("send fail!\r\n");
  26. printf("TXBuffer: %s \r\n",TxBuffer);
  27. printf("RxBuffer: %s \r\n",RxBuffer);
  28. }
  29. while(1);
  30. }



联系方式

地址:石家庄市新华区民族路77号华强广场D座2009
电话:0311-88816616/87087811
手机:13315190088
传真:0311-67901001
联系人:张工
网址:www.taihedz.cn
邮箱:feixindz@163.com
微信:xinpianjiemi
QQ:527263666/568069805

在线客服
热线电话

企业微信