How to write STM32 UART2 interrupt function

Publisher:ww313618Latest update time:2018-06-01 Source: eefocusKeywords:STM32  UART2 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

void USART2_IRQHandler(void)
{
 uchar tmp;
 //接收中断
 if(USART_GetITStatus(USART2,USART_IT_RXNE)==SET)  // 接收 中断
 {
  USART_ClearITPendingBit(USART2,USART_IT_RXNE); // U1RX_Clear_Intr_Status_Bit;
  tmp=USART_ReceiveData(USART2);
  }
 //USART_IT_TXE // 发送中断
 if( USART_GetITStatus(USART2, USART_IT_TXE) == SET  ) //一个是TXE=发送数据寄存器空,
 {
  if(TIndex2 < TCount2)
  {
   USART_SendData(USART2, TxBuf2[TIndex2++]);         
  }
  else if(TIndex2 == TCount2)
  {
   USART_SendData(USART2, 0x0D);
   TIndex2 ++;
  }
  else
  { // 因为是 发送寄存器空 的中断,所以发完字符串后必须关掉,
   // 否则只要空了,就会进中断  //送數據寄存器空標志位 
   //fTransmission_Complete=1;
   USART_ITConfig(USART2, USART_IT_TXE, DISABLE);                                                  
   //DIS_485TX();  为避免提前关闭,导致的发送不全.移至 外部Timer中控制.   
  }
 }
 //溢出-如果发生溢出需要先读SR,再读DR寄存器 则可清除不断入中断的问题
 if(USART_GetFlagStatus(USART2,USART_FLAG_ORE)==SET)
 {
  USART_ClearFlag(USART2,USART_FLAG_ORE); // 读SR
  USART_ReceiveData(USART2);    // 读DR
 }

}


Keywords:STM32  UART2 Reference address:How to write STM32 UART2 interrupt function

Previous article:Use of USART2 in STM32F103
Next article:Differences between LPC17xx Uart0, Uart1, Uart2, and Uart3

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号