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

PIC16F1847 wont work on crystal oscilator (with I2C)
Goto page Previous  1, 2, 3, 4
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19967

View user's profile Send private message

PostPosted: Wed Oct 29, 2025 10:27 am     Reply with quote

First thing to do, is get rid of a lot of your fuses:

Code:

#FUSES NOWDT                   //NO Watch Dog Timer
#FUSES PUT                      //Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPD                    //No EE protection
#FUSES BROWNOUT                 //Reset when brownout detected
//#FUSES ECH               //external clock
//#FUSES INTRC_IO                //internal oscillator
//#FUSES HS                  //crystal oscillator   
//#FUSES PLL                  //PLL enabled
//#FUSES NOCLKOUT                 //I/O function on OSC2 for internal oscillator & external clock
//#FUSES NOIESO                     //Internal External Switch Over mode disabled
//#FUSES NOFCMEN                    //Fail-safe clock monitor disabled
#FUSES NOWRT                    //Program memory not write protected
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES BORV25                   //Brownout reset at 2.5V
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for


Let the compiler set the clock fuses for you. With the crystal oscillator,
turning off the clock out, will stop the oscillator from working. That may well
be your whole problem. However also leave FCMEN enabled. That way if the
oscillator does not work, the unit will run, but at the wrong speed. Will
give a diagnostic if you have a problem with the actual oscillator.

Then do a really basic test with the crystal oscillator settings and verify
the clock is running at the right speed.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Wed Oct 29, 2025 6:47 pm     Reply with quote

Code:
#include <16F1847.h>
#device ADC=10
//#use delay(clock=32MHz,crystal=8MHz)      //crystal oscillator
#use delay(internal=32M)      //internal oscilator
#FUSES NOWDT                   //NO Watch Dog Timer
#FUSES PUT                      //Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPD                    //No EE protection
#FUSES BROWNOUT                 //Reset when brownout detected
//#FUSES ECH               //external clock
//#FUSES INTRC_IO                //internal oscillator
//#FUSES HS                  //crystal oscillator   
//#FUSES PLL                  //PLL enabled
//#FUSES NOCLKOUT                 //I/O function on OSC2 for internal oscillator & external clock
//#FUSES NOIESO                     //Internal External Switch Over mode disabled
//#FUSES NOFCMEN                    //Fail-safe clock monitor disabled
#FUSES FCMEN 
#FUSES NOWRT                    //Program memory not write protected
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES BORV25                   //Brownout reset at 2.5V
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for

#use rs232(baud=1200,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8,stream=PORT1,errors)
#use I2C(MASTER, SLOW=100000, I2C1, SMBUS, STREAM=I2CPORT)//I2C1 hardware used

Thank you for the prompt answer Ttelmah
I tested with internal oscillator and with crystal
Same as before
The serial communication works at the correct speed
On internal oscillator the led toggles every500ms.

I don't understan what you mean:
[quote]Let the compiler set the clock fuses for you
Quote:
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Wed Oct 29, 2025 8:55 pm     Reply with quote

Hi Ttelmah

You wrote in the past to try software I2C, maybe will solve the problem.
I never use software I2C.
Can you givw mw an example?

Best wishes
Joe
Ttelmah



Joined: 11 Mar 2010
Posts: 19967

View user's profile Send private message

PostPosted: Wed Oct 29, 2025 11:49 pm     Reply with quote

Just specify the pin numbers instead of selecting the I2C peripheral,
and add FORCE_SW to the setup line so it won't use the hardware on the
pins.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Thu Oct 30, 2025 2:13 am     Reply with quote

Thank you for the prompt answer Ttelmah
Code:
#use I2C(MASTER, SLOW=100000, SCL=PIN_B4,SDA=PIN_B1, SMBUS, FORCE_SW, STREAM=I2CPORT)//I2C software used

Is it OK?
Best wishes
Joe
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Thu Oct 30, 2025 2:23 am     Reply with quote

Thank you very much Ttelmah Smile
With software I2C works with both internal and extenal oscillator
Can you explain please why with software I2C works but not with the hardware?

Best wishes
Joe
temtronic



Joined: 01 Jul 2010
Posts: 9589
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Oct 30, 2025 7:03 am     Reply with quote

Hmm, software I2C is 'bit banged' and maybe(?) the hardware version is getting 'confused' somehow ? Maybe that PIC has a 'version' problem ??
It'd be interesting to know if your code, works on another type of PIC.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Thu Oct 30, 2025 4:52 pm     Reply with quote

Hi Temtronic

I stated in one of my previous posts on this topic.
Same program works fine on PIC18F26K22 (also on PIC18F25K22)
with hardware I2C.
Didn't tested the software I2C on otgher PIC.

Will try the software I2C with a much more complex program and will be back to report how it works.

Regarding version problem, I don't know. It may be PIC problem or the compiler problem.

Best wishes
Joe
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Thu Oct 30, 2025 6:52 pm     Reply with quote

Tested the software I2C with a more complex program, it works.
I have to check a lot of functions if they work corect, will report back.

Best wishes
Joe
temtronic



Joined: 01 Jul 2010
Posts: 9589
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Oct 31, 2025 5:40 am     Reply with quote

hmm, there may be a potential problem with using the software I2C, pretty sure interrupts will be disabled or at the least delayed ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19967

View user's profile Send private message

PostPosted: Fri Oct 31, 2025 9:11 am     Reply with quote

No, they shouldn't be. All that happens is when there is an interrupt the bit
is done slower.
I'd be suspicious of a hardware problem with the chip. None of the ones
listed in it's errata, should cause this, but it is slightly suspicious that there
are two affecting timer1, and three affecting the oscillator operation. Could
easily be that there is an unwanted timing behaviour on the I2C in slow
mode, when running from the crystal.... Sad
gjs_rsdi



Joined: 06 Feb 2006
Posts: 476
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sat Nov 01, 2025 2:43 am     Reply with quote

So yes, no problem with the software I2C in a much mre complex software, with many interrups, ADC, etc'

Thank you Ttelmah

Best wishes
Joe
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4
Page 4 of 4

 
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