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

18f6620 strange corrupt UART behaviour

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



Joined: 06 Jun 2004
Posts: 1
Location: UK

View user's profile Send private message Visit poster's website MSN Messenger ICQ Number

18f6620 strange corrupt UART behaviour
PostPosted: Sun Jun 06, 2004 3:52 am     Reply with quote

Hi,

I’m having a few problems converting code to run from a 18f258 to a 18f6620 and wondered if anyone could help.

On the 18f6620 if I use the following everything is ok:

Code:
while (1) {
   ch = fgetc(com1);
   fputc(com2);
}


However if I try the following on it I get around 80% of the message output ok, but some of the characters are corrupted:

Code:
while (1) {
   buffer[i++] = fgetc(com1);
   if (ch == 13) {
      fprintf(com2,”%s”, buffer);
   }
}


What I see being output varies every time, sometimes its 100% perfect but that’s about 1 in 10 (although totally random). On the 18f258 everything is ok with both methods above.

An example of this problem is if I had the ascii character 1 (0x31) being output sometimes the first half of the byte gets sent and then the second so I see two bytes 0x3 and 0x1 as individual bytes on the output, not a single transmitted character.

Am I doing something stupid? All other operations work ok on the pic it’s just the sending from a stored array that I’m having a problem with. If I exchange fprintf for putc and output character by character I still see the same random problems (I've even tried delaying each character being sent but no joy).

I’m confident the comms settings are ok on the PIC and receiving hardware, but this looks like some form of timing problem to me but I’m not sure what to investigate. I’m using a MAX202 as the transceiver for both uarts and version 3.190 of CCS. My fuses and uses are as below:

Code:
#include <18F6620.h>
#device adc=8
#use delay(clock=10000000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, NOBROWNOUT, BORV25, NOPUT, NOCPD, NOSTVREN, NODEBUG,  NOWRT, NOWRTD, NOCPB, NOEBTRB, NOEBTR, NOWRTC, NOWRTB, NOLVP
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, stream=com1)
#use rs232(baud=9600,parity=N,xmit=PIN_G1,rcv=PIN_G2,bits=8, stream=com2)


If anyone has any help or guidance to the source of the problem I would be really grateful as this is driving me up the wall.

Thanks,

Lee
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Sun Jun 06, 2004 4:32 am     Reply with quote

Two things to mention:

1. The format of fputc() is value = fputc(cdata, stream). You need to specify both the stream name and the data to be sent out.

2. The "%s" in the fprintf() expects a null-terminated string. Yours is not. That may be the reason for the random results you are seeing.
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