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

Spurious Characters using RS232 with PLL

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



Joined: 27 Apr 2007
Posts: 14
Location: UK

View user's profile Send private message

Spurious Characters using RS232 with PLL
PostPosted: Sat May 25, 2013 1:28 pm     Reply with quote

My first posting - hope it makes sense.

I have an 18F87K22 running minimal code to try to sort out system clock problems by viewing J0 and J1 (which are toggled using timer_0 and timer_1 ISRs) using a DSO.

I have had system clock success using a 14.7456MHz external crystals and using #fuses HSH, (or HSM) PLLEN and #use delay(clock=58982400) but am getting corrupt/spurious characters in the RS232 stream viewed on an external Crystalfontz serial LCD display or a 2nd PC running Realterm or CCS Serial Input/Output Monitor. This occurs at all Baud rates I have tried from 4800 to 19200. The USART is the internal hardware one #use rs232 (baud=19200, xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8, STOP=1)

If I remove the PLL (NOPLLEN) and just use the raw crystal clock frequency (#use delay(clock=1475600)) the RS232 is perfect at all Baud rates so I presume I'm doing something wrong with the PLL.

Please can someone point me in the right direction.
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Sat May 25, 2013 1:46 pm     Reply with quote

Unfortunately, there is an erratum on this chip for the EUSART.
The TXIF bit doesn't get set reliably to say the byte has been sent. It sometimes gets set prematurely.
They document it as only applying at high baud rates, but in fact it applies at high clock rates.
Rewrite the putc function with:
Code:

#bit TRMT=getenv("BIT:TRMT")

void your_putc(int8 ch)
{
   while(!TRMT);
   putc(ch);
}

Use this instead of putc;

It is very annoying.

Best Wishes
duncangray



Joined: 27 Apr 2007
Posts: 14
Location: UK

View user's profile Send private message

PostPosted: Sat May 25, 2013 3:02 pm     Reply with quote

Ttelmah.

Thank you for the rapid and knowledgeable response and, as a result I have looked at the Errata in the hope that I could swap to the K90. Unfortunately it has the same problem but both are referred to as problems using synchronous transmission. Is RS232 not asynchronous and, if so is the fault still present?

My code uses printf() so I would need to change the library function for printf() to substitute your_putc() in printf(). Please can you tell me how to find printf.

Time to dig out the K&R again!

Thanks, Duncan
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Sun May 26, 2013 1:37 am     Reply with quote

Remember you can use printf with any output function, like:

printf(your_putc,"what you want to print");

It is one of the 'good things' in CCS. Smile

It's 'odd'. I came across it on this chip family, when trying to use interrupt driven TX. It just would not work reliably. Ended up using a timer interrupt just slightly slower than the UART byte time, and sending one character in this, from a buffer. Told Microchip, and they referred to the erratum. It appears that it applies to the whole UART, when the clock rate is above perhaps 30MHzish.....
Obviously the timer approach is safe and reliable, but slightly slows the transmission.

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