| View previous topic :: View next topic |
| Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19967
|
|
Posted: Wed Oct 29, 2025 10:27 am |
|
|
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
|
|
Posted: Wed Oct 29, 2025 6:47 pm |
|
|
| 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 |
|
 |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 476 Location: Bali
|
|
Posted: Wed Oct 29, 2025 8:55 pm |
|
|
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
|
|
Posted: Wed Oct 29, 2025 11:49 pm |
|
|
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
|
|
Posted: Thu Oct 30, 2025 2:13 am |
|
|
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
|
|
Posted: Thu Oct 30, 2025 2:23 am |
|
|
Thank you very much Ttelmah
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
|
|
Posted: Thu Oct 30, 2025 7:03 am |
|
|
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
|
|
Posted: Thu Oct 30, 2025 4:52 pm |
|
|
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
|
|
Posted: Thu Oct 30, 2025 6:52 pm |
|
|
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
|
|
Posted: Fri Oct 31, 2025 5:40 am |
|
|
| 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
|
|
Posted: Fri Oct 31, 2025 9:11 am |
|
|
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....  |
|
 |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 476 Location: Bali
|
|
Posted: Sat Nov 01, 2025 2:43 am |
|
|
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 |
|
 |
|