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...