PIC16F1825 Configuration Errors – I2C Master

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

I intend to use the I2C of the PIC16F1825 as Master to control the 12bit DAC MCP4725.
MCP4725: http://ww1.microchip.com/downloads/en/D ... 22039d.pdf
PIC16F1825: http://ww1.microchip.com/downloads/en/D ... 41440A.pdf

I followed next example, using 16F1825 instead of 16F877A and works just fine.
https://www.ccsinfo.com/forum/viewtopic.php?t=54863
I wanted to port it to FlowCode. I use FlowCode 6.

I used next FlowChart, but there is definitely something wrong with the settings, the clock first and later maybe something else:
The FlowChart is compiled without errors, but the I2C frequency/clock is not good.
16F825_I2C_DAC.fcfx
(6.77 KiB) Downloaded 348 times
Then to simplify the debugging, I used a simpler FlowChart, just to toggle on/off a pin and I got many errors when I compile:
16F825_osc_test.fcfx
(3.72 KiB) Downloaded 350 times
What is wrong here?
Why do I get so many errors when I compile that simple FlowChart? Do you get them too?
Do you have any suggestions about the settings that must be done (oscillator and something else) in order to make it run in FlowCode?

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

Re: PIC16F1825 Configuration Errors – I2C Master

Post by Benj »

Hello,

