Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Problem with US0 and main program
PostPosted: Wed Sep 21, 2011 12:52 pm 
Offline

Joined: Wed Sep 21, 2011 12:46 pm
Posts: 2
Hi everybody, i have one question for you.

I have to read a byte with the usart and save this value in a variable for control the main program. I am receiving this byte correctly with the usart but in the main if i do this, the program never works:

int main(){
unsigned char status=0x00;
. . .

while(1){
status=read_status();
switch(status){
case A: ...
case B: ...
....
}
}
}

if I add a printf at the end of the while the program works OK, can someone explain me why the printf makes the program works ?
Thanks everybody. Regards.


Top
 Profile  
 
 Post subject: Re: Problem with US0 and main program
PostPosted: Thu Sep 22, 2011 10:33 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
You don't specify a compiler, but I'd guess you either have a buggy compiler, issues with optimization, or you're not defining peripheral registers as volatile properly.

Without knowing more about the tool chain, compiler settings, linker scripts, etc. it could be any number of things.

Look at the assembler code that's being generated for your application, it might be more enlightening about what's really going wrong.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: chasmopolitan and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: