[SOLVED] Interrupt driven USART Initialization in AVR

Status
Not open for further replies.

sgreen

Junior Member level 3
Joined
Nov 15, 2012
Messages
31
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,481
Hi,
"For interrupt driven USART operation, the Global Interrupt Flag should be cleared (and interrupts globally disabled) when doing the initialization." I don't understand the topics why it is necessary to clear interrupt flag. If anyone deal with this matter pls provide the clarification and if possible provide necessary links or pdf.
 

Well, The global interrupt flag should be enabled at the end of all initializations. Thats the rule. For AVR atmega this is an example....
UCSRB = 0x00;
UCSRA = 0x00;
UBRRL = 51; // 9600 baud rate;
UBRRH = 0x00;
UCSRB = 0xD8;

sei(); "global interrupt"
 


My quetion is why we have to choose this. If U know, provide reason in more detail
 



It is from ATmega32A datasheet page no.153 under the topics usart initialization. My question is why we have to clear global interrupt while initialization.@jayanth.devarayanadurga
 
Last edited:

The reason for that is because during initialization no interrupt will take place!!!! this is to make sure that there are no
ongoing transmissions or receiving during the period the registers are changed.
 
Reactions: sgreen

    sgreen

    Points: 2
    Helpful Answer Positive Rating
The reason for that is because during initialization no interrupt will take place!!!! this is to make sure that there are no
ongoing transmissions or receiving during the period the registers are changed.

Ok, I get the point. What kind of problems will happen if I use sei() before usart initialization?
 

You should not call sei() befor initializing the USART registers because USART will not be configured yet ie., baudrate etc will not be set. Using sei() before initialization might work (I don't know) but maybe if only the default settings of USART registers satisfy some UART Rx and Tx condition.
 
Reactions: sgreen

    sgreen

    Points: 2
    Helpful Answer Positive Rating
Well, we can call sei() before initialization, but the proper initialization of USART is not guaranteed. Because, if global interrupt is enabled and initialization is going on, it might be possible that the interrupt for USART will take place before we fully initialize it. That is the only reason. Its not that we cant do that, We can do that but performance is not guaranteed. I hope that is clear now.

- - - Updated - - -

Well anyways, What is the problem in doing initializing before sei()????????
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…