<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STM32串口通信設(shè)置(查詢方式)

          STM32串口通信設(shè)置(查詢方式)

          作者: 時(shí)間:2016-11-25 來源:網(wǎng)絡(luò) 收藏
          首先是配置UART的GPIO口


          void UART1_GPIO_Configuration(void)
          {
          GPIO_InitTypeDef GPIO_InitStructure;
          // Configure USART1_Tx as alternate push-pull
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
          GPIO_Init(GPIOA, &GPIO_InitStructure);

          // Configure USART1_Rx as input floating
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
          GPIO_Init(GPIOA, &GPIO_InitStructure);
          }

          然后是配置串口參數(shù)

          void UART1_Configuration(void)
          {

          USART_InitTypeDef USART_InitStructure;

          USART_InitStructure.USART_BaudRate = 9600;
          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_Rx | USART_Mode_Tx;


          USART_Init(USART1, &USART_InitStructure);


          USART_Cmd(USART1, ENABLE);
          }

          本文引用地址:http://www.ex-cimer.com/article/201611/321209.htm

          發(fā)送一個(gè)字符
          [
          u8 Uart1_PutChar(u8 ch)
          {

          USART_SendData(USART1, (u8) ch);
          while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
          {
          }
          return ch;
          }
          發(fā)送一個(gè)字符串

          void Uart1_PutString(u8* buf , u8 len)
          {
          for(u8 i="0";i {
          Uart1_PutChar(*buf++);
          }
          }



          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();