View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Sat Feb 10, 2024 3:42 am |
|
|
The point about delay after, rather than before, is if you have a compiler
that is not setting the fuses properly, or you want ot change from the
default fuses selected by the compiler. Put the delay before, and it's fuse
settings will be overridden by the fuses. Put the delay after and it'll
override all the clock fuse settings.
Honestly on a modern compiler I'd always put the delay after, and not do
any clock fuse settings. However 'historically' on compilers that had issues,
this was the fix.
In this case, his fuses match exactly what the compiler does, so this is
not the problem.
Will be really interested to hear how he gets on with the 'mini program'.
I won't be able to try this with his compiler till early next week. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Sat Feb 10, 2024 5:06 am |
|
|
Have you actually checked your oscillator is running at 32MHz when you
run in the internal oscillator mode?.
Do the flash an LED at 1 second test.
Realise I was letting the compiler setup the clock, not using your fuse
settings. Just tried compiling with your fuses, and doing it this way results
in the OSCON setting being removed from the initialisation code. This is
what programs the internal oscillator to 8MHz for use with the PLL. You
may actually be running a lot slower than you think in the INTRC mode. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Feb 10, 2024 6:54 am |
|
|
OK, kinda curious....
a simple test...
Does the I2S Scanner program from the code library here actually run with both Int RC and ext xtal clocks ?? if it does, then it points to some 'gremlin' in the OP's code
I've always run it whenever I had an I2C peripheral on a PIC. Like the '1Hz LED' program, it CONFIRMS the PIC hardware is working properly.
I suspect some 'gremlin' will finally appear after the 'process of elimination' is done |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Mon Feb 12, 2024 9:21 pm |
|
|
Hi Ttelmah
According to the LED toggling the PIC run at 32 MHz. No Problem there.
By the way, I moved to delay setting to the end of the fuses and the problem persist
Best wishes
Joe |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Wed Feb 14, 2024 4:02 am |
|
|
OK. I've just run a basic I2C test on this chip.
Attached a EEPROM, and used PCM_Programmer's I2C bus scanner code.
Setup the I2C using the setup from the post here, and tried with the internal
clock, and then with an 8MHz crystal. Clock setups as posted here. Used
the 5.062 compiler.
Both worked. Merrily found the chip.
Something else is going on.... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Feb 14, 2024 2:04 pm |
|
|
I had a feeling 'Mr T' would get 'bugged' by this, he'd grab a real PIC,cut the code and prove it does work.
tip of the hat to you sir !
I've got a messy snow/rain/ice storm coming tomorrow, busy trying to 'batten down the hatches' and stock up on water (have well,so if(no power) no water !!
Jay |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Fri Feb 16, 2024 6:49 am |
|
|
I am back with some delay
Below the test program:
Code: | /////////////////////////////////////////////////////////////////////
//Project: OSC47I2C
//Program: OSC47I2C.c
//Microcontroller: PIC16F1847
//Hardware 1847 PCB
//Start date: 2024/02/13
/////////////////////////////////////////////////////////////////////
#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 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)
#use I2C(MASTER, SLOW=100000, I2C1, STREAM=I2CPORT)//I2C1 hardware used;SDA PIN_B1;SCL PIN_B4
/////////////////////////////////////////////////////////////////////
#define LED PIN_A3//toggle every 500ms
/////////////////////////////////////////////////////////////////////
short timer20msincF,I2CstartF,I2CdataReadyF;
int LEDcounter,I2Ccounter,TX1counter;
int scomtx1words,scomtx1wchs;
int HDG8bit,HDGH8bit,HDGL8bit,PITCH8bit,ROLL8bit;
/////////////////////////////////////////////////////////////////////
#ZERO_RAM
/////////////////////////////////////////////////////////////////////
#int_TIMER1
void TIMER1_isr(void)
{
set_timer1(45536);
timer20msincF=1;
}
/////////////////////////////////////////////////////////////////////
void FUNCTIONS(void)
{
if(timer20msincF==1)
{
timer20msincF=0;//not to enter loop before next 20ms
LEDcounter++;
I2Ccounter++;
TX1counter++;
}
//toggle LED/////////////////////////////////////////////////////////
if(LEDcounter>=25)//500ms
{
LEDcounter=0;//to count for the next toggle
output_toggle(LED);
}
//start TX every 500ms///////////////////////////////////////////////
if(TX1counter>=25)
{
TX1counter=0;
enable_interrupts(INT_TBE);
}
//start I2C every 100ms//////////////////////////////////////////////
if(I2Ccounter>=5)
{
I2Ccounter=0;
I2CstartF=1;
}
/////////////////////////////////////////////////////////////////////
/*
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~
HDG8bit = i2c_read();//8 bit heading
HDGH8bit = i2c_read();//16 bit heading high
HDGL8bit = i2c_read();//16 bit heading low
PITCH8bit = i2c_read();//PITCH +/-90 degree
ROLL8bit = i2c_read(0);//last read with NACK; ROLL +/- 90 degree
i2c_stop();
I2CdataReadyF=1;
}
*/
}
/////////////////////////////////////////////////////////////////////
#int_RDA
void RDA_isr(void)
{
delay_us(1);
}
/////////////////////////////////////////////////////////////////////
#int_TBE
void TBE_isr(void)
{
switch(scomtx1words)
{
case 0:
{
fputc(0x55,PORT1);//sync byte 0x55
scomtx1wchs=0x55;
scomtx1words++;
}
break;
case 1:
{
fputc(0xAA,PORT1);//sync byte 0xAA
scomtx1wchs=0xFF;
scomtx1words++;
}
break;
case 2:
{
fputc(PITCH8bit,PORT1);
scomtx1wchs=scomtx1wchs+PITCH8bit;
scomtx1words++;
}
break;
case 3:
{
fputc(ROLL8bit,PORT1);
scomtx1wchs=scomtx1wchs+ROLL8bit;
scomtx1words++;
}
break;
case 4:
{
fputc(HDG8bit,PORT1);
scomtx1wchs=scomtx1wchs+HDG8bit;
scomtx1words++;
}
break;
case 5:
{
fputc(scomtx1wchs,PORT1);//calculated checksum LSB byte
scomtx1words=0;
disable_interrupts(INT_TBE);
}
break;
}
}
/////////////////////////////////////////////////////////////////////
void main()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//65.5 ms overflow
enable_interrupts(INT_TIMER1);
disable_interrupts(INT_TBE);
disable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(TRUE)
{
FUNCTIONS();
}
}
|
1. With I2C loop outcommented the LED toggles and the serial TX sends messages to the PC with crystal oscilator and with internal RC.
2. With I2C loop works on the internal RC
3. With I2C loop on crystal oscilator no serial TX to PC and LED doesn't toggle
4. Like always Ttelmah right, no need additional fuses settings for oscilator after #use delay
Best wishes
Joe |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Fri Feb 16, 2024 8:29 am |
|
|
There is a huge issue with what you post here.
You _MUST_ repeat _MUST_ always read the serial character in INT_RDA.
If you don't, and something results in this triggering, the processor
will become hung.
What happens is that the RDA interrupt cannot be cleared. It only clears
when the character is read.. Hence if something triggers the RDA interrupt
and you do not read, the interrupt will permanently re-trigger and everything
else will stop working.
This may be what is causing the problem.
Try again with a simple getc in the INT_RDA. Wondering if something in
your hardware is resulting in a spike being picked up on the UART receive
when the crystal is running. |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Fri Feb 16, 2024 8:40 am |
|
|
Thanks for the advice Ttelmah
I am out from work now, will try first thing in the morning
Best wishes
Joe |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Sat Feb 17, 2024 5:36 am |
|
|
Hi
Changed to:
Code: | #int_RDA
void RDA_isr(void)
{
scomrxw=fgetc(PORT1);
} |
The problem persist
Best wishes
Joe |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Feb 17, 2024 7:23 am |
|
|
comments
in the long posted program, you never enable INT_RDA.
have a look at the CCS supplied example program EX_SISR.C. It's a rough and ready program that does work. Incoming data is stored in a buffer,then main() processes that... |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Sat Feb 17, 2024 7:40 am |
|
|
Hi Temtronic
I am not using the RX of the serial communication so I am not enabling it
Best wishes
Joe |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Feb 17, 2024 8:43 am |
|
|
comments....
'CMPS14' seems to be some mag compass and I suspect it's really a 3 volt device. Module uses a BNO080 chip and that schematic shows it's 3v3.
If your PIC VDD is 5 volt, you'll have 'interface' problems
maybe ? your compass module does have proper 3 to 5, 5 to 3 conversion interface ??
also that device can be I2C, SPI or TTL Serial, so 'setup' is important. could be a bad solder connection selecting wrong 'interface'.
also confirm the compass address using the I2C scanner program.
debugging consists of eliminating things, one at a time.
and ,post your current complete test program. fresh eyes might see something ! |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Sat Feb 17, 2024 9:03 am |
|
|
Hi Temtronic
I am working with CMPS14 for more than 10 years now, always with 5v
Also worked with previous versions, CMPS11 and CMPS12
It works with uart TTL or I2C
The data sheet states: 3.3v - 5v
I posted the full program in this topic
Best wishes
Joe |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Feb 17, 2024 11:51 am |
|
|
I was curious as the interface chip(BNO080) shows it runs on 3v3. Maybe they have some 'magic' inside that allows for true 5V signalling ?? |
|
|
|