• 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 }
  • 相关阅读:
    Objective C 总结(十):Conventions
    Objective C 总结(九):Errors
    iOS 关于传值
    iOS UIImage剪切圆形
    iOS 触摸的位置放一个大头针
    iOS开发之各种动画各种页面切面效果
    AFNetworking2.4.1 解析
    iOS网络协议----HTTP/TCP/IP浅析
    ios 开发日记 9
    ios开发日记
  • 原文地址:https://www.cnblogs.com/leo0621/p/8709944.html
Copyright © 2020-2023  润新知