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

          新聞中心

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

          STM32的串口配置(中斷方式)

          作者: 時間:2013-04-10 來源:網(wǎng)絡(luò) 收藏

          修改NVIC_Configuration函數(shù)

          /***********************************************************

          * Name : NVIC_Configuration

          * Deion : Configures NVIC and Vector Table base location.

          * Input : None

          * Output : None

          * Return : None

          ***************************************************/

          void NVIC_Configuration(void)

          {

          NVIC_InitTypeDef NVIC_InitStructure;

          #ifdef VECT_TAB_RAM

          /* Set the Vector Table base location at 0x20000000 */

          NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);

          #else /* VECT_TAB_FLASH */

          /* Set the Vector Table base location at 0x08000000 */

          NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

          #endif

          /* Configure the NVIC Preemption Priority Bits */

          NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

          /* Enable the USART1 Interrupt */

          NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;

          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

          NVIC_Init(NVIC_InitStructure);

          }

          //串口中斷

          void USART1_IRQHandler(void)

          {

          //處理接收到的數(shù)據(jù)

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

          {

          /* Clear the USART1 Receive interrupt */

          USART_ClearITPendingBit(USART1, USART_IT_RXNE);

          }

          //發(fā)送中斷

          if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET)

          {

          USART_SendData(USART1, Send_Data[Send_Length++]);

          if (Send_Length==SEND_LENGTH)

          {

          //發(fā)送字節(jié)結(jié)束

          USART_ClearITPendingBit(USART1,USART_IT_TXE);

          USART_ITConfig(USART1, USART_IT_TXE, DISABLE);

          USART_ITConfig(USART1, USART_IT_TC, ENABLE);

          }

          }

          //發(fā)送完成

          if (USART_GetITStatus(USART1, USART_IT_TC) != RESET)

          {

          USART_ClearITPendingBit(USART1,USART_IT_TC);

          USART_ITConfig(USART1, USART_IT_TC, DISABLE);

          }

          }

          在需要發(fā)送的程序里Send_Data[SEND_LENGTH]和發(fā)送長度設(shè)置好,

          void Send_to_PC(void)

          {

          //設(shè)置好Send_Data[SEND_LENGTH]數(shù)組

          //打開發(fā)送中斷

          USART_ITConfig(USART1, USART_IT_TXE, ENABLE);

          }

          至此 串口就可以工作起來了!~


          上一頁 1 2 下一頁

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

          評論


          相關(guān)推薦

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