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

Baud rate wrong pic18f43k22

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 16, 2016 4:21 pm     Reply with quote

See if this program runs for you. I was able to make it work with an
18F46K22 (I don't have an 18F43K22, but it's the same PIC family).
I used MPLAB 8.92 and CCS vs. 5.065. I tested this with a PicDem2-Plus
board. It displays "Start: ", and then it echoes any keys that you type.
Make sure Local Echo is turned off on your terminal program. I used
TeraTerm for this test. I edited the PIC below to be the one you're using.
Also, I am compiling with MPLAB set for "Release" mode.
Code:

#include <18F43K22.h>
#fuses NOWDT,PUT,BROWNOUT
#use delay(internal=64M)
#use rs232(baud=9600, UART1, ERRORS)

//======================================
void main(void)
{
char c;

delay_ms(5);   // Allow time for the PLL to start-up

printf("\n\rStart: ");

while(TRUE)
  {
   c = getc();
   putc(c);
  }
 
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Sat Dec 17, 2016 3:36 am     Reply with quote

Realistically, the first thing you should do when you have any apparently 'clock' related problem, is step back to the old 'flash an led' test.
A literally sub ten line section of code, just setting up the oscillator and flashing an LED. So:

Code:

#include <18F43K22.h>
#use delay(clock=16M)

void main(void)
{
  while(TRUE)
  {
    output_toggle(PIN_A0);
    delay_ms(1000);
  }
}

Now if we build this, we can see straight away it runs wrong. The reason is simple. You are not selecting the internal oscillator, and it defaults to the external. This is not present, so it does a 'fail safe clock monitor' and switches to the internal oscillator at 1Mhz, and runs 16* slower than it should.

So we then use PCM_Programmer's basic fuse settings, and try:
Code:

#include <18F43K22.h>
#fuses NOWDT,PUT,BROWNOUT,NOLVP //prefer to specify NOLVP
#use delay(internal=16M)


Low and behold it starts flashing at the right rate.

Basically the reason the code is not working, is that you are not setting up the oscillator. It goes to a default that is 1/64th of the specified clock value (if you specify 64MHz), so gives 320baud when you select 19200 (not actually 300, but nearly).
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