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.

[SOLVED] Interrupt driven USART Initialization in AVR

Status
Not open for further replies.

sgreen

Junior Member level 3
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"
 

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
 


@sgreen

Please refer to the datasheet of the AVR you are using.
See about UCSRB, UCSRA, UBRRL, UBRRH registers in datasheet.
The resiters have to be set to enable serial interrupts and to set the baudrate, start and stop bits of data frame. 8bit/9bit data setting, etc.

Why we have to choose what?

See this http://deans-avr-tutorials.googlecode.com/svn/trunk/InterruptUSART/Output/InterruptUSART.pdf

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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top