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

rs232, H4, 40 MHz -> not working

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



Joined: 18 Mar 2009
Posts: 38

View user's profile Send private message

rs232, H4, 40 MHz -> not working
PostPosted: Sat Apr 28, 2012 2:21 pm     Reply with quote

all is in the subject :

I am using a 18f2525 with an external crystal of 10 MHz.
When I do not use the H4 fuse, rs232 is going well at any baud rate up to 115200 baud.
If I try to run the chip at 40 MHz, the RS232 is messed up.

What is wrong ?

Thanks for you help


PCWHD 4.065

Code:

#include <18f2525.h>
#device *=16            // This enables use of all RAM.
#define FOSC 40007000  // increase if the autonomous clock is too slow
#fuses NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, hs, //H4 //,NOMCLR,
//#fuses WDT4096, NOPROTECT, NOBROWNOUT, NOPUT, NOLVP, DEBUG,
#use delay(clock=FOSC)
#include "flexlcd416.c"
#include "stdlib.h"
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7,ERRORS))

char const line [80] = "-------------------------------------------------------------------------------";

void main() {

  delay_ms(1000);
  lcd_init();
  printf("\r\n%s\r\nDCF77 Clock  JLD(c) version 1.2 : "__date__"\r\n%s\r\n",line,line);
  lcd_gotoxy(1,3);
  printf(lcd_putc,"    logger  " ); 


   while (TRUE) {

                 
      printf("\n\rhell!");
        delay_ms(1000);

      printf("\n\rbye!");
        delay_ms(1000);
       
   }
}
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Sun Apr 29, 2012 6:16 am     Reply with quote

Code:
#define FOSC 40007000  // increase if the autonomous clock is too slow
dynamitron



Joined: 18 Mar 2009
Posts: 38

View user's profile Send private message

PostPosted: Sun Apr 29, 2012 6:22 am     Reply with quote

yes I know....
But the 7000 are there 'cause I tried to play around with the frequency value to see if the fact that it is high it could cause uncertainties in the division factors down to the baud rate.
And I had no success...
Ttelmah



Joined: 11 Mar 2010
Posts: 19482

View user's profile Send private message

PostPosted: Sun Apr 29, 2012 7:04 am     Reply with quote

What you post, has HS selected, so the chip will run at 10MHz. Of course it won't work....
Hopefully just a typo, but it doesn't give 'confidence'.
What compiler version?.

There are two ways of enabling the PLL with this chip. So, try:
(a couple of comments inline).
Code:

#include <18f2525.h>
//#device *=16            // This enables use of all RAM.
//No it doesn't - this is _not_ needed or wanted with a PIC18.....

#define FOSC 40000000 
#fuses NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, H4 //,NOMCLR,
#use delay(clock=FOSC)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7,ERRORS))
//Always put this in front of the includes. Otherwise things involving
//serial I/O, won't work properly.

#include "flexlcd416.c"
#include "stdlib.h"



Code:

#include <18f2525.h>

#define FOSC 40000000 
#fuses NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, HS //,NOMCLR,
#use delay(clock=FOSC)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7,ERRORS))
//Always put this in front of the includes. Otherwise things involving
//serial I/O, won't work properly.

#include "flexlcd416.c"
#include "stdlib.h"
void main() {
    setup_oscillator(OSC_PLL_ON);

//etc..

I note also you have the debug fuse shown but remmed out in one line - remember, that the PLL fuse _does not change the oscillator_, until a power on reset is performed. So if operating with a debugger, you have to change the fuse, then reset the board, or the system will keep running without the PLL - this may be your problem.

Best Wishes
dynamitron



Joined: 18 Mar 2009
Posts: 38

View user's profile Send private message

PostPosted: Sun Apr 29, 2012 1:12 pm     Reply with quote

Thanks Ttelmah for your hints !!
Unfortunately, none of them are successful, I still experience the same behavior.
I should maybe find another quartz, let say 8 MHz and test if the code works at 32 MHz.
Any other suggestion is welcomed.
dynamitron



Joined: 18 Mar 2009
Posts: 38

View user's profile Send private message

PostPosted: Tue May 08, 2012 3:43 pm     Reply with quote

I make an up of this message because I have no solution yet Crying or Very sad Question
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue May 08, 2012 4:43 pm     Reply with quote

Post the code version you have now and that you think should work. It could be just a small typo.

Quote:
PCWHD 4.065
This is another problem you will run into. The compiler was very unstable for the first year of v4.0xx releases. Only around v4.075 the compiler started to work for most basic programs and it took to about 4.090 to get usable.
Save everybody a lot of time and upgrade to a newer version.
anglab



Joined: 27 Sep 2010
Posts: 4

View user's profile Send private message

PostPosted: Tue May 08, 2012 5:07 pm     Reply with quote

May be the problem is order of declaration.

#fuses H4, HS //work
//#fuses HS, H4 - not work
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 08, 2012 5:11 pm     Reply with quote

I don't have your PIC, but I have one that is in the same family (same
data sheet). I installed the PIC on my PicDem2-Plus board, along with
a 10 MHz crystal. I also installed compiler vs. 4.065. I then loaded
TeraTerm and set it for 115200 baud. I compiled the simple test
program shown below and ran it. It worked fine. I get this output in
the TeraTerm window on my PC:
Quote:

Hello World, this is 115200 baud.
Hello World, this is 115200 baud.
Hello World, this is 115200 baud.
Hello World, this is 115200 baud.
Hello World, this is 115200 baud.
Hello World, this is 115200 baud.
Hello World, this is 115200 baud.
Hello World, this is 115200 baud.

Test program:
Code:

#include <18F4620.h>
#fuses H4,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=40M)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

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

while(1)
  {
   printf("Hello World, this is 115200 baud. \n\r");
   delay_ms(500);
  }

}
dynamitron



Joined: 18 Mar 2009
Posts: 38

View user's profile Send private message

PostPosted: Wed May 09, 2012 1:10 pm     Reply with quote

okay rs232 woks now at 40 MHz. I remove the "HS" fuse and just let the H4.

Frankly, I am lost : when should I use HS ?

In addition, the onewire routines found somewhere else on this forum do not work anymore at 40 MHz. I measured the operating frequency and find that is was not exactly 10 MHz but 10.000382 MHz. Could that be the problem ?
jeremiah



Joined: 20 Jul 2010
Posts: 1343

View user's profile Send private message

PostPosted: Wed May 09, 2012 1:33 pm     Reply with quote

If you go to the view menu bar in CCS and look at the valid fuses for your chip, you will notice that both H4 and HS are options for the same fuse. So you can't use both, you use one or the other. HS is for the high speed oscillator and H4 is for the high speed oscillator + PLL(x4). That's probably why the order mattered for you. The compiler probably took the first one as the one for that FUSE setting and ignored the other.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 09, 2012 1:48 pm     Reply with quote

Quote:
the onewire routines found somewhere else on this forum do not work anymore at 40 MHz.

Always post a link to referenced code. We are not mind-readers.
dynamitron



Joined: 18 Mar 2009
Posts: 38

View user's profile Send private message

PostPosted: Thu May 10, 2012 12:36 pm     Reply with quote

This is the link to this very nice code :

http://www.ccsinfo.com/forum/viewtopic.php?t=19255
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