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 support@ccsinfo.com

rs232 sends 3 characters only

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



Joined: 08 Jan 2011
Posts: 18

View user's profile Send private message

rs232 sends 3 characters only
PostPosted: Mon Jan 10, 2011 7:35 am     Reply with quote

Since I couldnt manage sending strings and converting them to numerical value,I decided to start it from the rough.
I used siow in csc s.I have pic16f877.
Following is the pic code :
Code:

#include <16F877A.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7)
#org 0x1F00,0x1FFF {}
#opt 9

void main()
{
int flag=1;
char ch;
char text[5];
output_high(PIN_B5);
*text="gotit";
while(1)
{

output_high(PIN_D3); //this is LED (on)
puts(text);
delay_ms(250);
ch=getc();
delay_ms(10);
putc(ch);

output_low(PIN_D3);  // this is LED (off)
delay_ms(500);


}



Now, I open siow (serial port monitorl) and write 'a' as ascii and send.It is OK,pic sends me back 'agotit' and LED is on-off.
I write 'ab' and press send,pic sends me back 'agotit' and in a new line 'bgotit'.Its ok.
I write 'abc' and send.The result is again as expected.
BUT, when I write abcd,pic only sends three lines containing 'agotit' 'bgotit' 'cgotit'.It doesnt recognize 4th character.What may be the reason for this?
Sorry for long question,thanks for your answers.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Jan 10, 2011 7:55 am     Reply with quote

It looks like you are overflowing the UART buffer. The buffer only holds 2 characters. The first character 'a' is read and immediately processed, but you have some long delays in your processing loop. The next 2 characters come in and are buffered. When the 4th character arrives the UART buffer overflows and generates an error. You don't have any code to handel a UART error.

You should start by looking at the ERRORS option of the #use RS232 command and seeing if it is applicable to your code.
_________________
The search for better is endless. Instead simply find very good and get the job done.
bigfish



Joined: 08 Jan 2011
Posts: 18

View user's profile Send private message

PostPosted: Mon Jan 10, 2011 8:22 am     Reply with quote

Hi, thanks for the reply.

Where can I find its options? Also can't we just empty the buffer after I gather the second character, using built in function?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Jan 10, 2011 9:46 am     Reply with quote

The help entry for use RS232 gives a list of the options and a short description of the ERRORS option.

Of course it is best to avoid errors by handling the characters as they come in. Either handle them in the main code, which means no long delays or printing while characters are coming, or use interrupts with a circular buffer to store as many characters as you need (and have RAM for) until you can deal with them.
_________________
The search for better is endless. Instead simply find very good and get the job done.
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