Go to last post By: joesaliba
Today 20:45
Forum: The Lounge
Starter: Les
Views: 0
Replies: 7
Today 10:19
Forum: Website / Forum Issues
Starter: jwb
Views: 0
Replies: 0
Today 09:44
Forum: Proton Users File Server
Starter: Les
Views: 0
Replies: 1
+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Junior Member bradysmall's Avatar
    Join Date
    Sep 2017
    Posts
    7
    Thumbs Up
    Received: 0
    Given: 1
    Total Downloaded
    85.12 MB

    0 Not allowed!

    Default EData and ERead problems in a PIC16F18877

    Hello everyone.. Long time, first time..

    I have a PIC16F18877 I'm designing with and everything is going great.. Only issue i have run into is using the onboard eeprom. I can't seem to get any data into it or out of it using EData and ERead. I've made a small sample program with a serial debug out to see whats going on.. and it seems the write and read never really happen..

    Code:
    Device = 16F18877
    
    
    Config1 FEXTOSC_OFF, RSTOSC_HFINTPLL, CLKOUTEN_OFF, CSWEN_ON, FCMEN_OFF
    Config2 MCLRE_OFF, PWRTE_OFF, LPBOREN_OFF, BOREN_ON, BORV_LO, ZCD_OFF, PPS1WAY_OFF, STVREN_OFF
    Config3 WDTCPS_WDTCPS_31, WDTE_OFF, WDTCWS_WDTCWS_7, WDTCCS_SC
    Config4 WRT_OFF, SCANE_not_available, LVP_ON
    Config5 CP_OFF, CPD_OFF
    
    Declare Xtal 16   
    
    
    Symbol SerialOutPin = PORTB.3  
    Symbol Baud9600 = 16468         
    Output SerialOutPin
    
    
    
    
    Dim ReturnData As Byte
    Dim IncCount As Byte 
    SerOut SerialOutPin, Baud9600,["Starting up..",13]
    
    
    MainSub:
    
    
            ReturnData = ERead 0  'Read the data from the EEPROM
            
            SerOut SerialOutPin, Baud9600,["ERead Address 0: ",Dec ReturnData," Written Data: ", Dec IncCount,13]  'Send it out our serial pin.
             
            Inc IncCount  'Go up by one.
            EData Byte IncCount 'Write in the new value..
            
            If IncCount = 255 Then IncCount = 0 'If goes over.. go back to 0
    
    
            DelayMS 2000
            
    GoTo MainSub
    The output i see looks like this:

    Starting up..
    ERead Address 0: 0 Written Data: 0
    ERead Address 0: 0 Written Data: 1
    ERead Address 0: 0 Written Data: 2
    ERead Address 0: 0 Written Data: 3
    ERead Address 0: 0 Written Data: 4
    ERead Address 0: 0 Written Data: 5
    ERead Address 0: 0 Written Data: 6
    ERead Address 0: 0 Written Data: 7
    ERead Address 0: 0 Written Data: 8
    ERead Address 0: 0 Written Data: 9
    ERead Address 0: 0 Written Data: 10
    ERead Address 0: 0 Written Data: 11
    ERead Address 0: 0 Written Data: 12
    ERead Address 0: 0 Written Data: 13

    When i use my programmer to read the EEPROM memory space, i see this..

    0000- 3b ff ff ff ff ff ff ff
    0008- ff ff ff ff ff ff ff ff
    0010- ff ff ff ff ff ff ff ff
    0018- ff ff ff ff ff ff ff ff
    0020- ff ff ff ff ff ff ff ff
    0028- ff ff ff ff ff ff ff ff
    0030- ff ff ff ff ff ff ff ff
    0038- ff ff ff ff ff ff ff ff
    0040- ff ff ff ff ff ff ff ff
    0048- ff ff ff ff ff ff ff ff
    0050- ff ff ff ff ff ff ff ff
    0058- ff ff ff ff ff ff ff ff
    0060- ff ff ff ff ff ff ff ff
    0068- ff ff ff ff ff ff ff ff
    0070- ff ff ff ff ff ff ff ff
    0078- ff ff ff ff ff ff ff ff
    0080- ff ff ff ff ff ff ff ff
    0088- ff ff ff ff ff ff ff ff
    0090- ff ff ff ff ff ff ff ff
    0098- ff ff ff ff ff ff ff ff
    00a0- ff ff ff ff ff ff ff ff
    00a8- ff ff ff ff ff ff ff ff
    00b0- ff ff ff ff ff ff ff ff
    00b8- ff ff ff ff ff ff ff ff
    00c0- ff ff ff ff ff ff ff ff
    00c8- ff ff ff ff ff ff ff ff
    00d0- ff ff ff ff ff ff ff ff
    00d8- ff ff ff ff ff ff ff ff
    00e0- ff ff ff ff ff ff ff ff
    00e8- ff ff ff ff ff ff ff ff
    00f0- ff ff ff ff ff ff ff ff
    00f8- ff ff ff ff ff ff ff ff

    I don't know were the 3b is coming from in the first byte.. and it never changes when re-read the eeprom memory.

    If i write a DWord, and then re-read the eeprom from my programmer, I can see 4 bytes now.

    swap out:

    Code:
     EData Dword IncCount
    Reading the EEPROM i see this now:

    0000- 4a 00 00 00 ff ff ff ff
    0008- ff ff ff ff ff ff ff ff
    0010- ff ff ff ff ff ff ff ff

    So its doing something, but don't know where the 4a came from..

    Using the latest compiler - 3.6.0.3

    Any help to point me in the right direction would be great... Thanks!

    Brady

  2. #2
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    2,997
    Thumbs Up
    Received: 299
    Given: 109
    Total Downloaded
    1.50 GB

    0 Not allowed!

    Default Re: EData and ERead problems in a PIC16F18877

    Some of the enhanced 14-bit core devices have had massive changes done to them for so little reason, other than Microchip must have a new bunch of nerds working for them. :-)

    I'm busy working on the next update to the compiler to make sure all the unnecessary changes to these devices has been catered for.

    I've uploaded an include file that replaces the compiler's library eread and ewrite command routines for you to test. I don;t have that exact part, but the routines follow the spec within the datasheet. Also make sure your programmer does actually fully support these devices, and it's not just an add on to it.

    Replacement Eread and EWrite library routines for a PIC16F18877 device
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  3. #3
    Junior Member bradysmall's Avatar
    Join Date
    Sep 2017
    Posts
    7
    Thumbs Up
    Received: 0
    Given: 1
    Total Downloaded
    85.12 MB

    0 Not allowed!

    Default Re: EData and ERead problems in a PIC16F18877

    Thanks for the sample code.. Something is still a miss.. It looks like its modifying the program code space, instead of the EEPROM memory space..

    I can program the pic, fire it up.. program will run once, with output and then its done..

    Reading From Programmed Eeprom
    0: 0
    1: 0
    2: 128
    3: 184
    4: 168
    5: 175
    6: 176
    7: 160
    8: 40
    9: 3
    Writing
    Reading
    3: 3
    3: 3
    3: 3
    3: 3
    3: 3
    3: 3
    3: 3
    3: 3
    3: 3
    3: 3


    Power cycle the pic, and it doesn't respond.. If I compare the code that went in to it and the code that is now in it.. See attached picture.

    changed_code.JPG

    Highlighted area in the compare is the only part in the program memory that was modified.

    Reading the EEPROM space from the programmer.. I see the correct data!

    0000- 01 02 03 04 05 06 07 08
    0008- 09 00 ff ff ff ff ff ff
    0010- ff ff ff ff ff ff ff ff
    0018- ff ff ff ff ff ff ff ff
    Last edited by bradysmall; 4th November 2017 at 20:10.

  4. #4
    Junior Member bradysmall's Avatar
    Join Date
    Sep 2017
    Posts
    7
    Thumbs Up
    Received: 0
    Given: 1
    Total Downloaded
    85.12 MB

    0 Not allowed!

    Default Re: EData and ERead problems in a PIC16F18877

    Adding to my last post.. Programmer was set to program the EEPROM space as well.. I turned that off, and its still the same, pic will run once and then its done..

    When I re-read the EEPROM space.. It has not been modified.

    0000- ff ff ff ff ff ff ff ff
    0008- ff ff ff ff ff ff ff ff
    0010- ff ff ff ff ff ff ff ff
    0018- ff ff ff ff ff ff ff ff

    Re-Reading the program memory space, and its been modified.

  5. #5
    Junior Member bradysmall's Avatar
    Join Date
    Sep 2017
    Posts
    7
    Thumbs Up
    Received: 0
    Given: 1
    Total Downloaded
    85.12 MB

    0 Not allowed!

    Default Re: EData and ERead problems in a PIC16F18877

    Been playing with this some more.. And the EData command doesn't seem to be doing the destructive write to the program space.. But it doesn't also write to the EEPROM space as well.

    If i just leave in the EData command and no EWrite.. Program memory is not affected.

    As soon as I enable the EWrite as you have sent in the sample code, it starts writing in the program memory space.. Sound like the definition for the chip might be a little off..


    I saw since this chip has two MSSP (I2C) hardware controlled outputs, it doesn't support the compiler's HBusIN/HBusOut commands due to the register that HBus is looking for.. (SSPCON1) This chip has the SSPxCON1 register unlike ones that only have one of the MSSP hardwares in it. I saw in a post you had a while back about modified HBus1 and Hbus2 code.. I'll try that out later for this chip..

  6. #6
    Junior Member bradysmall's Avatar
    Join Date
    Sep 2017
    Posts
    7
    Thumbs Up
    Received: 0
    Given: 1
    Total Downloaded
    85.12 MB

    0 Not allowed!

    Default Re: EData and ERead problems in a PIC16F18877

    Les,

    Still not able to get EWrite and ERead to work correctly.. on the 18877.

    EData does set it correctly and my programmer does program the EEPROM when i read it back..

    If I manually do this...

    Code:
     Dim Hbyte As Byte
     Dim LByte As Byte
    
         Set NVMCON1bits_NVMREGS
         NVMADRH = $F0                   'EEPROM Memory space is located at: F000h-F0FFh 
         NVMADRL = $00
         Set NVMCON1bits_RD
        
         Hbyte = NVMDATH
         LByte = NVMDATL
    I get my EEPROM bytes read back correctly that were programmed in by EData.

    Have not tried to manually write into the EEPROM yet.. staying up too late.. Eyes getting tired.... Will look tomorrow..

  7. #7
    Inactive member erbiem's Avatar
    Join Date
    Aug 2014
    Posts
    1
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    884.08 MB

    0 Not allowed!

    Default Re: EData and ERead problems in a PIC16F18877

    Hello bradysmall


    did you solve eread and ewrite problem?

  8. #8
    Junior Member bradysmall's Avatar
    Join Date
    Sep 2017
    Posts
    7
    Thumbs Up
    Received: 0
    Given: 1
    Total Downloaded
    85.12 MB

    0 Not allowed!

    Default Re: EData and ERead problems in a PIC16F18877

    Yes. I had to do this manually by flipping bits in the registers. Here is the code I wrote to debug the issue.

    Code:
    'READ A ADDRESS
        Set NVMCON1bits_NVMREGS          'Page 186 - Set the NVMREG Bit to 1 =  Want to access EEPROM memory area.
        NVMADRH = $F0                           'Page 185 - Set the NVMDATH -  NONVOLATILE MEMORY DATA HIGH BYTE REGISTER Byte   'This the the location in EEPROM we want to read the data from..
        NVMADRL = $00                            'Page 185 - Set the NVMADRL -  NONVOLATILE MEMORY DATA LOW BYTE REGISTER Byte
        Set NVMCON1bits_RD                    'Page 186 -  Set the RD bit to 1 Initiates a read at address = NVMADR1, and loads data to NVMDAT Read takes one instruction cycle and the bit is cleared when the operation is complete. 
        
        UserByte1 = NVMDATH                'Page 185 - Read the HIGH And LOW byte out of the two registers to get the data in the EEPROM location specified above.
        UserByte2 = NVMDATL                'NOTE - Reading from EEPROM loads only NVMDATL<7:0> -
    
    
        SerOut SerialOutPin, Baud9600,["ADDRESS: $00 High: ",Dec UserByte1," Low: ",Dec UserByte2,13] 
    
    
    
    'Write to an Address
        Set NVMCON1bits_NVMREGS        'Page 186 - Set the NVMREG Bit to 1 =  Want to access EEPROM memory area.   
        Set NVMCON1bits_WREN              'Page 186 - Set the WREN bit to 1 = Allows Program and erase cycles.
        NVMADRH = $F0                          'Page 185 - Set the NVMDATH -  NONVOLATILE MEMORY DATA HIGH BYTE REGISTER Byte   'This the the location in EEPROM we want to read the data from..
        NVMADRL = $01                          'Page 185 - Set the NVMADRL -  NONVOLATILE MEMORY DATA LOW BYTE REGISTER Byte
        
        NVMDATH = FirstByte1                 'Write the data we want to save to the NVMDATH and NVMDATL registers.
        NVMDATL = FirstByte2
        
        NVMCON2 = $55                          'Must send this sequence to the NVMCON2 Register to unlock it to allow writing. Page 173.
        NVMCON2 = $AA
        Set NVMCON1bits_WR                  'Set the NVMCON1 WR bit to 1 to start the write.
        
        'DelayMS 50
                                        
        While NVMCON1bits_WR = 1        'Check the WR bit.. Once its 0.. You can write to the next address.
           SerOut SerialOutPin, Baud9600,["Writing to EEPROM",13]
        Wend
        
        SerOut SerialOutPin, Baud9600,["Write Complete!",13]

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Pic16f18877
    By teo in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 4th December 2016, 15:47
  2. New PIC16F1579 and PIC16F18877 families with Core-Independent Peripherals
    By normnet in forum New devices and techniques
    Replies: 2
    Last Post: 21st July 2015, 08:04
  3. [SOLVED !] Edata Eread problems with words
    By Jamil in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 22nd April 2008, 13:16

Members who have read this thread since 12th September 2018, 12:42 : 1

Actions :  (Set Date)  (Clear Date)

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

Tags for this Thread

Posting Permissions

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