STM32 USATR固件库中定义的几个中断标志的含义
扫描二维码
随时随地手机看文章
在stm32f10x_usart.h中有以下宏定义:
#define USART_IT_PE ((uint16_t)0x0028)
#define USART_IT_TXE ((uint16_t)0x0727)
#define USART_IT_TC ((uint16_t)0x0626)
#define USART_IT_RXNE ((uint16_t)0x0525)
#define USART_IT_IDLE ((uint16_t)0x0424)
#define USART_IT_LBD ((uint16_t)0x0846)
#define USART_IT_CTS ((uint16_t)0x096A)
#define USART_IT_ERR ((uint16_t)0x0060)
#define USART_IT_ORE ((uint16_t)0x0360)
#define USART_IT_NE ((uint16_t)0x0260)
#define USART_IT_FE ((uint16_t)0x0160)
它的含义如下(Dx---表示二进制中的第x位):
D0~D4:代表中断标志位对应的中断使能位在CRx寄存器的哪一位
D5~D7:代表中断标志位对应的中断使能位在 CR1、CR2还是CR3寄存器中
D8~D15:代表中断标志位在SR寄存器中的哪一位
以上结论可以通过stm32f10x_usart.c中USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);函数的实现就可以推理出上面的结论!以下是其相应的代码。
ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT)
{
uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
ITStatus bitstatus = RESET;
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_USART_GET_IT(USART_IT));
if (USART_IT == USART_IT_CTS)
{
assert_param(IS_USART_123_PERIPH(USARTx));
}
usartreg = (((uint8_t)USART_IT) >> 0x05); //D5~D7:代表中断标志位对应的中断使能位在 CR1、CR2还是CR3寄存器中
itmask = USART_IT & IT_Mask;
itmask = (uint32_t)0x01 << itmask; //D0~D4:代表中断标志位对应的中断使能位在CRx寄存器的哪一位
if (usartreg == 0x01)
{
itmask &= USARTx->CR1;
}
else if (usartreg == 0x02)
{
itmask &= USARTx->CR2;
}
else
{
itmask &= USARTx->CR3;
}
bitpos = USART_IT >> 0x08; //D8~D15:代表中断标志位在SR寄存器中的哪一位
bitpos = (uint32_t)0x01 << bitpos;
bitpos &= USARTx->SR;
if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
return bitstatus;
}