I've tried the osc_test program and it's compiling as expected for me in Flowcode 6.
Target folder: C:\Users\BenR\AppData\Local\Temp
Source name: C:\Users\BenR\AppData\Local\Temp\16F825_osc_test-1.fcfx
Title:
Description:
Device: PIC.16F.16F1825
Generated by: Flowcode v6.1.3.2
Date: Thursday, January 12, 2017 12:44:32
Users: 50
Registered to: Dev User
Licence key: XDKHX7
http://www.matrixtsl.com
Launching the compiler...
C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\boostc_16F.exe -v -t PIC16F1825 "16F825_osc_test-1.c"
Launching BoostC...
BoostC Optimizing C Compiler Version 7.20 (for PIC16 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2013 Pavel Baranov
Copyright(C) 2004-2013 David Hobday

Licensed to FlowCode User under Single user Pro License for 1 node(s)
Limitations: PIC12,PIC16 max code size:Unlimited, max RAM banks:Unlimited


16F825_osc_test-1.c
Starting preprocessor: "C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\pp.exe" 16F825_osc_test-1.c -i "C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\include" -d _PIC16F1825 -la -c2 -o 16F825_osc_test-1.pp -v -d _BOOSTC -d _PIC16 -d _PIC16x -d _CHAR_INDEX

..................
16F825_osc_test-1.c success

success
Completed BoostC compilation, return = 0

Launching the linker/assembler...
C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\boostlink_picmicro.exe -ld "C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\lib" libc_16F.lib rand_16F.lib float_16F.lib "16F825_osc_test-1.obj" -t PIC16F1825 -d "C:\Users\BenR\AppData\Local\Temp" -p "16F825_osc_test-1" -swcs 6 2
BoostLink Optimizing Linker Version 7.20
http://www.sourceboost.com
Copyright(C) 2004-2013 Pavel Baranov
Copyright(C) 2004-2013 David Hobday


Warning unreferenced functions removed:
FC_CAL_Port_In__x in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_IO.c
FC_CAL_Port_Out__x in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_IO.c
FC_CAL_Port_Out_DDR__x in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_IO.c
Wdt_Delay_S in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
Wdt_Delay_Ms in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINT_US in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINT_MS in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINTWDT_MS in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINT_S in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINTWDT_S in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_GETCHAR in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_GETLENGTH in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_MIDSTRING in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_LEFTSTRING in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_RIGHTSTRING in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOSTRING in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOSTRS16 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOSTRS32 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOSTRU16 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOSTRU32 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOLOWER in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOUPPER in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_COMPARE in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_FLOAT_TO_STRING in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_NUMBER_TO_HEX in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_STRING_TO_INT in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_STRING_TO_FLOAT in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_STRREV in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_STRMOV in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_SHEAD in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_SCOPY in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
isinf in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
pow in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
flt_round in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
flt_floor in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
flt_ceil in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
flt_atan in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
cos in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
sin in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
tan in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c

Building CASM file
Memory Usage Report
===================
RAM available:1024 bytes, used:35 bytes (3.5%), free:989 bytes (96.5%),
Heap size:336 bytes, Heap max single alloc:95 bytes
ROM available:8192 words, used:182 words (2.3%), free:8010 words (97.7%)



success
.

FINISHED
Can you post the error messages you're receiving.

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

Hi Benj,

I found the error regarding the small FlowChart with previous compiling error.
It was due to our server. The .fcfx file was placed in a folder on my desktop and the desktop is mirrored / redirected on the server for backup purpose. When I moved the FlowChart in another folder as C:\FlowCode Projects\ then I got no more compilation errors.
That may be understandable, but is in the same time strange, because the first FlowChart that I am really interested in, with I2C, was placed on the same folder on desktop and did not show any errors during compilation.
Do you still need me to upload the compilation logs?

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

Hi Benj,

For your further reference and debugging here is the log with error when the FlowChart was on de desktop folder, the one redirected through our server.
I marked with xxxxxxx the name and path of our server.
Target folder: C:\Users\xxxxxxx\Desktop\FLOWCO~1
Source name: C:\Users\xxxxxxx\Desktop\Flowcode components and examples\16F825_osc_test.fcfx
Title:
Description:
Device: PIC.16F.16F1825
Generated by: Flowcode v6.1.3.2
Date: Thursday, January 12, 2017 14:41:24
Users: 1
Registered to: Pro Motion
Licence key: 1HHER7
http://www.matrixtsl.com
Launching the compiler...
C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\boostc_16F.exe -v -t PIC16F1825 "16F825_osc_test.c"
Launching BoostC...
BoostC Optimizing C Compiler Version 7.20 (for PIC16 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2013 Pavel Baranov
Copyright(C) 2004-2013 David Hobday

Licensed to FlowCode User under Single user Pro License for 1 node(s)
Limitations: PIC12,PIC16 max code size:Unlimited, max RAM banks:Unlimited


16F825_osc_test.c
Starting preprocessor: "C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\pp.exe" 16F825_osc_test.c -i "C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\include" -d _PIC16F1825 -la -c2 -o 16F825_osc_test.pp -v -d _BOOSTC -d _PIC16 -d _PIC16x -d _CHAR_INDEX

...........
16F825_osc_test.c(86:3): error: unknown identifier 'FCP_TRIS_A'
16F825_osc_test.c(86:3): error: invalid operand 'FCP_TRIS_A'
16F825_osc_test.c(86:14): error: failed to generate expression
16F825_osc_test.c(86:35): error: unknown identifier 'FCP_PORT_A'
16F825_osc_test.c(86:35): error: invalid operand 'FCP_PORT_A'
16F825_osc_test.c(86:46): error: failed to generate expression
16F825_osc_test.c(86:35): internal error: failed to generate conditional expression
16F825_osc_test.c(86:32): error: failed to generate expression
16F825_osc_test.c(93:3): error: unknown identifier 'FCP_TRIS_A'
16F825_osc_test.c(93:3): error: invalid operand 'FCP_TRIS_A'
16F825_osc_test.c(93:14): error: failed to generate expression
16F825_osc_test.c(93:35): error: unknown identifier 'FCP_PORT_A'
16F825_osc_test.c(93:35): error: invalid operand 'FCP_PORT_A'
16F825_osc_test.c(93:46): error: failed to generate expression
16F825_osc_test.c(93:35): internal error: failed to generate conditional expression
16F825_osc_test.c(93:32): error: failed to generate expression
16F825_osc_test.c success

failure
Completed BoostC compilation, return = 1

C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\boostc_16F.exe reported error code 1


FINISHED

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

And here is the successful log when I moved the FlowChart in C:\FlowCode Projects\:
Target folder: C:\FLOWCO~1
Source name: C:\FlowCode Projects\16F825_osc_test.fcfx
Title:
Description:
Device: PIC.16F.16F1825
Generated by: Flowcode v6.1.3.2
Date: Thursday, January 12, 2017 16:04:28
Users: 1
Registered to: Pro Motion
Licence key: 1HHER7
http://www.matrixtsl.com
Launching the compiler...
C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\boostc_16F.exe -v -t PIC16F1825 "16F825_osc_test.c"
Launching BoostC...
BoostC Optimizing C Compiler Version 7.20 (for PIC16 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2013 Pavel Baranov
Copyright(C) 2004-2013 David Hobday

Licensed to FlowCode User under Single user Pro License for 1 node(s)
Limitations: PIC12,PIC16 max code size:Unlimited, max RAM banks:Unlimited


16F825_osc_test.c
Starting preprocessor: "C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\pp.exe" 16F825_osc_test.c -i "C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\include" -d _PIC16F1825 -la -c2 -o 16F825_osc_test.pp -v -d _BOOSTC -d _PIC16 -d _PIC16x -d _CHAR_INDEX

...........
16F825_osc_test.c success

success
Completed BoostC compilation, return = 0

Launching the linker/assembler...
C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\boostlink_picmicro.exe -ld "C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\lib" libc_16F.lib rand_16F.lib float_16F.lib "16F825_osc_test.obj" -t PIC16F1825 -d "C:\FLOWCO~1" -p "16F825_osc_test" -swcs 6 2
BoostLink Optimizing Linker Version 7.20
http://www.sourceboost.com
Copyright(C) 2004-2013 Pavel Baranov
Copyright(C) 2004-2013 David Hobday


Caution: argument of 'delay_us' calls must have a value of 1 or more
Warning unreferenced functions removed:
FC_CAL_Port_In__x in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_IO.c
FC_CAL_Port_Out__x in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_IO.c
FC_CAL_Port_Out_DDR__x in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_IO.c
Wdt_Delay_S in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
Wdt_Delay_Ms in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINT_US in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINT_MS in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINTWDT_MS in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINT_S in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_DELAYINTWDT_S in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
FCI_GETCHAR in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_GETLENGTH in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_MIDSTRING in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_LEFTSTRING in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_RIGHTSTRING in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOSTRING in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOSTRS16 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOSTRS32 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOSTRU16 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOSTRU32 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOLOWER in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_TOUPPER in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_COMPARE in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_FLOAT_TO_STRING in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_NUMBER_TO_HEX in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_STRING_TO_INT in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_STRING_TO_FLOAT in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_STRREV in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_STRMOV in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_SHEAD in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
FCI_SCOPY in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
isinf in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
pow in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
flt_round in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
flt_floor in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
flt_ceil in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
flt_atan in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
cos in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
sin in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
tan in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
FCD_03d91_led_base1__TurnOn in: C:\FLOWCO~1\16F825_osc_test.c
FCD_03d91_led_base1__TurnOff in: C:\FLOWCO~1\16F825_osc_test.c

Building CASM file
Memory Usage Report
===================
RAM available:1024 bytes, used:34 bytes (3.4%), free:990 bytes (96.6%),
Heap size:336 bytes, Heap max single alloc:95 bytes
ROM available:8192 words, used:109 words (1.4%), free:8083 words (98.6%)



success
.

FINISHED

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

I noticed that PIC16F1825 needs to have specified the OSCCON value in FlowCode, either with a C code block or with Projects Option -- > Use supplementary code, something like:
osccon = 0x72;
I intend to use the internal oscillator.
I would like to know the settings for 16MHz or lower and 32MHz.
The 32MHz can be achieved only with PLL, which must be enabled.
1) My first question is about how do make the oscillator settings proper in FlowCode for 16MHz and for 32MHz using the internal oscillator?
2) Besides the “OSCCON=0x…”, do I need also to set other registers? as for example OSCSTAT = 0x00; and OSCTUNE = 0x00; or even more? As for example LATA = 0x00; TRISA = 0x3F; ANSELA = 0x17; WPUA = 0x00; LATC = 0x02; TRISC = 0x3C; ANSELC = 0x0C; WPUC = 0x00; IOCAP = 0x00; IOCAN = 0x00; IOCAF = 0x00; APFCON0 = 0x00; APFCON1 = 0x00;
My real problem and question is related with “I2C Transmit” subroutine.
How do we set it properly as a Master I2C sending data to the 12bit DAC MCP4725?

I did not try yet with a real PIC, but I can do that if it is needed for the discussion here.
The simulation with Proteus with 2 such PIC16F1825, one loaded with HEX from FlowCode and the other with HEX from CCS C compiler (which gives successful results), each one with its own DAC MCP4725 and the virtual oscilloscope (and sometimes I2C Debugger), shows the problem. The clock and data from FlowCode is not proper, but to find the cause tracing backwards is not so easy.

Can you help with the I2C here?
Attachments
16F825_I2C_DAC.fcfx
This my first I2C FlowChart test
(6.77 KiB) Downloaded 336 times

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

I really do not care about Proteus and simulation, because I can make the real tests and measure with a real oscilloscope and debug the I2C with the oscilloscope decoder, but for fast result I simulated it ans I get the bad results below.
1.jpg
schematic
(274.43 KiB) Downloaded 2001 times
2.jpg
oscilloscope
(386.72 KiB) Downloaded 2001 times
3.jpg
I2C Debugger
(321.18 KiB) Downloaded 2001 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by medelec35 »

Hi,
I would either calculate OSCCON value shown in this example
Or if using Flowcode V7 there is an Osccon Helper component called IntOsc Helper within Tools menu.
Add to a panel, then select the IntOsc Helper on the panel.
Then its just a simple case of selecting correct speed from the drop-down list:
IntOsc Helper.png
(67.42 KiB) Downloaded 7978 times
Its important to also select correct Clock speed within project options so its matches hardware speed!
Note the clock speed within project options does not set the hardware internal osc speed.
It is only OSCCON=0xXX; within C code placed at the start of main that sets hardware clock speed.
The job of clock speed within project options is for all the critical timings of components, delays etc.

Martin
Martin

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

Hi Martin,

Thank you for explanations.
As you can see from my above posts, I have only FlowCode version 6, but maybe during the present year there is a chance to buy/upgrade to v7, so all the explanations that I am interested for the moment are related with v6, because only this I can apply practical in my tests/application.
I reviewed the datasheet of the 16F1825 to have a better understanding and I have also looked at MPLABX with XC8, because they provide Code Configurator plugin to help setup the clock. I will come later with details, maybe helpful for other people too.
As you pointed in the link with that example for 32MHz settings, the value for OSCCON may be OSCCON=0x70; or OSCCON=0xF0; both are correct , depending by the SPLLEN bit (Software PLL Enable bit), but usually is set to 0, so 0x70 is a common setting.
I have my setup as follows:
1a.jpg
1a.jpg (80.28 KiB) Viewed 13638 times
2a.jpg
2a.jpg (117.22 KiB) Viewed 13638 times
3a.jpg
3a.jpg (100.3 KiB) Viewed 13638 times
Interesting to notice that if we uncheck “Show descriptive names” then we get the same mnemonics as in the datasheet.

But my real challenge is how to make I2C run proper as Master with that DAC.
Can you provide any help in that direction?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by medelec35 »

Hi Viki,
You posted about graphical LCD and Flowcode V7 in the V7 section, so I though you had Floecode V7 as well.
Hence posting about both methods.
viki2000 wrote:But my real challenge is how to make I2C run proper as Master with that DAC.
Can you provide any help in that direction?
Sorry, I have only used I2C for RTC and Temperature/Humidity measurements.
not used DAC.

Martin
Martin

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

Then I will try to debug slowly that I2C by myself.

I have only one question related with the clock setup.
In the configuration settings if I set Clock Out Enable in order to get the clock out at the OSC2 pin, I do not see any signal, no matter how is that CLKOUTEN bit 11 is set enabled or disabled.
Then either does not work properly or one moe register setting must be done with the help of C code.

Could you please double check/test that with a simple FlowChart?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by medelec35 »

All you need to do is have Clock out Enable set to enable and that's it.
Can you send the hex file and I will check it's ok.
Have you scoped the out put to check that all is running at the correct speed?

Martin
Martin

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

Hi Martin,
I was ready to answer you "yes“, but I used only simulation software, so I decided for a real PIC.
I used the HEX code generated by FlowCode and a simple FlowChart.
With a real PIC16F1825 and a real oscilloscope everything works fine. I got 8MHz at pin3, PORTA, RA4.
The 8MHz is Fosc/4=32MHz/4, so we are good here.
The simulation software has a bug and does not show any signal at that CLKOUT pin.
Actually I have tried 2 simulation software: Proteus (https://www.labcenter.com/ ) and PIC16 simulator IDE (http://www.oshonsoft.com/pic16.html ), both do not show any signal on CLKOUT.

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

Hi Martin,

Any idea why the Data Scope in FlowCode does not show/simulate the CLKOUT signal?
Data_Scope
Data_Scope
Data_Scope_1.jpg (124.25 KiB) Viewed 13581 times
Settings
Settings
Settings.jpg (167.07 KiB) Viewed 13581 times
I used the below simple FlowChart:
16F1825_CLKOUT.fcfx
CLKOUT
(4.2 KiB) Downloaded 298 times

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

Re: PIC16F1825 Configuration Errors – I2C Master

Post by Benj »

Hello,
Any idea why the Data Scope in FlowCode does not show/simulate the CLKOUT signal?
This is expected, we simulate the components and the I/O but we do not account for things like configuration registers. The simulation should be 99% accurate, for 100% accuracy we recommend using the actual physical chip.

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

Thank you for the clarification.
That means, if I understand it right, that CLKOUT signal is not seen, not simulated because is related with a setting in a register.
I have tested also MPLABX with XC8 compiler and the Simulator inside the MPLABX and it seems that has the same limitation, does not show any CLKOUT signal on scope/analyzer screen, even though if I compile and I burn the HEX file in a real chip, then I can see the CLKOUT with a real scope.

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

Proteus is able to simulate the CLKOUT signal, but the settings are hidden.
Here is a link with screenshots: https://goo.gl/9Il5yC
Then, maybe in future worth to consider the CLKOUT simulation signal also in FlowCode, because in the end it has to do with I/O, the signal being present at one pin.

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: PIC16F1825 Configuration Errors – I2C Master

Post by viki2000 »

Apart of that I was able to make the DAC MCP4725 working by reading and trying different C codes from internet, most of them related with Arduino and less with different PIC microcontrollers.
Below is the attached working code for FC6 tested with a real device.
When you test your MCP4725 you must pay attention to the MCP4725 address, because it is easy to make mistakes if you do not pay attention.
Below is a guide with few explanations which may be useful for other users in future.

1) My 1st mistake was to not check the address of the real MCP4725, because on the datasheet at chapter 7.2 under Device addressing is written:
“The A2 and A1 are programmed to ‘00’ (default), if not requested by customer”
And I did not ask for any special address, so I summed (wrong) that A2 and A1 is 00.
The code marking confirms the ordering code.
In my case A2 and A1 is 10, code marking starting with AQ.
http://i926.photobucket.com/albums/ad10 ... kh4uxj.jpg

2) When you check the device addressing how is it formed with A2, A1, A0, do not make the confusion/mistake with from Address Option Part Number at Package Marking Information. There we have too A3, A2, A1, A0, but these have nothing to do with A2, A1, A0 used to form the I2C address. For me it created a small confusion. It would have been good if Microchip would use other names for Address Option Part Number at Package Marking Information.
http://i926.photobucket.com/albums/ad10 ... cuyjko.jpg

