Today 18:29
Forum: Website / Forum Issues
Starter: rcurl
Views: 0
Replies: 5
Today 14:15
Forum: Absolute Beginners Section
Starter: amod
Views: 0
Replies: 29
Today 14:11
Forum: The Lounge
Starter: pic-ignorant
Views: 0
Replies: 2
Yesterday 21:12
Forum: Proton Plus Compiler v3
Starter: Dave-S
Views: 0
Replies: 3
+ Reply to Thread
Results 1 to 5 of 5

Thread: CWrite Issues on 16F94 days old

  1. #1
    Junior Member mjturner's Avatar
    Join Date
    Dec 2003
    Posts
    70
    Thumbs Up
    Received: 8
    Given: 0
    Total Downloaded
    392.84 MB

    0 Not allowed!

    Default CWrite 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

  2. #2
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,556
    Thumbs Up
    Received: 61
    Given: 89
    Total Downloaded
    895.24 MB

    1 Not allowed!

    Default Re: 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.

    Tim
    Tim

  3. #3
    Junior Member mjturner's Avatar
    Join Date
    Dec 2003
    Posts
    70
    Thumbs Up
    Received: 8
    Given: 0
    Total Downloaded
    392.84 MB

    0 Not allowed!

    Default Re: CWrite Issues on 16F

    Quote Originally Posted by Tim View Post
    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.

    Tim
    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.

  4. #4
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,556
    Thumbs Up
    Received: 61
    Given: 89
    Total Downloaded
    895.24 MB

    0 Not allowed!

    Default Re: 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 blocks
    Tim

  5. #5
    Junior Member mjturner's Avatar
    Join Date
    Dec 2003
    Posts
    70
    Thumbs Up
    Received: 8
    Given: 0
    Total Downloaded
    392.84 MB

    0 Not allowed!

    Default Re: 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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Change PIC 16F877 by 16F ... ?
    By VE2AH in forum Proton Plus Compiler v3
    Replies: 11
    Last Post: 25th November 2009, 02:15
  2. Optimiser and 16f
    By HelpMe! in forum Proton Plus Compiler v3
    Replies: 24
    Last Post: 17th May 2009, 16:25
  3. 16F serial buffer
    By all77 in forum Proton Plus Compiler v3
    Replies: 8
    Last Post: 25th April 2008, 13:25
  4. 16F v 18F
    By crankshaft in forum The Lounge
    Replies: 2
    Last Post: 5th November 2005, 11:08
  5. Pic18 for 16F series
    By BenH in forum Labcenter Proteus VSM
    Replies: 1
    Last Post: 27th November 2004, 12:32

Members who have read this thread since 14th November 2018, 07:30 : 0

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts