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

UART on 18F66K80

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nik.the.greek



Joined: 12 Jul 2012
Posts: 4

View user's profile Send private message

UART on 18F66K80
PostPosted: Thu Jul 12, 2012 3:48 pm     Reply with quote

Hello there.

I am about to lose the rest of my hair here. If anyone could help I'd really appreciate it.

I am using the 18F66K80 with CCS. I am quite new to this compiler. I am used to Hi-Tech C.

Anyway, I can't get the UART timing right. I have a 16MHz crystal with PLL disabled (just to eliminate this as a cause of timing problems).

My setup is:
Code:

#use delay(clock=16000000)
#use RS232(BAUD=9600, PARITY=N, BITS=8, STOP=1, STREAM=COM_A, ERRORS, UART1)
#fuses NOMCLR
#fuses NOPLLEN
#fuses HSM

I am telling the compiler my clock is 16MHz
I want a 9600,8,n,1 set up on the UART and I want to use the hardware peripheral.

MCLR is disabled
PLL is disabled
And the oscillator is an external crystal with medium power drive.

The peripheral does initialise but nothing intelligible is coming out of it.

I can't think of what else I can change so hopefully one of you guys can point out something very silly that I am doing wrong.

Many thanks.

Nik
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 12, 2012 4:11 pm     Reply with quote

I compiled the program below with vs. 4.134 and it worked fine. I ran
the PIC on a PicDem2-Plus board and programmed it with an ICD3.
It displayed this in the TeraTerm window:
Quote:

Hello World

Test program:
(This is not your exact PIC, but it's in the same family).
Code:

#include <18F46K80.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT
#use delay(clock=16M)
#use rs232(baud=9600, UART1, ERRORS)

//======================================
void main(void)
{

printf("Hello World \n\r");

while(1);
}
 

If it doesn't work for you, then post your CCS compiler version. It's
a 4-digit number (only) in this format x.xxx and it's given at the top of
the .LST file, which will be in your project directory after a successful
compilation. Example of version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo
nik.the.greek



Joined: 12 Jul 2012
Posts: 4

View user's profile Send private message

PostPosted: Thu Jul 12, 2012 5:06 pm     Reply with quote

Thanks for the feedback PCM programmer.

My compiler version is 4.129.

I will have another stab at it tomorrow. If still no success I'm going to remove the RS232 converter and see if I can get anything at logic level.

Thanks again.

Nik
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Fri Jul 13, 2012 1:12 am     Reply with quote

Generally, I would change the order of things to match that shown by PCM_Programmer. So always start with the PIC's definition file, then fuses, then clock, (then select lines on chip's with programmable peripherals), then RS232. Otherwise, if you load things like #include files before the clock definition (for example), you won't get correct functionality for anything using the clock in the stuff in these files. Similarly with delays.

Now, as a general comment, the 'nature' of the 'nothing intelligible' might help us. If (for instance), you set it up to produce a 16 character text message, and you are seeing 8 characters, then it says 'double clock rate somewhere'.
My 'guess' would be that in fact the oscillator is not running correctly, so the chip is implementing 'fail safe', and dropping back to the internal clock. This is then defaulting a different speed (8MHz is the default for this)....

Remember you can see exactly what patterns the compiler is loading to the fuses, by looking at the end of the .lst file.

If your crystal is slightly low in gain, HSM, might be having problems starting (16MHz, is right on the 'max' for this mode). Might be worth trying HSH. Try with NOFCMEN as well. If it doesn't work at all, it shows 'where' the problem is.

So, something like:
Code:

#include <18F66K80.h>
#fuses HSH,NOWDT,PUT,BROWNOUT,NOFCMEN,NOIESO,NOMCLR,NOPLLEN
#use delay(clock=16M)
#use rs232(baud=9600, UART1, ERRORS)

//======================================
void main(void) {
   delay_ms(15); //on some hardware allow time for the RS232 charge
   //pump to get going.
   printf("Hello World \n\r");

   while(1);
}


Best Wishes
nik.the.greek



Joined: 12 Jul 2012
Posts: 4

View user's profile Send private message

PostPosted: Fri Jul 13, 2012 7:24 am     Reply with quote

Tttelmah,

Thanks for the feedback. I have just double checked my RS232 hardware an it is working OK.

I considered the oscillator not working correctly but have found it be be a rock steady 16MHz signal. I had already tried HSH with the same results.

I will try your coding suggestions and let you know.

Many thanks.

Nik
nik.the.greek



Joined: 12 Jul 2012
Posts: 4

View user's profile Send private message

PostPosted: Fri Jul 13, 2012 7:32 am     Reply with quote

Ttelmah, PCM programmer,

Thank you for the help. I changed the order of the definitions at the beginning of the file as suggested and it worked! Who knew..

I really appreciate it.


Nik
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