3) When you write the C code you need the steps above.
You initialize once in the beginning the I2C.
Then each time when you send data from PIC to MCP4725 there are 6 steps in our case: START, SEND Device Address, SEND Internal Device Address, SEND DATA, SEND DATA, STOP.
4) The biggest nightmare that you might have is SEND Device Address if you do not know exactly what your address is. Probably using an I2C scanner would be easy as suggested.
Looking in the datasheet of the MCP4725 we form the address as follows:
We start with 1100 for Device Code, then follows A2, A1, A0. In my case A2 and A1 is 10. A0 depends where is connected, to VSS it is 0 and to VDD is 1. In my case I connect to VSS(-) and I have the A0=0. Then I have Slave Address 1100 10 0. Here are 7bits. Because is a write operation, the last bit will be 0, which will be added after Slave Address to form the Address Byte. Then I got the Address Byte 11001000. This is what I will use in SEND Device Address.
http://i926.photobucket.com/albums/ad10 ... b4lvuf.jpg
http://i926.photobucket.com/albums/ad10 ... ewwv5h.jpg

5) Then follows SEND Internal Device Address.
http://i926.photobucket.com/albums/ad10 ... mxxhbm.jpg

When we want to write only to MCP4735 register without writing to EPROM, then we have:
Write DAC Register: (C2, C1, C0) = (0,1,0).
Here we have C2 C1 C0 X X PD1 PD0 X, where X is unused, so we can consider 0. PD1 and PD0 bits are power down bits, which for normal operation are also 0. Only when we want to put MCP4725 in Sleep mode, low power consumption, then we modify these bits.
Then for normal operation, writing only to DAC register we have 010 00 00 0. This is what we send with SEND Internal Device Address.
6) The rest is data, sent in 2 lines, because the MCP4725 is 12bits, so we must split these 12 bits in 2, because we send 1byte (8bits) each time.
7) Below are the oscilloscope of a real working device, I2C signals and Output voltage.
First the output voltage:
http://i926.photobucket.com/albums/ad10 ... znizbl.png
http://i926.photobucket.com/albums/ad10 ... rr57ru.png
Then we have 4 bytes, the START and STOP is not decoded, but we can see it as signals. We have 0x64, 0x40, 0x80, 0x00. They correspond to writing decimal value 2048 to the DAC. We have like this:
a) 0x64 is hexadecimal for 11001000 – the SEND Device Address
b) 0x40 is hexadecimal for 01000000 – the SEND Internal Device Address
c) 0x80 is hexadecimal for 10000000 – the MSB bits of the 2048 decimal (0b100000000000)
d) 0x0 is hexadecimal for 00000000 – the LSB bits of the 2048 decimal (0b100000000000)
16F825_I2C_DAC.fcfx
MCP4725
(6.74 KiB) Downloaded 253 times

Post Reply