Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Interrupt Service Routine for Atmega 16

2007-12-05 by David VanHorn

On Dec 4, 2007 8:59 PM, huiyangdoh <huiyangdoh@yahoo.com> wrote:
> I am trying to write code of interrupt service routine for Atmega 16.
> I got to know For UART, the ISP routine is just a line of code in
> enabling the UART RXD enable pin to wait for incoming data. For
> transmission, simply send the data and monitor the UART TXD ready pin
> for sending the next data.  Can anybody help me to figure out the
> code? Many thanks.

So much depends on how the rest of your app is structured.

Will you use TX and RX buffers?  TX byte by byte, and RX buffer?....
One reason that you probably didn't get much response on this, is that
there are a lot of ways to do this, and it's really up to you to
determine what's best for the rest of your application.


What >I< do, is to set up TX and RX circular buffers in SRAM, and ISRs
for TX and RX.
The TX ISR takes a char and puts it in the USART TX, IF there's a char
to be sent, and IF the handshaking pin (if used) or Xon/Xoff state (if
used) allows.  The RX isr takes a char from the USART, and puts it in
the buffer, checks the buffer full level, and (if used) sets hardware
handshake, or (if used) sets a flag to transmit an Xoff char.
A routine in the main loop checks the tx buffer for chars left by
other tasks, and if there are any, enables the UDRE int which is how I
send chars to the USART.

The buffers are "circular" buffers, each has a "head" and "tail"
pointer. In my implementations, I keep them < 255 bytes long which
makes the pointer math easy, and I also keep a count of the bytes in
the buffer, so I don't have to do math on the pointers to find out the
state.

My generic buffer routines require the caller to point to the buffer
in question using the Y register, and they will get a byte, put a
byte, or tell you how many bytes are in the buffer (by returning the
count byte)

This fits my apps well, but I almost always use a cooperative
multitasking approach.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.