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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > STM32串口中斷方式接收

          STM32串口中斷方式接收

          作者: 時間:2016-11-20 來源:網(wǎng)絡(luò) 收藏
          void RCC_Configuration(void)

          {

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

          RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA |
          RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
          }

          首先中斷的配置

          void NVIC_Configuration(void)
          {
          NVIC_InitTypeDef NVIC_InitStructure;

          #ifdefVECT_TAB_RAM

          NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
          #else

          NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
          #endif


          NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

          NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
          NVIC_Init(&NVIC_InitStructure);
          }

          接著設(shè)置GPIO的第二功能

          void GPIO_Configuration(void)
          {
          GPIO_InitTypeDef GPIO_InitStructure;


          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_Init(GPIOA, &GPIO_InitStructure);

          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
          GPIO_Init(GPIOA, &GPIO_InitStructure);

          }

          初始化串口

          void USART_Configuration(void)
          {
          USART_InitTypeDef USART_InitStructure;
          USART_ClockInitTypeDefUSART_ClockInitStructure;



          #if 1
          USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
          USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
          USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
          USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;

          USART_ClockInit(USART1, &USART_ClockInitStructure);
          #endif
          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_ITConfig(USART1, USART_IT_RXNE, ENABLE);


          USART_Cmd(USART1, ENABLE);

          }

          然后是中斷處理函數(shù),這里只實現(xiàn)了簡單的將收到的字符回顯到終端上

          void USART1_IRQHandler(void)
          {
          u16 i;

          if(USART_GetFlagStatus(USART1,USART_IT_RXNE)==SET)
          {
          i = USART_ReceiveData(USART1);
          USART_SendData(USART1,i);
          while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
          {
          }
          }

          if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
          {

          USART_ClearITPendingBit(USART1, USART_IT_RXNE);

          }

          }



          關(guān)鍵詞: STM32串口中斷方

          評論


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