小学生
最后登录1970-1-1
在线时间 小时
注册时间2023-4-3
|
- void DEBUG_USART_IRQHandler(void)
- {
- uint8_t ucTemp;
- if(USART_GetITStatus(DEBUG_USARTx,USART_IT_RXNE)!=RESET)
- {
- ucTemp = USART_ReceiveData(DEBUG_USARTx);
- USART_SendData(DEBUG_USARTx,ucTemp);
- }
- }
复制代码 stm32指南者串口通信实验中,移植USART1接发到USART2接发的时候,为何这里的中断函数的中断标志位还是选取的RXNE?
- #define USART_IT_RXNE ((uint16_t)0x0525)
复制代码- 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));
- /* The CTS interrupt is not available for UART4 and UART5 */
- if (USART_IT == USART_IT_CTS)
- {
- assert_param(IS_USART_123_PERIPH(USARTx));
- }
-
- /* 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;
- }
复制代码 如果选取的标志位RXNE,其值为0x0525,得到的usartreg为0x01,而IT_Mask的值为0X1F,这样运算下来itmask = 0x01,不是永远都只会进入CR1吗,跟CR2串口中断有什么关系呢。
|
-
-
|