• USART_GetITStatus和USART_GetFlagStatus的区别


    USART_GetITStatus()和USART_GetFlagStatus()的区别

      都是访问串口的SR状态寄存器,唯一不同是,USART_GetITStatus()会判断中断是否开启,如果没开启,也会返回false。

        ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint32_t USART_IT)

      该函数不仅会判断标志位是否置1,同时还会判断是否使能了相应的中断。所以在串口中断函数中,如果要获取中断标志位,通常使用该函数。------串口中断函数中使用。

        

         FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint32_t USART_FLAG)

      该函数只判断标志位。在没有使能相应的中断时,通常使用该函数来判断标志位是否置1。------做串口轮询时使用。

        

     1 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG)
     2 {
     3   FlagStatus bitstatus = RESET;
     4   /* Check the parameters */
     5   assert_param(IS_USART_ALL_PERIPH(USARTx));
     6   assert_param(IS_USART_FLAG(USART_FLAG));
     7 
     8   /* The CTS flag is not available for UART4 and UART5 */
     9   if (USART_FLAG == USART_FLAG_CTS)
    10   {
    11     assert_param(IS_USART_1236_PERIPH(USARTx));
    12   } 
    13     
    14   if ((USARTx->SR & USART_FLAG) != (uint16_t)RESET)
    15   {
    16     bitstatus = SET;
    17   }
    18   else
    19   {
    20     bitstatus = RESET;
    21   }
    22   return bitstatus;
    23 }
     1 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT)
     2 {
     3   uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
     4   ITStatus bitstatus = RESET;
     5   /* Check the parameters */
     6   assert_param(IS_USART_ALL_PERIPH(USARTx));
     7   assert_param(IS_USART_GET_IT(USART_IT)); 
     8 
     9   /* The CTS interrupt is not available for UART4 and UART5 */ 
    10   if (USART_IT == USART_IT_CTS)
    11   {
    12     assert_param(IS_USART_1236_PERIPH(USARTx));
    13   } 
    14     
    15   /* Get the USART register index */
    16   usartreg = (((uint8_t)USART_IT) >> 0x05);
    17   /* Get the interrupt position */
    18   itmask = USART_IT & IT_MASK;
    19   itmask = (uint32_t)0x01 << itmask;
    20   
    21   if (usartreg == 0x01) /* The IT  is in CR1 register */
    22   {
    23     itmask &= USARTx->CR1;
    24   }
    25   else if (usartreg == 0x02) /* The IT  is in CR2 register */
    26   {
    27     itmask &= USARTx->CR2;
    28   }
    29   else /* The IT  is in CR3 register */
    30   {
    31     itmask &= USARTx->CR3;
    32   }
    33   
    34   bitpos = USART_IT >> 0x08;
    35   bitpos = (uint32_t)0x01 << bitpos;
    36   bitpos &= USARTx->SR;
    37   if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
    38   {
    39     bitstatus = SET;
    40   }
    41   else
    42   {
    43     bitstatus = RESET;
    44   }
    45   
    46   return bitstatus;  
    47 }
  • 相关阅读:
    百度地图 android SDKv2.2.0
    由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值。System.Threading.ThreadAbortException
    jquery.autocomplete 搜索文字提示
    【444】Data Analysis (shp, arcpy)
    【442】Remote control GUP Linux
    【441】JSON format
    【440】Tweet 元素意义
    Spark(八)JVM调优以及GC垃圾收集器
    Spark(七)Spark内存调优
    Spark(六)Spark之开发调优以及资源调优
  • 原文地址:https://www.cnblogs.com/leo0621/p/8709944.html
Copyright © 2020-2023  润新知