Embedded Freaks..

November 8, 2008

Bad Example of Interrupt Handling

Filed under: avr, programming-tips — Tags: , — kunilkuda @ 3:39 pm

In life, you need two examples: good one, and bad one. Here’s one of my bad design of interrupt handling.

The purpose of the firmware was to read a line (CR/LF terminated characters) from serial port, then parse it. Actually, I tried to port my simple AT handler from Java into C (AVR-GCC). It works, and as you can see, this program runs okay under x86 PC, but not under AVR with 8Mhz xtal.

Here’s the actual problem:

if (SerialLineReader_isReady()) {
printf("Line: %sn", SerialLineReader_readline());

The source code for x86 PC is trying to emulate AVR’s UART receive interrupt handler.

uint8_t data = UDR0;

if (SerialLineReader_isReady()) {

Testing it under PC, no problem has found. Under AVR, the problem will show up if you pump a lot of newline eventhough the data is below the READ_BUFFER_SIZE. The problem even worse if the newline is very short (2-10 characters). You will lose a lot of newline.

Well, I guess I have to redesign my work. Btw, here’s the link of my bad example.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: