Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Sending data in AVR's USART Receive interrupt . Available or not ?

Status
Not open for further replies.

nimaaa

Newbie level 6
Joined
Jul 25, 2014
Messages
14
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
Tehran, Iran, Iran
Activity points
122
Sending data in AVR's USART Receiver interrupt . Available or not ?

Hi

I need my MC to consume low power and I prefer no to put my code in any permanent While Loop.
so I want to write all of my code with Interrupts.

Now I need to give the user a response when MC receives a data .

Is it available to send data or character in USART receiver interrupt ?
If not , Do you have any alternative solution to solve my issue ?
How can I get out of receiver Interrupt to active another interrupt ? ( for example : MC's timer interrupt )

please consider my code, simple. like this :


Code:
// USART Receiver interrupt service routine


interrupt [USART_RXC] void usart_rx_isr(void)
{

char data;
data=UDR;
if ( data == 'A' )
putchar('B') ;

}

Thanks In Advance : )
 
Last edited:

which compiler are you using? how is the 'putchar' implementation? bear in mind that you need to implement also an interrupt-driven putchar (because most implementations blocks the execution until it has the UDR buffer available).

if your code is as simple as that, I think you can replace it by:
Code:
// USART Receiver interrupt service routine


interrupt [USART_RXC] void usart_rx_isr(void)
{

char data;
data=UDR;
if ( data == 'A' )
    UDR ='B' ; //this will initiate the Transmission, if data is not 'A' it will never execute,
   //please don't use putchar never ever more in the rest of your code, or a collision could happen...

}

but this will only work with simple 8-bit responses to 8-bit data request... if you want to send more complex response (like a string or bigger number (16,32 bit)) you need to implement some Transmission buffer and use a interrupt-driven 'putchar'

about your other question, you can always 'enable' any interrupt in your main code, or even inside an interrupt, it doesn't matter, but enabling them doesn't execute them. Also, remember that any pending interrupt is executed after exiting the current interrupt...

if your code requires a higher priority interrupt ( as the timer interrupt executing even when the uart interrupt is been executed), you can look for information about Non-Blocking interrupts for your compiler (in avr-gcc it's ISR_NOBLOCK), in that way, you can set the uart interrupt as non-block and the timer interrupt could trigger inside it...

if you want to execute the same tasks from one interrupt (like the timer tasks) from another interrupt (like inside the uart interrupt) it's better if you make a re-entrant procedure that can be called from both interrupts... if both interrupts routines are exactly the same you can look for aliases like the ISR_ALIASOF from avr-gcc's...
 
  • Like
Reactions: nimaaa

    nimaaa

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top