cancel
Showing results for 
Search instead for 
Did you mean: 

Interpretation of TXEIE bit (UART programming)

sidney
Associate II
Posted on July 04, 2013 at 13:33

Hi all,

The documentation of the ''GetITStatus'' function, as found in the file 'stm32f10x_uasrt.c'', describes the functionality as follows:

    ''Checks whether the specified USART interrupt has occurred or not.''

However, when I follow what happens why I call GetITStatus(UART1, USART_IT_TXE), it appears that it simply returns bit 7 of CR1 (TXEIE) which, according to the STM32 reference manual (RM0008), is the ''TXE interrupt enable''.

It seems these are two different things; the GetITStatus() documentation claims that the bit returns if the interrupt *has happened*, while the reference manual gives the meaning as: the interrupt is enabled (i.e., it *can happen*).

Can anyone explain which of these two interpretations is the correct one?

#uart
3 REPLIES 3
zzdz2
Associate II
Posted on July 04, 2013 at 14:11

If I follow it correctly it returns SET when two bits are set TXE in SR and TXEIE in CR1.

It seems the only way to check if the interrupt has occurred.
Posted on July 04, 2013 at 14:39

USART_GetITStatus() gets the flagging from USARTx->SR, and masks that with if the bits are actually enabled.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sidney
Associate II
Posted on July 04, 2013 at 16:03

> If I follow it correctly it returns SET when two bits are set TXE in SR and TXEIE in CR1.

Yes, on second inspection that appears to be what it does: anding the appropriate bits from the SR and the appropriate CR{1|2|3}.

This means that the documented behavior (''Checks whether the specified USART interrupt has occurred or not'') is not quite correct.

For example, writing to DR just before executing ''USART_GetITStatus()''  will make it return false, even if we're actually handling the TXE interrupt.