 |
 |
| View previous topic :: View next topic |
| Author |
Message |
dyeatman
Joined: 06 Sep 2003 Posts: 1969 Location: Norman, OK
|
|
Posted: Sat Feb 17, 2024 1:20 pm |
|
|
The published specs are:
| Quote: | Power - 3.3v-5v 18mA Typ.
Resolution - 0.1 Degree
Accuracy - 5°
Signal levels - 3.3v, 5v tolerant
I2C mode - up to 400khz
Serial mode - 9600, 19200, 38400 baud |
I take that to mean it tolerates 5V input but puts out 3.3V signals. _________________ Google and Forum Search are some of your best tools!!!! |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9597 Location: Greensville,Ontario
|
|
Posted: Sat Feb 17, 2024 1:44 pm |
|
|
Yes, I read the electrical specs of the BNO080.... Vout is 90% of VDDIO which means .9* 3.63, so Vhigh is 3.3 volts.
What's unclear is does the 'module' contain additional 'logic level' conversion chip ? Maybe it does ? need to see schematic of the module...
If using PIC's I2C pins, Vhi is .7* VDD so .7*5=3.5
Close, but not 100% .Maybe sensor puts out 3.4, PIC is OK with 3.4, so may work but I wouldn't trust it. Change room temperature, turn on an LED, oopsy... 'it doesn't work'.....
Now that PIC will work at 3 volts,32MHz so that's how I'd design/build the unit. |
|
 |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 476 Location: Bali
|
|
Posted: Sun Feb 18, 2024 12:49 am |
|
|
From the data sheet:
| Quote: | Power supply requirements are flexible, you can feed between 3.3 - 5v and the module draws a nominal 18mA
of current. A choice of serial or I2C interfaces can be used for communication. |
And no any "ops, don't work". It works flowless. Tested in - 5 degree celsius and + 50 degree celsius
I have 2.2K resistors on SCL and SDA
Also the topic is why works on internal RC oscillator but won't work on crystal oscillator
Best wishes
Joe |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9597 Location: Greensville,Ontario
|
|
Posted: Sun Feb 18, 2024 6:50 am |
|
|
hmm.. since Mr T proved the PIC works fine with intrc and xtal ,using EEPROM and I2C scanner program and you say the compass operates fine.......
....perhaps there's a 'setup' requirement of the compass chip that's met with the internal RC and not the xtal/caps clock ?
maybe code so...
PIC gets power
setup serial and I2C
delay 500ms
blink an LED
reset the I2C bus
send 'reset' the compass
delay 100ms
blink an LED
then execute main()
I suspect the compass is getting 'locked' due to some timing issue or invalid set of pulses to it. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19989
|
|
Posted: Sun Feb 18, 2024 8:42 am |
|
|
Can I suggest you add SMBUS to the I2C setup. This reduces the voltage
the I2C will accept as a high. Safer for a 3.3v device. I was using a 5v
EEPROM for my test.
Also, I'm scared by one erratum on your chip. It has a problem that can
result in the chip not waking with a crystal, if the crystal is slow to start.
Tell us what the actual crystal you have is, how it is wired, and what
loading capacitors you are using. It may be that your crystal is one that
takes too long to start and hence your chip does not run with your crystal.
Any chance you have a different one you could try?. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9597 Location: Greensville,Ontario
|
|
Posted: Sun Feb 18, 2024 9:20 am |
|
|
read some more stuff of the net and the BNO080 device in the compass module does have some 'power up' specs
The OP does say xtal does the 1Hz LED pgm, so on the surface not a xtal problem.
Since the only hardware change is the PIC clock, my gut says 'timing'. Maybe the compass module gets confused,so that's why I suggested a proper I2C reset,wait a bit, then access the compass. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19989
|
|
Posted: Sun Feb 18, 2024 12:15 pm |
|
|
I have to ask a couple of thingsL
Why not just use software I2C?. You are only running at 100KHz, software
will do that easily. Also using software I2C, you can just use pins with
TTL input levels, and it won't then mind 3.3v signalling.
If you must use hardware, then try using I2C2. It would tell us a lot
about what is actually happening.
Also what is the decoupling on the chip?. The crystal is more fussy about
decoupling than the internal oscillator. I'm wondering if when the chip tries
to signal on the I2C is is causing a glitch on the supply. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9597 Location: Greensville,Ontario
|
|
Posted: Sun Feb 18, 2024 1:16 pm |
|
|
I'm pretty sure that PIC will run at 3v3, so simple test...run at 3v3 and see what happens ??
I don't know about the 'startup' time difference between using the internal RC vs a real xtal/caps but.... |
|
 |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 476 Location: Bali
