<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>UART interrupt routine</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/28037/uart-interrupt-routine</link><description> 
hi guys, 

 
can i have some help regarding the given code below. 

 
in the code i am capable of using the interrupt based
receiving. 

 
but i have to tell how much byte i m sending. 

 
Now i wish whenever the data come it should go to IRQ
handler</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: UART interrupt routine</title><link>https://community.arm.com/thread/105581?ContentTypeID=1</link><pubDate>Mon, 19 Dec 2011 04:46:33 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1faeffb8-e45b-4203-bf38-e3f205d691df</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
You just can&amp;#39;t assume there are two characters in the FIFO, unless
you happen to know that it was a watermark interrupt and not a
timeout interrupt.&lt;/p&gt;

&lt;p&gt;
Remember that if you send a large message - larger than the FIFO
can handle - then the UART must generate multiple interrupts. The
first interrupt is likely to happen when there are two or more
characters in the FIFO (i.e. a FIFO watermark interrupt where the
interrupt happens to let you empty it before it overflows) but the
last interrupt may happen for a single byte. When you don&amp;#39;t get
enough characters to reach the FIFO watermark level, you will get a
last FIFO timeout interrupt, to let your code pick up the remaining
part of a transfer.&lt;/p&gt;

&lt;p&gt;
You can receive as big message as your buffer can handle - or even
larger in case you have a state machine that starts to consume data
on-the-fly.&lt;/p&gt;

&lt;p&gt;
But your interrupt code should contain something like:&lt;/p&gt;

&lt;pre&gt;
while (UART_GetFlagStatus(UART0,UART_FLAG_RxFIFOEmpty) != SET) {
    c = UART0-&amp;gt;DR;
    if (my_rx_buffer_full)
        my_rx_overflows++;
    else
        RxBuffer[InsertPos++] = c;
}
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
Your interrupt routine is of course free to look at received data to
figure out where a message starts/ends. But that is totally separate
from how the interrupt routine should check the status flags to
figure out if it can pick up more data or not.&lt;/p&gt;

&lt;p&gt;
It would be considered a bug in your program, if you can&amp;#39;t consume
data fast enough from your receive buffer, so the UART interrupt
handler gets a buffer overflow.&lt;/p&gt;

&lt;p&gt;
Another thing - you do not want the receive buffer to insert like
that. It&amp;#39;s way better to have a ring buffer, where one counter is
insert position (producer) and one counter is remove position
(consumer). Then you get the lucky situation that the interrupt only
modifies the insert (write) position, and the main program only
modifies the remove (read) position. The world is full of sample
implementations. Go for one where the buffer size is 2^n large and
where the two indices are allowed to use the full numeric range - it
has the advantage that you can have 0 to n characters in the buffer.
The variant that folds the indices when they reaches the full size of
the buffer can only store n-1 entries to avoid the duality that
rx-idx == tx-idx would happen both for a full or for an empty
buffer.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART interrupt routine</title><link>https://community.arm.com/thread/79850?ContentTypeID=1</link><pubDate>Mon, 19 Dec 2011 04:00:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d3a64865-d54c-4295-93fa-c301785caea8</guid><dc:creator>Saurabh Yadav</dc:creator><description>&lt;p&gt;&lt;p&gt;
&amp;gt;Thanks Westermark for paying attention&lt;/p&gt;

&lt;p&gt;
&amp;gt;I am using STR912FA.&lt;/p&gt;

&lt;p&gt;
&amp;gt;No. of bytes to be received is declared in first two
bytes.&lt;/p&gt;

&lt;p&gt;
&amp;gt;Actually for the assurance of receiving the correct no. of
bytes i used the above way of implementation.&lt;/p&gt;

&lt;p&gt;
&amp;gt;I have taken help from the examples given.&lt;/p&gt;

&lt;p&gt;
&amp;gt;Firstly I was using the below code but i was not able to
receive more than 255 bytes&lt;/p&gt;

&lt;pre&gt;
void UART0_IRQHandler(void)
{
if((UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET)&amp;amp;&amp;amp;(RxCounter &amp;lt; RxBufferSize))
            {
              RxBuffer[RxCounter++] = UART0-&amp;gt;DR;
            }

}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART interrupt routine</title><link>https://community.arm.com/thread/67130?ContentTypeID=1</link><pubDate>Mon, 19 Dec 2011 00:04:33 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:20c767ba-bbc9-4afd-8e7e-06ea13615c41</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
1) You forgot to mention what processor you have.&lt;/p&gt;

&lt;p&gt;
2) Why do you think you can pick up more than one byte from the
FIFO without first checking if there are more than one character in
the FIFO? You normally check for receive fifo non-empty and as long
as that condition you can pick up one more character.&lt;/p&gt;

&lt;p&gt;
Here, you pick up two characters - why?&lt;/p&gt;

&lt;pre&gt;
        RxBuffer[RxCounter++] = UART0-&amp;gt;DR;
        RxBuffer[RxCounter++] = UART0-&amp;gt;DR;
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>