I2C 18F47K40

Moderator: Benj

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8412
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2401 times
Been thanked: 3434 times
Contact:

I2C 18F47K40

Postby medelec35 » Mon Mar 25, 2019 3:42 pm

Software I2C is working as expected.
With channel 1 or channel 2 I2C does not work & no commands after I2C are executed.
The microcontroller is brought to a halt.
Attachments
I2C test.fcfx
(122.38 KiB) Downloaded 24 times
These users thanked the author medelec35 for the post (total 2):
LeighM (Tue Mar 26, 2019 9:00 am) • Benj (Tue Mar 26, 2019 6:11 pm)
Rating: 10.53%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Benj
Matrix Staff
Posts: 14295
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4394 times
Been thanked: 4123 times
Contact:

Re: I2C 18F47K40

Postby Benj » Tue Mar 26, 2019 6:11 pm

Hi Martin,

Leigh's got one of these device on order so we can investigate for you.
These users thanked the author Benj for the post:
medelec35 (Tue Mar 26, 2019 6:49 pm)
Rating: 5.26%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8412
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2401 times
Been thanked: 3434 times
Contact:

Re: I2C 18F47K40

Postby medelec35 » Wed Mar 27, 2019 8:47 am

Thanks Ben & Leigh.
When you test the device, can you also test ADC with internal OSC at 64MHz please as it appears to be wandering all over the place.

Thank you.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: I2C 18F47K40

Postby LeighM » Tue Apr 09, 2019 2:11 pm

Hi Martin,
I think I have the I2C fixed now.
Please try the attached updated CAL file. (C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\PIC)
Thanks
Leigh
Attachments
PIC_CAL_I2C.c
(29.06 KiB) Downloaded 32 times
These users thanked the author LeighM for the post:
medelec35 (Tue Apr 09, 2019 2:32 pm)
Rating: 5.26%
 

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: I2C 18F47K40

Postby LeighM » Tue Apr 09, 2019 2:26 pm

Hi Martin,
I've just done a quick ADC test with default settings and it looks OK.
Do you want to post an example?
Thanks
Leigh

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8412
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2401 times
Been thanked: 3434 times
Contact:

Re: I2C 18F47K40

Postby medelec35 » Tue Apr 09, 2019 2:32 pm

LeighM wrote:'ve just done a quick ADC test with default settings and it looks OK.

Hi Leigh,
Was that running the chip with internal osc @ 64 MHz?
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: I2C 18F47K40

Postby LeighM » Tue Apr 09, 2019 2:38 pm

Just checked and that was running with OSCFRQ = 0x07;
as your previous program, so that will be 48MHz, not 64

Edit: Yes you are correct, it's a mess at 64MHz
Although in the datasheet there is note reference (3) against that setting, cannot find the relevant note though!

Edit 2: Just changed the ADC conversion speed to Fosc/16 and all is well again. (@64MHz)

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8412
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2401 times
Been thanked: 3434 times
Contact:

Re: I2C 18F47K40

Postby medelec35 » Tue Apr 09, 2019 2:55 pm

LeighM wrote:Just checked and that was running with OSCFRQ = 0x07;
Yes I was running osc for I2C at 48MHz.
What to change it to 64MHz when ADC was working.
as your previous program, so that will be 48MHz, not 64

LeighM wrote:Just changed the ADC conversion speed to Fosc/16 and all is well again. (@64MHz)

Brilliant thanks Leigh for your help on both I2C and ADC.
Will do some testing and let you know how I got on.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8412
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2401 times
Been thanked: 3434 times
Contact:

Re: I2C 18F47K40

Postby medelec35 » Tue Apr 09, 2019 2:55 pm

LeighM wrote:Just checked and that was running with OSCFRQ = 0x07;
as your previous program, so that will be 48MHz, not 64

Yes I was running osc for I2C at 48MHz.
What to change it to 64MHz when ADC was working.
LeighM wrote:Just changed the ADC conversion speed to Fosc/16 and all is well again. (@64MHz)

Brilliant thanks Leigh for your help on both I2C and ADC.
Will do some testing and let you know how I got on.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8412
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2401 times
Been thanked: 3434 times
Contact:

Re: I2C 18F47K40

Postby medelec35 » Wed Apr 10, 2019 8:38 am

Hi Leigh,
Tried I2C with:
channel2 (SDA = RD0, SCL = RD1) - Working.
channel1 (SDA = RC0, SCL = RC1) - Not Working.
Software (SDA = RC0, SCL = RC1) - Working.
Using internal osc @ 48MHz
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: I2C 18F47K40

Postby LeighM » Wed Apr 10, 2019 9:29 am

Thanks Martin,
Interesting, I used channel 1 and port C OK, but not pins 0 and 1
One thing I did add in code at start of program was a setting of the port to open drain.
ODCONC = 0xff;
I then forgot to remove it to see if it was really needed.
I'm out of the office at the moment so will investigate further tomorrow.
Leigh
These users thanked the author LeighM for the post:
medelec35 (Wed Apr 10, 2019 9:45 am)
Rating: 5.26%
 

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: I2C 18F47K40

Postby LeighM » Thu Apr 11, 2019 9:14 am

Hi Martin,
Update: It does not require setting of the port to open drain.
But, weirdly, I can get it to work OK on every pin on port C except 0 and 1!
Hmm, does it need further investigation or a read of the silicon errata :roll:
I'll be back
These users thanked the author LeighM for the post:
medelec35 (Thu Apr 11, 2019 9:23 am)
Rating: 5.26%
 

User avatar
LeighM
Matrix Staff
Posts: 1888
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 445 times
Been thanked: 640 times
Contact:

Re: I2C 18F47K40

Postby LeighM » Thu Apr 11, 2019 10:17 am

I suspect this might be something to do with the secondary oscillator
but haven't got my head round all the relevant datasheet sections yet
These users thanked the author LeighM for the post:
medelec35 (Thu Apr 11, 2019 12:56 pm)
Rating: 5.26%
 

User avatar
Benj
Matrix Staff
Posts: 14295
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4394 times
Been thanked: 4123 times
Contact:

Re: I2C 18F47K40

Postby Benj » Thu Apr 11, 2019 5:30 pm

I've poked my head into the datasheet but I've not spotted anything useful so far.
These users thanked the author Benj for the post:
medelec35 (Fri Apr 12, 2019 11:44 am)
Rating: 5.26%
 

patrick schoon
Posts: 52
Joined: Mon Aug 23, 2010 7:07 pm
Location: Amsterdam
Has thanked: 4 times
Been thanked: 9 times
Contact:

Re: I2C 18F47K40

Postby patrick schoon » Sun May 05, 2019 3:56 pm

Hi Guys,

I experiance the same problem with a PIC16F15356.

Software I2C is working but Ch1 and Ch2 are not.
FC8.1.1.11


Regards,

PS