CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

USART Transmit Problems

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rhaguiuda



Joined: 05 Sep 2007
Posts: 46
Location: Londrina - Brazil

View user's profile Send private message

USART Transmit Problems
PostPosted: Wed Jan 28, 2009 7:17 am     Reply with quote

Hi.

This is not the first time I've seen this bug. Don't know why it happens.
When trying to make a simple program that sends a sequence through USART:

Code:

   printf ("Teste");
   putc(0x7E);


If I use this sequence, the computer shows only some words. PIC never sends all chars. Usually stops at "t".

The only way to receive the complete sequence of chars is putting a delay of some time after the code, just like this.

Code:

   printf ("Teste");
   putc(0x7E);
   delay_ms (100);


I'm using a PIC18F876, with a 4 MHz crystal. PCM 4.084.

Fuses:
Code:

#fuses XT, PUT, NOWDT, NOLVP
#use delay(oscillator=4M)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,errors)


Does anyone know about this problem?
_________________
Give a man a fish and you'll feed him for a day. Teach a man to fish, and you'll feed him for a lifetime.
Guest








PostPosted: Wed Jan 28, 2009 9:28 am     Reply with quote

You don't show the rest of the program, but I'd guess there is a simple key thing missing.
Code:

void main(void) {
   //setup code here to initialise the chip peripherals as needed

   printf ("Teste");
   putc(0x7E);
}

This _will_lose the last two characters.

Code:

void main(void) {
   //setup code here to initialise the chip peripherals as needed

   printf ("Teste");
   putc(0x7E);
   while(TRUE);
}

This _won't_.

The key is understanding, that when you write a program like this on a PC, there is a complete operating system running 'outside' the program. When the program terminates, it can leave the OS to 'get on' with housekeeping outside. However written on the PIC, _there is nothing but the code you write_. Now in the first case, there are two characters in the hardware transmit buffer, when the program terminates. The processor then basically stops (it actually goes to sleep), so these characters are lost. In the second, the code _remains running_, so the characters are sent.
What you are doing, is 'running off the end' of the code. Don't. You should stay inside the program at all times, and write code to handle everything.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group