野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2643|回复: 0

STM32指南者 串口通信 移植的疑惑

[复制链接]
发表于 2023-4-12 21:52:46 | 显示全部楼层 |阅读模式
  1. void DEBUG_USART_IRQHandler(void)
  2. {
  3.   uint8_t ucTemp;
  4.         if(USART_GetITStatus(DEBUG_USARTx,USART_IT_RXNE)!=RESET)
  5.         {               
  6.                 ucTemp = USART_ReceiveData(DEBUG_USARTx);
  7.                 USART_SendData(DEBUG_USARTx,ucTemp);     
  8.         }         
  9. }
复制代码
stm32指南者串口通信实验中,移植USART1接发到USART2接发的时候,为何这里的中断函数的中断标志位还是选取的RXNE?

  1. #define USART_IT_RXNE                        ((uint16_t)0x0525)
复制代码
  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.   /* The CTS interrupt is not available for UART4 and UART5 */
  9.   if (USART_IT == USART_IT_CTS)
  10.   {
  11.     assert_param(IS_USART_123_PERIPH(USARTx));
  12.   }   
  13.   
  14.   /* Get the USART register index */
  15.   usartreg = (((uint8_t)USART_IT) >> 0x05);
  16.   /* Get the interrupt position */
  17.   itmask = USART_IT & IT_Mask;
  18.   itmask = (uint32_t)0x01 << itmask;
  19.   
  20.   if (usartreg == 0x01) /* The IT  is in CR1 register */
  21.   {
  22.     itmask &= USARTx->CR1;
  23.   }
  24.   else if (usartreg == 0x02) /* The IT  is in CR2 register */
  25.   {
  26.     itmask &= USARTx->CR2;
  27.   }
  28.   else /* The IT  is in CR3 register */
  29.   {
  30.     itmask &= USARTx->CR3;
  31.   }
  32.   
  33.   bitpos = USART_IT >> 0x08;
  34.   bitpos = (uint32_t)0x01 << bitpos;
  35.   bitpos &= USARTx->SR;
  36.   if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
  37.   {
  38.     bitstatus = SET;
  39.   }
  40.   else
  41.   {
  42.     bitstatus = RESET;
  43.   }
  44.   
  45.   return bitstatus;  
  46. }
复制代码
如果选取的标志位RXNE,其值为0x0525,得到的usartreg为0x01,而IT_Mask的值为0X1F,这样运算下来itmask = 0x01,不是永远都只会进入CR1吗,跟CR2串口中断有什么关系呢。
野火论坛202304122147248480..png
野火论坛202304122147166865..png
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-6-15 20:07 , Processed in 0.048901 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表