|
|
Posted: Mon Feb 19, 2024 4:18 am |
|
|
Hi Ttelmah
I am working with this PIC16F1847 for many years but first time with I2C.
I used PIC18F26K22 for the CMPS14 with I2C also I2C for EEPROM to other PIC's (with your help in the past) always 5V with 2.2K resistors on SDA and SCL
I will try to answer one by one:
I have 3 PCB's, 3 PIC16F1847, all have the same problem with I2C.
To use I2C2 will have to make new PCB. Will check if I can use hardware UART on other pins if I use I2C2.
I have other functions working with interrupts, this why I don't want to use the software I2C.
The decoupling on all the chips are 100nF capacitors, good quality.
I check the supply voltage with oscilloscop, found no glich on the power supply
I have powerup timer enabled.
Can you write me how to add SMBUS? never done it
Hi Temtronic
I had no any issue with the CMPS14 get confused. It gives always correct data.
I am waiting 100ms between asking for new message
Best wishes
Joe |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19989
|
|
Posted: Mon Feb 19, 2024 7:36 am |
|
|
On I2C, use of interrupts for other interfaces makes no difference. Interrupts
are only used for I2C receive. For transmit, there is no advantage to using
the hardware, except if you are using speeds, above those the software can
do. Since I2C is a master timed interface, if there is a pause in the
transmission, while an interrupt is serviced, it makes no difference at all.
#use I2C(MASTER, SLOW=100000, I2C1, SMBUS, STREAM=I2CPORT) |
|
 |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 476 Location: Bali
|
|
Posted: Mon Feb 19, 2024 8:13 am |
|
|
Thank you for the prompt answer Ttelmah
I am out of office, will test again tomorrow
Best wishes
Joe |
|
 |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 476 Location: Bali
|
|
Posted: Wed Feb 21, 2024 12:06 am |
|
|
Hi
I added to the I2C
| Code: | | #use I2C(MASTER, SLOW=100000, I2C1,SMBUS, STREAM=I2CPORT) |
It didn't help
Best wishes
Joe |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19989
|
|
Posted: Wed Feb 21, 2024 2:29 am |
|
|
and what happens when you use software I2C?.
Mys suspicion is that something about the sequencing of the signals on
your board is resulting in the I2C peripheral getting hung when running
off the crystal. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9597 Location: Greensville,Ontario
|
|
Posted: Wed Feb 21, 2024 6:19 pm |
|
|
hmm...
another test to try...
add a 2nd I2C device, run the I2C Scanner program. does it return BOTH devices ? |
|
 |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 476 Location: Bali
