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

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



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PIC16F1847 wont work on crystal oscilator (with I2C)
PostPosted: Wed Feb 07, 2024 1:19 am     Reply with quote

PIC16F1847 wont work on crystal oscilator (with I2C)
CCS PCM C Compiler, Version 5.062, 31220
The below code works with internal oscilator at 32Mhz
Reads data from CMPS14
Code:
   if(I2CstartF==1)
   {
      I2CstartF=0;//ready for next session
         i2c_start();
        i2c_write(0xC0);//CMPS14 address with write
      i2c_write(0x01);//CMPS14 heading address
         i2c_start();//restart for read
         i2c_write(0xC1);//CMPS14 address with read~
      HDG8bitI2C = i2c_read();//8 bit heading
      HDGH8bitI2C = i2c_read();//16 bit heading high
      HDGL8bitI2C = i2c_read();//16 bit heading low
      PITCH8bitI2C = i2c_read();//PITCH +/-90 degree
         ROLL8bitI2C = i2c_read(0);//last read with NACK; ROLL +/- 90 degree
         i2c_stop();
      I2CdataReadyF=1;
   }

The fuses setting:

Code:
#include <16F1847.h>
#device ADC=10
//#use delay(clock=32MHz,crystal=8MHz)      //crystal oscillator
#use delay(internal=32M)      //internal oscilator
#FUSES NOWDT                      //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 I/O
#use rs232(baud=1200,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8,stream=PORT1,errors)//EAGLE0FCU1847 PCB
#use I2C(MASTER, SLOW=100000, I2C1, STREAM=I2CPORT)//I2C1 hardware used

If I change the fuses to crystal oscilator, the PIC wont work
Code:
#include <16F1847.h>
#device ADC=10
#use delay(clock=32MHz,crystal=8MHz)      //crystal oscillator
//#use delay(internal=32M)      //internal oscilator
#FUSES NOWDT                      //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 I/O
#use rs232(baud=1200,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8,stream=PORT1,errors)//EAGLE0FCU1847 PCB
#use I2C(MASTER, SLOW=100000, I2C1, STREAM=I2CPORT)//I2C1 hardware used

If I outcomment the I2C loop, the PIC works correct on crytal oscilator

I made the tests on PCB not with simulator
I have a led toggles every 500ms and serial communication to the PC terminal
On crystal oscilator the led don't toggle and the serial communication wont work also

In the LST file the fuses setting are correct for both cases

I have no problem working with internal oscilator but I would like to understand why, what is the problem.

Best wishes
Joe
temtronic



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

View user's profile Send private message

PostPosted: Wed Feb 07, 2024 6:42 am     Reply with quote

OK, I'm thinking that the MSSP and clk share the same pin ??

Need to check the datasheet, but that PIC might have 'alternate pin functions' ? NOT 'PPS', an earlier version of it though...
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Wed Feb 07, 2024 6:56 am     Reply with quote

Hi Temtronic
Thank you for the answer

The rs232 is set xmit=PIN_B5 and rcv=PIN_B2
The I2C is set SDA1=pin B1 and SCL1=pin B4
I am not using MSSP, using I2C

So I don't understand why wont work on crystal oscillator but works on internal RC oscillator
What is the difference?

Best wishes
Joe
temtronic



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

View user's profile Send private message

PostPosted: Wed Feb 07, 2024 7:40 am     Reply with quote

Curious and waiting for 2nd pot of java to be made.....I downloaded the datasheet. My hunch was right.

Both SPI and I2C use the MSSP peripheral.....there isn't a separate I2C only perpiheral. Some 'newer' PICs have that,but not this one.

If you look at TABLE #1,page 7 you'll see that BOTH MSSP and clk use the same pin RA6 and YOU have to program the 'APFCON' register as you need.
Page 120 shows the register and which bits do what.....
hope this helps, cause my coffee is READY !!!
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Wed Feb 07, 2024 8:35 am     Reply with quote

Hi Temtronic

I was thinking that CCS doing that for me:
Code:
#use I2C(MASTER, SLOW=100000, I2C1, STREAM=I2CPORT)//I2C1 hardware used


I know that SSP and I2C have the same hardware. can't use both in the same time

How it explains that the program works on internal RC but not on crystal oscillator?

Best wishes
Joe
temtronic



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

View user's profile Send private message

PostPosted: Wed Feb 07, 2024 8:45 am     Reply with quote

