2007-03-20 08:18 AM
2011-05-17 12:39 AM
Hi All
I recently had a look at the UART code in the ST library. I was having a problem with UART interrupts (see last forum posting) and wanted to check that I was clearing UART interrupts correctly. This is the code in the library to do it [91x_uart.c, * 05/24/2006 : Version 1.1]: -void UART_ClearITPendingBit(UART_TypeDef* UARTx, u16 UART_IT) { /* Clear the specified interrupt */ UARTx->ICR &= UART_IT; } My code was effectively doing UARTx->ICR = UART_IT; So I read the data sheet, which states „Write ‚1’ clears the Rx interrupt. Write ‚0’ has no effect“ and I checked reading the 'read-only' register to see whether it maybe read 0xffffffff. It reads 0x00000000. Therefore I don't understand how this code works (or can work). It can only ever write 0 to the register, which has no effect. Does the code somehow work or has it never been tested? Best regards Mark Butcher www.uTasker.com2011-05-17 12:39 AM
Change that line of source code to:
UARTx->ICR = UART_IT; The given library implementation is wrong since you'll always be performing an AND with one zero operand, effectively doing nothing more than wasting processor time. This allows a 1 to be written to the register, which clears that interrupt flag.2011-05-17 12:39 AM
Hi
The code I use is already doing this correctly but the question is - if the library code doesn't do it correctly then the interrupt routine will never reset the flag - this means that any project using the code will hang as soon as one character is sent or received - this begs the question as to whether the code has been verified in a project since it can not work (?) The reason why I have interest is because there is also code for Ethernet and USB available and I have been told by someone who wants us to do some work with these that all code is available and so we essentially have nothing to do. But if the UART code can not work, can the Ethernet and USB code be relied upon? What has actually been tested? regards Mark