打印

stm32的firmware库

[复制链接]
2843|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ninesunsz|  楼主 | 2009-5-12 09:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
stm32库中的关于uart的USART_GetITStatus()函数是查询中断源的,从函数库中看是根据uart的CR1,CR2,CR3三个寄存器判断中断位,但是手册中描述uart的SR才是中断标志位,CR中保存的只是中断使能的设定,这是怎么回事?
沙发
香水城| | 2009-5-16 21:56 | 只看该作者

楼主再看看

ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT)
{
  uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
  ITStatus bitstatus = RESET;
  /* Check the parameters */
  assert_param(IS_USART_ALL_PERIPH(USARTx));
  assert_param(IS_USART_GET_IT(USART_IT));
  assert_param(IS_USART_PERIPH_IT(USARTx, USART_IT)); /* The CTS interrupt is not available for UART4 and UART5 */  
  
  /* Get the USART register index */
  usartreg = (((uint8_t)USART_IT) >> 0x05);
  /* Get the interrupt position */
  itmask = USART_IT & IT_Mask;
  itmask = (uint32_t)0x01 << itmask;
  
  if (usartreg == 0x01) /* The IT  is in CR1 register */
  {
    itmask &= USARTx->CR1;
  }
  else if (usartreg == 0x02) /* The IT  is in CR2 register */
  {
    itmask &= USARTx->CR2;
  }
  else /* The IT  is in CR3 register */
  {
    itmask &= USARTx->CR3;
  }
  
  bitpos = USART_IT >> 0x08;
  bitpos = (uint32_t)0x01 << bitpos;
  bitpos &= USARTx->SR;  <<<
  if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
  {
    bitstatus = SET;
  }
  else
  {
    bitstatus = RESET;
  }
  
  return bitstatus;  
}

使用特权

评论回复
板凳
ninesunsz|  楼主 | 2009-5-17 15:56 | 只看该作者

犯的错误太低级了

今天版主指出来才发现,谢谢!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

31

主题

82

帖子

1

粉丝