|
| I2C wont work on crystal oscillator PIC16F1847 |
Posted: Wed Oct 29, 2025 2:04 am |
|
|
Back after a very long break (health)
If someone still interested in the subject, the problem persists.
CCS PCM C Compiler, Version 5.062, 31220 29-Oct-25 15:20
| Code: | /////////////////////////////////////////////////////////////////////
//Project: FCP47T0
//Program: FCP47T0.c
//Microcontroller: PIC16F1847
//Start date: 2025/10/29
//Last updte: 2025/10/29
//Program closed:
/////////////////////////////////////////////////////////////////////
//TX messages sent consecutively; 1200 BPS
//I2C reads every 100ms from CMPS14, pitch, roll & heading
//ADC checks battery volts LiFePO4*4
//on internal oscillator works OK
//on crystal orcillator works scom only; LED don't toggle
//ADC outcommented, works scom only
//I2CstartF=1 every 100ms outcommented, scom works; LED don't toggle
//setup_wdt(WDT_128MS); & restart_wdt(); outcommented
//I2C without delays; I2CstartF=1 not outcommented, scom works, LED don't toggle
//I2C with delays; I2CstartF=1 not outcommented, scom works, LED don't toggle;
//Back to internal oscillator: LED toggle; scom works; I2C works with & without delays
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
#include <FCP47T0.h>
#include "FCP47T0VR.h"
#include "FCP47T0AD.h"
#include "FCP47T0FC.h"
#include "FCP47T0SC.h"
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
#ZERO_RAM
//main program///////////////////////////////////////////////////////
void main()
{
setup_adc_ports(sAN1|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//65.5 ms overflow
set_adc_channel (1);
output_low (PIN_B3);//not used in this project
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TBE);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(TRUE)
{
FUNCTIONS();
ADC();
}
}
|
| Code: | /////////////////////////////////////////////////////////////////////
//Project: FCP47T0
//Program: FCP47T0.h
//Microcontroller: PIC16F1847
/////////////////////////////////////////////////////////////////////
#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 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, SMBUS, STREAM=I2CPORT)//I2C1 hardware used
///////////////////////////////////////////////////////////////////// |
| Code: | /////////////////////////////////////////////////////////////////////
//Project: FCP47T0
//Program: FCP47T0VR.h
//Microcontroller: PIC16F1847
/////////////////////////////////////////////////////////////////////
//#define trigger PIN_A0
//RA1 AN1;Analogue reading LiFePO4*4 cells
//#define PIN_A2
#define LED PIN_A3//toggle every 500ms////EAGLE0FCU1847 PCB
//#define PIN_A4
//RA5 MCLR~
//RA6 8MHz
//RA7 8MHz
//#define PIN_B0
//#define I2C SDA PIN_B1
//#define RX PIN_RB2
//#define PIN_B3
//#define I2C SCL PIN_B4
//#define TX PIN_RB5
//#define PIN_B6
//#define PIN_B7
//VARIABLES//////////////////////////////////////////////////////////
short timer20msincF=0;
int LEDcounter=0;
/////////////////////////////////////////////////////////////////////
//I2C VARIABLE///////////////////////////////////////////////////////
short I2CstartF=0;
int I2Ccounter=0;
short I2CdataReadyF=0;
//SCOM RX////////////////////////////////////////////////////////////
int scomrx1w0=0;
//SCOM TX////////////////////////////////////////////////////////////
int scomtx1words;
int scomtx1wchs;
/////////////////////////////////////////////////////////////////////
long HDG8bitI2C=0;
long HDGH8bitI2C=0;
long HDGL8bitI2C=0;
long PITCH8bitI2C=0;
long ROLL8bitI2C=0;
long HDG8bit=0x80;
long PITCH8bit=0x80;
long ROLL8bit=0x80;
int DIGITAL0rpt=0xF0;
//ADC VARIABLES//////////////////////////////////////////////////////
int BATT8bit=0;
long BATTvolts=0;
long BATTvolts0=0;
long BATTvolts1=0;
long BATTvolts2=0;
long BATTvolts3=0;
long BATTvolts4=0;
long BATTvolts5=0;
long BATTvolts6=0;
long BATTvolts7=0;
long BATTvolts8=0;
long BATTvolts9=0;
long BATTvolts10=0;
long BATTvolts11=0;
long BATTvolts12=0;
long BATTvolts13=0;
long BATTvolts14=0;
long BATTvolts15=0;
long BATTvoltsAVG=0;
long BATTvoltsAVG0=0;
long BATTvoltsAVG1=0;
long BATTvoltsAVG01=0;
///////////////////////////////////////////////////////////////////// |
| Code: | /////////////////////////////////////////////////////////////////////
//Project: FCP47T0
//Program: FCP47T0AD.h
//Microcontroller: PIC16F1847
/////////////////////////////////////////////////////////////////////
//analog reading is 16 bit FIFO filterd in addition to the capacitor
//filter on the PCB
/////////////////////////////////////////////////////////////////////
void ADC(void)
{
/////////////////////////////////////////////////////////////////////
//AN1 Analogue LiFePO4*4 cells 100% charged, rest 13.6V; charging 14.6
/////////////////////////////////////////////////////////////////////
BATTvolts=read_adc(ADC_START_AND_READ);
set_adc_channel (1);
BATTvolts15=BATTvolts14;//shifting 16 ADC - FIFO
BATTvolts14=BATTvolts13;
BATTvolts13=BATTvolts12;
BATTvolts12=BATTvolts11;
BATTvolts11=BATTvolts10;
BATTvolts10=BATTvolts9;
BATTvolts9=BATTvolts8;
BATTvolts8=BATTvolts7;
BATTvolts7=BATTvolts6;
BATTvolts6=BATTvolts5;
BATTvolts5=BATTvolts4;
BATTvolts4=BATTvolts3;
BATTvolts3=BATTvolts2;
BATTvolts2=BATTvolts1;
BATTvolts1=BATTvolts0;
BATTvolts0=BATTvolts;
BATTvoltsAVG0=(BATTvolts7+BATTvolts6+BATTvolts5+BATTvolts4+BATTvolts3+BATTvolts2+BATTvolts1+BATTvolts0)/8;//avaraging 8.75us
BATTvoltsAVG1=(BATTvolts15+BATTvolts14+BATTvolts13+BATTvolts12+BATTvolts11+BATTvolts10+BATTvolts9+BATTvolts8)/8;//avaraging 8.75us
BATTvoltsAVG01=(BATTvoltsAVG0+BATTvoltsAVG1)/2;//1.375us
BATTvoltsAVG=BATTvoltsAVG01*64;//left justified; 2.0us
BATT8bit=MAKE8(BATTvoltsAVG,1);//0.25us
delay_cycles(1);
}
///////////////////////////////////////////////////////////////////// |
| Code: | /////////////////////////////////////////////////////////////////////
//Project: FCP47T0
//Program: FCP47T0FC.h
//Microcontroller: PIC16F1847
/////////////////////////////////////////////////////////////////////
#int_TIMER1
void TIMER1_isr(void)
{
set_timer1(45564);//to interrupt after
timer20msincF=1;
}
/////////////////////////////////////////////////////////////////////
//FUNCTIONS - not interrupt driven
/////////////////////////////////////////////////////////////////////
void FUNCTIONS(void)
{
if(timer20msincF==1)
{
timer20msincF=0;//not to enter loop before next 20ms
LEDcounter++;
I2Ccounter++;
}
//toggle LED/////////////////////////////////////////////////////////
if(LEDcounter>=25)//500ms
{
LEDcounter=0;//to count for the next toggle
output_toggle(LED);
}
//start I2C every 100ms/////////////////////////////////////////////
if(I2Ccounter>=5)
{
I2Ccounter=0;
I2CstartF=1;
}
/////////////////////////////////////////////////////////////////////
//I2C read from CMPS14 when request from FCP
//CMPS14 address 0xC0;8 bit HDG 0x01;16 bit HDGH 0x02;16 bit HDGL 0x03;
//PITCH 0x04; ROLL 0x05
/////////////////////////////////////////////////////////////////////
/*
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;
}
*/
if(I2CstartF==1)
{
I2CstartF=0;//ready for next session
i2c_start();
delay_us(5);
i2c_write(0xC0);//CMPS14 address with write
delay_us(5);
i2c_write(0x01);//CMPS14 heading address
delay_us(5);
i2c_start();//restart for read
delay_us(5);
i2c_write(0xC1);//CMPS14 address with read~
delay_us(5);
HDG8bitI2C = i2c_read();//8 bit heading
delay_us(5);
HDGH8bitI2C = i2c_read();//16 bit heading high
delay_us(5);
HDGL8bitI2C = i2c_read();//16 bit heading low
delay_us(5);
PITCH8bitI2C = i2c_read();//PITCH +/-90 degree
delay_us(5);
ROLL8bitI2C = i2c_read(0);//last read with NACK; ROLL +/- 90 degree
delay_us(5);
i2c_stop();
I2CdataReadyF=1;
}
/////////////////////////////////////////////////////////////////////
if(I2CdataReadyF==1)
{
I2CdataReadyF=0;
HDG8bit=HDG8bitI2C;
PITCH8bit=PITCH8bitI2C;
ROLL8bit=ROLL8bitI2C;
}
}
///////////////////////////////////////////////////////////////////// |
| Code: | /////////////////////////////////////////////////////////////////////
//Project: FCP47T0
//Program: FCP47T0SC.h
//Microcontroller: PIC16F1847
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
//serial com RX not used in this project
/////////////////////////////////////////////////////////////////////
#int_RDA
void RDA_isr(void)
{
scomrx1w0=fgetc(PORT1);
}
/////////////////////////////////////////////////////////////////////
//serial com TX
/////////////////////////////////////////////////////////////////////
#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(DIGITAL0rpt,PORT1);//DIGITAL rpt
scomtx1wchs=scomtx1wchs+DIGITAL0rpt;
scomtx1words++;
}
break;
case 3:
{
fputc(PITCH8bit,PORT1);//PITCH 8bit rpt
scomtx1wchs=scomtx1wchs+PITCH8bit;
scomtx1words++;
}
break;
case 4:
{
fputc(ROLL8bit,PORT1);//ROLL 8bit rpt
scomtx1wchs=scomtx1wchs+ROLL8bit;
scomtx1words++;
}
break;
case 5:
{
fputc(HDG8bit,PORT1);//Heading 8bit rpt
scomtx1wchs=scomtx1wchs+HDG8bit;
scomtx1words++;
}
break;
case 6:
{
fputc(BATT8bit,PORT1);//Battery 8bit rpt
scomtx1wchs=scomtx1wchs+BATT8bit;
scomtx1words++;
}
break;
case 7:
{
fputc(scomtx1wchs,PORT1);//calculated checksum LSB byte
scomtx1words=0;
}
break;
}
}
///////////////////////////////////////////////////////////////////// |
|
|
 |
|
|
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
|