hmm...
On crystal oscilator the led don't toggle and the serial communication wont work also

what value caps do you have with the crystal ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19238

View user's profile Send private message

PostPosted: Wed Feb 07, 2024 8:56 am     Reply with quote

What pins are you actually using????.
Your software I2C setup uses B2/B5. B2 & B5 are I2C2, not I2C1.
I2C1 uses B1 & B4. Might explain why it doesn't work!.......

Also what version is the chip (18pin PDIP?). If so, what pins are you putting
the crystal on (15 & 16)?. What loading capacitors and lead lengths?.

Also, comment, you do not have to set the clock fuses at all. The
#use delay setting does these for you automatically.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Thu Feb 08, 2024 5:58 am     Reply with quote

Hi Ttelmah and Temtronic

Thank you for the answers

I am using pin B1 SDA1 and pin B4 SCL1 (according to the data sheet)
I am using pin B2 as RX and pin B5 as TX for serial communication
The chip is 18 pin PDIP
The capacitors are 22 pF lead lengths 5.08mm
Using LED, toggles every 500ms

As I wrote before, on internal RC at 32MHz verything works 100%
On crystal oscillator (8MHz with PLL enabled) the program won't work
If I outcomment the I2C loop, all works 100%, but I need the I2C to read the CMPS14
The LST shows the fuses are correct

Thank you for the advice regarding the fuses.
I have them because I prepare myself the list of the fuses not to forget something.
Quote:
Also, comment, you do not have to set the clock fuses at all. The
#use delay setting does these for you automatically.


Best wishes
Joe
temtronic



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

View user's profile Send private message

PostPosted: Thu Feb 08, 2024 6:21 am     Reply with quote

OK, time to take a step back.

Please cut/compile/test/post the simple '1Hz LED flashing program
well 2 really

1st using internal osc
2nd using external xtal/cap

there has to be something 'odd' going on but it's not obvious so having just the LED flash gives us all a solid base to build on.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Thu Feb 08, 2024 8:28 am     Reply with quote

Hi Temtronic

No reason to do that
1. without the I2C loop the led toggles every 500ms an the serial com works fine on the crystal oscillator
2. on the internal RC everything works fine including the I2C

Best wishes
Joe
Ttelmah



Joined: 11 Mar 2010
Posts: 19238

View user's profile Send private message

PostPosted: Thu Feb 08, 2024 8:55 am     Reply with quote

Looking through the listing, the only big difference, is when you select
the INT_RC mode, it always runs with the PLL enabled in software.
There is an erratum on that chip for the startup of the HS oscillator.
It makes no change at all to the I2C code etc..
temtronic



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

View user's profile Send private message

PostPosted: Thu Feb 08, 2024 9:57 am     Reply with quote

well I'm confused.... though looking at the code...

he has #use delay(...) before the FUSES

maybe this is somehow causing the problem ???

it is odd that the PIC blinks LED using the xtal when I2C is commented out

I'd like to see a small program that does this....easier for my 70 year old grey(gray) cells to ponder.
Ttelmah



Joined: 11 Mar 2010
Posts: 19238

View user's profile Send private message

PostPosted: Fri Feb 09, 2024 7:01 am     Reply with quote

I'm suspicious that something else is happening when the I2C transaction
occurs. Possibly something elsewhere in the code triggered by the
I2CdataReadyF being set. I've tried a basic test with just the I2C
call shown, reading from a hardware I2C simulator, and it works OK with
either oscillator. I will have to try again with his compiler (I noticed this
tests the interrupt flag rather than the data ready bit).
Are there any calls elsewhere in the code to setup_oscillator?. Given the
hardware bug in the HS configuration, these could hang the chip.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Fri Feb 09, 2024 9:30 pm     Reply with quote

Hi Temtronic

The reason of #use delay(...) before the FUSES is because in the past I had problems with this PIC with the internal RC when the #use delay(...) was before #use rs232

Ttelmah advised me to put it where it is now and from then I had no problem with it.

Best wishes
Joe
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Fri Feb 09, 2024 9:38 pm     Reply with quote

Hi Ttelmah

PLL enabled in software also with the crystal oscillator

Don't have any other place in the software that the oscillator is setup

Will make in the weekend a short program just with the LED and the I2C and will see what happening.
I will post the program.

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 1, 2, 3  Next
Page 1 of 3

 
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