Wednesday, 15 June 2011

Using USART Receiver interrupts in Atmega32


In my previous blog post here, i discussed about the basic usage of USART communication. But to make the program more efficient we make use of interrupts. Using interrupts the micro-controller doesn't need to poll the USART Rx continuously.The incoming data stream causes the micro-controller to be interrupted from its current routine and serve the incoming interrupt by going to its ISR address.

 So in case of the previous blog the micro-controller can perform actions according to the received data from USART. But in cases were we want the micro-controller to perform tasks independent of the USART data then we use interrupts so that the actions of USART Rx data can be performed in the interrupt service routine and the some other task independent of USART can be performed in the infinite while loop.

The same header file usart.h used previously is reproduced. For deatils of its impementation refer to the previous blog here.

For implementing interrupts we need to import the header file avr/interrupts.h which contains the ISR addresses of respective ave chips.For USART receiver interrupt the isr function is defined as ISR(USART_RXC_vect){}. The logic for the actions against USART Rx interrupt has to be coded in this function.


In this example the incoming character is echoed back to the terminal. Nothing great in that but its a start.











No comments:

Post a Comment

Popular Posts