Hot!eeprom_read() & eeprom_write() are not recognized with a pic16f18313

Author
PAR
Starting Member
  • Total Posts : 46
  • Reward points : 0
  • Joined: 2005/02/15 13:49:48
  • Location: Portland, Or
  • Status: offline
2016/06/02 14:03:07 (permalink)
0

eeprom_read() & eeprom_write() are not recognized with a pic16f18313

I'm using compiler xc8 v1.32 in PRO Mode.
 
I can use the microchip functions eeprom_read() & eeprom_write() in a 16f1938 but not in a pic16f18313.
 
Is it done differntly..?  Have the names changed for the 16f18313..?
Any help would be great.  Thanks in advance, Pat.
#1

12 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 14834
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2016/06/02 14:38:26 (permalink)
    0
    I assume the Version of Plib in that compiler does not have those functions for that PIC.You can try a newer version of Plib, But is it is a new PIC, since PLib is end of life you may have to code it yourself.  Or steal the code from MCC
    #2
    PAR
    Starting Member
    • Total Posts : 46
    • Reward points : 0
    • Joined: 2005/02/15 13:49:48
    • Location: Portland, Or
    • Status: offline
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2016/06/02 14:51:57 (permalink)
    0
    Thank you NKurzman,
     
    I think I found the issue.  I have to upgrade xc8 v1.32 to v1.37.
    If that fails I'll be back.
    Thanks again, Pat.
    #3
    DarioG
    Scheisse Menschen
    • Total Posts : 52401
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: hi there
    • Status: online
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2016/06/02 15:03:12 (permalink)
    0
    ***
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 14834
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2016/06/02 15:52:58 (permalink)
    0
    PAR
    Thank you NKurzman,
     
    I think I found the issue.  I have to upgrade xc8 v1.32 to v1.37.
    If that fails I'll be back.
    Thanks again, Pat.


    You will have to install Plib separately.  It is on the same web page as the compiler.
    #5
    DarioG
    Scheisse Menschen
    • Total Posts : 52401
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: hi there
    • Status: online
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2016/06/11 03:26:13 (permalink)
    0
    aaa test
    #6
    PAR
    Starting Member
    • Total Posts : 46
    • Reward points : 0
    • Joined: 2005/02/15 13:49:48
    • Location: Portland, Or
    • Status: offline
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2016/06/30 12:03:51 (permalink)
    0
    Okay I'm back trying to get this to work.  So far I had to upgrade to v1.37 because the older one would not compile the 16f18313 chip.  Plus it seem functions eeprom_read() & eeprom_write() are not used in v1.37.  So I used the latest MCC in mplabx v3.30 to create
    void DATAEE_WriteByte(unsigned int bAdd, unsigned char bData)
    unsigned char DATAEE_ReadByte(unsigned int bAdd)
    The project compiles fine now but when I write some data to address 0 and 1 I can read the data correctly but if I try to write to those locations again with data it clears the data to zeros.  All other writes to the eeprom location still no new data saved.?  It is like I can only write once then after that it only writes zeros.
     
    Also when I read out the chip using IPE v3.30 the eeprom showes 0xFF in the locations that are zero.
    Dario, it seems you knew I was barking up the wronge tree...
     
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 14834
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2016/06/30 12:45:00 (permalink)
    0
    1.You can add New PICs to Old Compilers with a Patch file (where you found the compiler)
    2. eeprom_read() & eeprom_write() Are in PLib now legacy and a separate install.
    3. How are you telling if you read and wrote correctly?
    4. Post the code for those functions.
     
    #8
    PAR
    Starting Member
    • Total Posts : 46
    • Reward points : 0
    • Joined: 2005/02/15 13:49:48
    • Location: Portland, Or
    • Status: offline
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2016/06/30 13:48:32 (permalink)
    0
    1&2) I'll take a look and see if can get them to work.
    3) First I was in debug and before I get to main I would read the locations.  The first time they would read as 0xFFFF if this is true I would write 0x04D2 into address 0 and 1.  In main I would read the eeprom locations, after 5 seconds, if they are equal to 0x04D2 write 0x0001.  Then I would read the eeprom again 5 seconds later and if not equel to 0x04D2 then write 0x04D2.  Using break points I could see 0x4D2 writen to and I can see it read out and equel to 0x04D2.  I can see that I try to write 0x0001 but every read after that always reports zero.
    Second I used the above code not in debug and drive a pin to 1 if eeprom locations are 0x04D2 a square wave if equel to 0x0001 and zero if anything else.  On the scope you see the pin go to 1 for 5 seconds then drops to zero.  Forever.
     
    The code generated for the 2 functions are...
    void DATAEE_WriteByte(unsigned int bAdd, unsigned char bData)
    {
    unsigned char GIEBitValue = INTCONbits.GIE;
    NVMCON1bits.NVMREGS = 1;
    NVMADRH = ((bAdd >> 8) & 0xFF);
    NVMADRL = (bAdd & 0xFF);
    NVMDATL = bData;
    NVMCON1bits.WREN = 1;
    INTCONbits.GIE = 0; // Disable interrupts
    NVMCON2 = 0x55;
    NVMCON2 = 0xAA;
    NVMCON1bits.WR = 1;
    // Wait for write to complete
    while (NVMCON1bits.WR)
    {
    }
    NVMCON1bits.WREN = 0;
    INTCONbits.GIE = GIEBitValue; // restore interrupt enable
    }
    unsigned char DATAEE_ReadByte(unsigned int bAdd)
    {
    NVMADRH = ((bAdd >> 8) & 0xFF);
    NVMADRL = (bAdd & 0xFF);
    NVMCON1bits.NVMREGS = 1;
    NVMCON1bits.RD = 1;
    NOP(); // NOPs may be required for latency at high frequencies
    NOP();
    return (NVMDATL);
    }
     
    Thanks for all your help, Pat.
    #9
    NKurzman
    A Guy on the Net
    • Total Posts : 14834
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2016/06/30 16:07:31 (permalink)
    0
    Note after you change the EEPROM or Flash During Debug it will not be reflected in the EEPROM Window.
    You would need to read it back. It is Possible you would need to do that in IPE.  In Mplab 8 the capability depended on the tools.
     
    You may want to read it back in you program as a test.
    Since they check for write done at the end the data will be ok in the read.
    But, that is not the preferred way.  It may be better to check for busy at the begining of both.  Writes are slow and the time could be spent doing other things.
    #10
    NKurzman
    A Guy on the Net
    • Total Posts : 14834
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2016/06/30 16:28:18 (permalink)
    0
    With Code Tags
     
     Note this is My reading of the Data sheet
     

     
    void DATAEE_WriteByte(unsigned char bAdd, unsigned char bData)
    {
       bit GIEBitValue = INTCONbits.GIE;

       while (NVMCON1bits.WR){}     // Wait for write to complete, if needed
       NVMCON1bits.NVMREGS = 1;   //1 = Access EEPROM, Configuration, User ID and Device ID Registers,  0 = Flash
       NVMADRH = (0x7000 >> 8) ;  // eeprom address + 0x7000 (10.4.3)
       NVMADRL = bAdd;                  // set write addr
       NVMDATL = bData;                 // set data
       NVMCON1bits.WREN = 1;        // enable writing
       INTCONbits.GIE = 0; // Disable interrupts
       NVMCON2 = 0x55;                // Unlock Key 1
       NVMCON2 = 0xAA;                 // Unlock Key 2
       NVMCON1bits.WR = 1;            // Start the write
       NVMCON1bits.WREN = 0;         // Disable writing
       INTCONbits.GIE = GIEBitValue; // restore interrupt enable
     }


    unsigned char DATAEE_ReadByte(unsigned byte bAdd)
    {
       while (NVMCON1bits.WR){}     // Wait for awrite to complete, if needed 
       NVMADRH = (0x7000 >> 8) ;  // eeprom address + 0x7000 (10.4.3)
       NVMADRL = bAdd;                  // set write addr
       NVMCON1bits.NVMREGS = 1;    // 1 = Access EEPROM, Configuration, User ID and Device ID Registers,  0 = Flash       NVMCON1bits.RD = 1;             // begin read
       //NOP();  the data sheet says nothing abouth these NOPs, check the Eratta
       //NOP(); 
       return (NVMDATL);
    }

    #11
    ajitnayak87
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2017/06/20 03:53:02
    • Location: 0
    • Status: offline
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2017/10/06 19:04:37 (permalink)
    0
    Have you tested Internal EEprom Code. Its working with function DataEE_writeByte(). I found it wont update the eeprom Register while debug mode. if its really working can u let me know MCC configuration. I have also tested on PIC18F24K42. but i cant able to see in EEPROM. Below thing i created using MCC configurator  but i cant see updated EEPROM
     
    /**
      Generated Main Source File

      Company:
        Microchip Technology Inc.

      File Name:
        main.c

      Summary:
        This is the main file generated using MPLAB(c) Code Configurator

      Description:
        This header file provides implementations for driver APIs for all modules selected in the GUI.
        Generation Information :
            Product Revision : MPLAB(c) Code Configurator - 4.15
            Device : PIC18F24K40
            Driver Version : 2.00
        The generated drivers are tested against the following:
            Compiler : XC8 1.35
            MPLAB : MPLAB X 3.40
    */

    /*
        (c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this
        software and any derivatives exclusively with Microchip products.

        THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
        EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
        WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
        PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
        WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.

        IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
        INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
        WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
        BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
        FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
        ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
        THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.

        MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
        TERMS.
    */

    #include "mcc_generated_files/mcc.h"
    #include"xc.h"
    #include"pic18.h"
    //#include "18f24k40.cgen.inc"
    unsigned char Digits[4]=0;
    unsigned char TempData;


    void main(void)
    {
        // Initialize the device
        SYSTEM_Initialize();

        
        
         
        // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
        // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
        // Use the following macros to:

        // Enable high priority global interrupts
        //INTERRUPT_GlobalInterruptHighEnable();

        // Enable low priority global interrupts.
        //INTERRUPT_GlobalInterruptLowEnable();

        // Disable high priority global interrupts
        //INTERRUPT_GlobalInterruptHighDisable();

        // Disable low priority global interrupts.
        //INTERRUPT_GlobalInterruptLowDisable();

        // Enable the Global Interrupts
        //INTERRUPT_GlobalInterruptEnable();

        // Enable the Peripheral Interrupts
        //INTERRUPT_PeripheralInterruptEnable();

        // Disable the Global Interrupts
        //INTERRUPT_GlobalInterruptDisable();

        // Disable the Peripheral Interrupts
        //INTERRUPT_PeripheralInterruptDisable();

        while (1)
        {
           /*eeprom_write(0X00,0X10) ;
           TempData=eeprom_Read(0X00);*/
            DATAEE_WriteByte(0X00,0X10);
            Digits[0]= DATAEE_ReadByte(0X00);
           
             DATAEE_WriteByte(0X01,0X05);
             Digits[1]= DATAEE_ReadByte(0X01);
           
               DATAEE_WriteByte(0X02,0X05);
            
            
        }
    }



    [/code]

    Attached Image(s)

    #12
    NKurzman
    A Guy on the Net
    • Total Posts : 14834
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: eeprom_read() & eeprom_write() are not recognized with a pic16f18313 2017/10/06 19:09:46 (permalink)
    +1 (1)
    MPLAB X does Not see what you write to EEPROM or Flash unless you Read Back form the Device.  Green Up Arrow to the left of Debug.
    #13
    Jump to:
    © 2017 APG vNext Commercial Version 4.5