cancel
Showing results for 
Search instead for 
Did you mean: 

Library UART code

m_j_butcher
Associate II
Posted on March 20, 2007 at 16:18

Library UART code

3 REPLIES 3
m_j_butcher
Associate II
Posted on May 17, 2011 at 09:39

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.com

sjackson
Associate II
Posted on May 17, 2011 at 09:39

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.

m_j_butcher
Associate II
Posted on May 17, 2011 at 09:39

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