
Thread: CWrite Issues on 16F – 185 days old
-
18th August 2018, 14:17 #1
- Join Date
- Dec 2003
- Posts
- 86
- Total Downloaded
- 468.57 MB
Thumbs Up Received: 14
Given: 4
0CWrite Issues on 16F
I want to commit some values to EEPROM, but it seems they no longer include the separate EEPROM area anymore. So I'm having to use the code flash memory. I'm struggling to get CRead/CWrite/CErase to function as expected.
The following is the core part of the code where the issue is. I've included fuses just in-case they have a bearing.
The basic idea is that it reads a known location, if it isn't zero then we know the chip has been flashed and is new. Therefore it generates valid starting values and saves them to flash memory. The issue is that it always sees a non-zero value. Which would indicate to me that it isn't writing the values. However I've no idea why the write would be failing.
The value used for StoredAddr is just a value that I picked that would be above the program size, I picked one divisible by 512 so it should be on a 32 byte boundary in theory. I did originally try just writing the bytes I needed, but tried putting the full 32 in there just in case that was the issue.
Any thoughts on what I might be doing wrong?
Code:Device = 16F15345 Config1 FEXTOSC_OFF, RSTOSC_HFINT32, CLKOUTEN_OFF, CSWEN_ON, FCMEN_ON Config2 MCLRE_OFF, PWRTE_OFF, LPBOREN_OFF, BOREN_ON, BORV_LO, ZCD_OFF, PPS1WAY_ON, STVREN_ON Config3 WDTCPS_WDTCPS_31, WDTE_OFF, WDTCWS_WDTCWS_7, WDTCCS_HFINTOSC Config4 BBSIZE_BB512, BBEN_OFF, SAFEN_OFF, WRTAPP_OFF, WRTB_OFF, WRTC_OFF, WRTSAF_OFF, LVP_ON Config5 CP_OFF ;**** End of Fuse Configurator Settings **** ;------------------------------------------------------------------------------- Xtal = 32 All_Digital = TRUE ' Set PORTA and PORTC to all digital Declare Optimiser_Level = 0 Symbol StoredAddr =7680 ReadSequence: vstemp=CRead StoredAddr + 4 If vstemp<>0 Then ' This is a re-programmed device, so reset the server and sequence codes SerOut SerialOutDiag,84,["Keys reset"] SerOut SerialOutDiag,84,[13] SerOut SerialOutDiag,84,[10] vstemp=0 Clear ServerSequence OrbSequence=1 GoSub UpdateSequence GoSub WiFi_PowerOn GoSub DoWipeKeys DelayMS 1000 GoSub DoPowerDownWiFi Else ServerSequence.LowByte=CRead StoredAddr ServerSequence.HighByte=CRead StoredAddr+1 OrbSequence.LowByte=CRead StoredAddr+2 OrbSequence.HighByte=CRead StoredAddr+3 OrbSequence=OrbSequence+20 End If Return UpdateSequence: CErase StoredAddr CWrite StoredAddr,[ServerSequence.LowByte,ServerSequence.HighByte,OrbSequence.LowByte,OrbSequence.HighByte,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255] Return
-
20th August 2018, 08:30 #2
- Join Date
- Jan 2003
- Posts
- 7,597
- Total Downloaded
- 895.24 MB
Thumbs Up Received: 69
Given: 91
1Re: CWrite Issues on 16F
Some thoughts
Ensure StoreAddr is on the correct boundary and you are writing the correct number of bytes. Some are as low as 32 bytes others 64. Look at the data sheet or the PPI file for the device.
TimTim
-
21st August 2018, 17:48 #3
- Join Date
- Dec 2003
- Posts
- 86
- Total Downloaded
- 468.57 MB
Thumbs Up Received: 14
Given: 4
0Re: CWrite Issues on 16F
Thanks Tim. How do I figure out the boundary? This PIC lists it as 32 byte pages. Therefore I figured if the address is divisible by 32 it should be OK, or is that assumption incorrect?
Also the datasheet doesn't mention about having to write the full 32 bytes, only that you can only write to previously erased bytes. Nothing in the EWrite command seemed to indicate that I had to write all 32 bytes. However I did give that a go and it didn't seem to help.
-
21st August 2018, 22:47 #4
- Join Date
- Jan 2003
- Posts
- 7,597
- Total Downloaded
- 895.24 MB
Thumbs Up Received: 69
Given: 91
0Re: CWrite Issues on 16F
Sorry for the delay
Yes if it says 32 byte then its a number divisible by 32. eg $4EC0 which is 32 x 630
You have to write from the same 32 byte boundry
Ewrite basically writes to a set of regs (in the pic) then it makes the pic write that lot to flash memory. Proton will not do the write until it counts the full x number of data is written
In the PPI file it has the number expected
BLOCK=32 ; Size of the Code Memory Write Segment (in Words)
ERASE=32 ; Size of the Code Memory Erase Segment (in Words)
So for example you want to write to memory a series of data
1 Erase the block
2 Write all the data, this can be as long command as you have done or a loop
Once Proton sees enough data written it will complete the command
I think I have this right the pic uses 14bits data so you need to write words
And you need to check the fuses are set right as you can prevent data writing to certain memory blocksTim
-
26th August 2018, 07:38 #5
- Join Date
- Dec 2003
- Posts
- 86
- Total Downloaded
- 468.57 MB
Thumbs Up Received: 14
Given: 4
0Re: CWrite Issues on 16F
Tim - thanks. Yes that is the bit I didn't understand - while the PIC datasheet says you can write just the bytes you want, Proton only commits the write when it has a full block. I ran a few tests to dump out the ram, and indeed it only changed when 32 bytes were in the CWrite command. All works now! Thank you.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
This valuable resource relies upon the very
small amount of revenue generated by displaying online advertisements
to our visitors.
The advertisements we display are relevant to this web site and your
browsing history
Please consider supporting us by disabling your ad blocker.
Note: Some users have reported issues related to ad-blockers rendering
parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this
resource with adblocking enabled.
If you can, please report issues in the forum area WebSite / Forum Issues
Thank you for your attention.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Change PIC 16F877 by 16F ... ?
By VE2AH in forum Proton Plus Compiler v3Replies: 11Last Post: 25th November 2009, 02:15 -
Optimiser and 16f
By HelpMe! in forum Proton Plus Compiler v3Replies: 24Last Post: 17th May 2009, 16:25 -
16F serial buffer
By all77 in forum Proton Plus Compiler v3Replies: 8Last Post: 25th April 2008, 13:25 -
16F v 18F
By crankshaft in forum The LoungeReplies: 2Last Post: 5th November 2005, 11:08 -
Pic18 for 16F series
By BenH in forum Labcenter Proteus VSMReplies: 1Last Post: 27th November 2004, 12:32
Members who have read this thread : 30
Actions : (Set Date)
You do not have permission to view the list of names.
Proton Compiler Updates
Full install of 8-bit Proton and Proton24 Download the full compiler...
1st January 1970, 01:00