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

          新聞中心

          ARM的串口通信配置

          作者: 時(shí)間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
          #include "Usart.h"

          #include "stdio.h"

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

          void usart_Configuration(void)
          {GPIO_InitTypeDef GPIO_InitStructure;
          USART_InitTypeDef USART_InitStructure;
          NVIC_InitTypeDef NVIC_InitStructure;
          USART_ClockInitTypeDefUSART_ClockInitStructure;
          //////////////////////////////////////////////////////////////////
          //
          USART_ClockInit(USART1, &USART_ClockInitStructure);

          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_Rx | USART_Mode_Tx;

          USART_Init(USART1, &USART_InitStructure);


          USART_Cmd(USART1, ENABLE);
          USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
          USART_ITConfig(USART1,USART_IT_TXE,ENABLE);

          USART_ClearFlag(USART1, USART_FLAG_TC);
          }


          int fputc(int ch, FILE *f)
          {


          USART_SendData(USART1,(uint8_t) ch);


          while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
          {

          }

          return ch;
          }


          int fgetc(FILE *f)
          {

          while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)
          {}
          return (int)USART_ReceiveData(USART1);
          }

          void USART1_IRQHandler(void)
          {u16 RxBuf;
          if(USART_GetFlagStatus(USART1,USART_IT_RXNE)==SET)
          {
          RxBuf=USART_ReceiveData(USART1);
          //printf("%d",RxBuf);
          //printf("");
          switch(RxBuf)
          {//
          case 1: printf("1 ");printf("%d",255);break;//對(duì)方發(fā)送是1
          case 2: printf("2 ");printf("%d",255);break;//對(duì)方發(fā)送是2
          case 3: printf("3 ");printf("%d",255);break;//對(duì)方發(fā)送是3
          default: printf("4 ");printf("%d",255);break;
          }
          }
          if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)//這段是為了避免STM32 USART 第一個(gè)字節(jié)發(fā)不出去的BUG
          {
          USART_ITConfig(USART1, USART_IT_TXE, DISABLE);//禁止發(fā)緩沖器空中斷,
          }
          }



          關(guān)鍵詞: ARM串口通信配

          評(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); })();