STM32 串口固件库中定义的几个中断标志什么意思?
2014-08-20 22:50
531 查看
STM32 串口固件库中定义的几个中断标志位什么意思?
#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)
可见,在stm32f10x_usart.h中宏定义的以上几个宏,很没有规律,咋一看还真不知道为什么会这么定义,其实通过代码就很容易明白:
D7~D5:代表中断标志位对应的中断使能位在 CR1、CR2还是CR3寄存器中
D4~D0:代表中断标志位对应的中断使能位在CRx寄存器的哪一位
D15~D8:代表中断标志位在SR寄存器中的哪一位
上面我们仅仅是给出了这个结论,其实仅仅是看上面的几行宏定义是看不出来各位代表什么意思的,只有从代码中推理出来,下面给出stm32f10x_usart.c中USART_GetITStatus函数的实现就可以推理出上面为什么将上面的那几个宏定义成那种形式了!
/**
* @brief Checks whether the specified USART interrupt has occurred or not.
* @param USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* USART1, USART2, USART3, UART4 or UART5.
* @param USART_IT: specifies the USART interrupt source to check.
* This parameter can be one of the following values:
* @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
* @arg USART_IT_LBD: LIN Break detection interrupt
* @arg USART_IT_TXE: Tansmit Data Register empty interrupt
* @arg USART_IT_TC: Transmission complete interrupt
* @arg USART_IT_RXNE: Receive Data register not empty interrupt
* @arg USART_IT_IDLE: Idle line detection interrupt
* @arg USART_IT_ORE: OverRun Error interrupt
* @arg USART_IT_NE: Noise Error interrupt
* @arg USART_IT_FE: Framing Error interrupt
* @arg USART_IT_PE: Parity Error interrupt
* @retval The new state of USART_IT (SET or RESET).
*/
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); //由此可见D7~D5:代表中断标志位对应的中断使能位在
CR1、CR2还是CR3寄存器中
/* Get the interrupt position */
itmask = USART_IT & IT_Mask;
itmask = (uint32_t)0x01 << itmask; //由此可见D4~D0:代表中断标志位对应的中断使能位在CRx寄存器的哪一位
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; //由此可见D15~D8:代表中断标志位在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;
}
#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)
可见,在stm32f10x_usart.h中宏定义的以上几个宏,很没有规律,咋一看还真不知道为什么会这么定义,其实通过代码就很容易明白:
D7~D5:代表中断标志位对应的中断使能位在 CR1、CR2还是CR3寄存器中
D4~D0:代表中断标志位对应的中断使能位在CRx寄存器的哪一位
D15~D8:代表中断标志位在SR寄存器中的哪一位
上面我们仅仅是给出了这个结论,其实仅仅是看上面的几行宏定义是看不出来各位代表什么意思的,只有从代码中推理出来,下面给出stm32f10x_usart.c中USART_GetITStatus函数的实现就可以推理出上面为什么将上面的那几个宏定义成那种形式了!
/**
* @brief Checks whether the specified USART interrupt has occurred or not.
* @param USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* USART1, USART2, USART3, UART4 or UART5.
* @param USART_IT: specifies the USART interrupt source to check.
* This parameter can be one of the following values:
* @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
* @arg USART_IT_LBD: LIN Break detection interrupt
* @arg USART_IT_TXE: Tansmit Data Register empty interrupt
* @arg USART_IT_TC: Transmission complete interrupt
* @arg USART_IT_RXNE: Receive Data register not empty interrupt
* @arg USART_IT_IDLE: Idle line detection interrupt
* @arg USART_IT_ORE: OverRun Error interrupt
* @arg USART_IT_NE: Noise Error interrupt
* @arg USART_IT_FE: Framing Error interrupt
* @arg USART_IT_PE: Parity Error interrupt
* @retval The new state of USART_IT (SET or RESET).
*/
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); //由此可见D7~D5:代表中断标志位对应的中断使能位在
CR1、CR2还是CR3寄存器中
/* Get the interrupt position */
itmask = USART_IT & IT_Mask;
itmask = (uint32_t)0x01 << itmask; //由此可见D4~D0:代表中断标志位对应的中断使能位在CRx寄存器的哪一位
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; //由此可见D15~D8:代表中断标志位在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;
}
相关文章推荐
- void (*func)(int) 知道这样定义这个函数什么意思么?
- XMLHttpRequest对象发送请求后,请求的状态有几个值,每个值代表什么意思?
- stm32 中断几个库函数实现过程分析。
- stm32串口中断接收发送实验
- STM32串口中断使用
- 什么叫oo编程,oo是哪两个英语单词缩写,rss标志是什么意思
- php定义function时,函数名前加“&”符号是什么意思?
- iPhone的解锁、越狱、激活、固件等等是什么意思_有什么分别
- "单片机外部中断0由数据信号线的下降沿触发"是什么意思
- STM32串口中断使用
- STM32串口中断方式接收
- iPhone的解锁、越狱、激活、固件等等是什么意思,有什么分别?
- c#【1】 串口编程:类名和命名空间是什么?有几个重要参数、并简述?
- ABAP编程中对内表的定义,后面接一个OCCURS (n)是代表什么意思。
- iPhone 的解锁、越狱、激活、固件等等是什么意思,有什么分别?
- fwrite()函数和fread()函数分别有几个返回值?分别代表什么意思?(C语言)
- 一不小心搜到几个有趣的英文句子,来猜猜它们的意思是什么
- STM32串口采样与仪表步进电机控制程序(主程序与串口程序,需用正点原子定时器中断实验程序模板)
- 杂乱无章_c++ 定义接口 [out,retval] 什么意思?
- (转载)怎么看到有的代码定义变量用var $a是什么意思?