Hot!Read & write function Internal EEPROM PIC18F24K40

Author
ajitnayak87
Starting Member
  • Total Posts : 48
  • Reward points : 0
  • Joined: 2017/06/20 03:53:02
  • Location: 0
  • Status: offline
2017/10/06 05:41:38 (permalink)
0

Read & write function Internal EEPROM PIC18F24K40

Dear all,
 
I am trying to write and Read Internal EEPROM register for PIC18F24K40 controller. I used below code to check weather its writing or not.
 
If i used this instruction it will give build error. when i un comment and use only  DATAEE_WriteByte and  DATAEE_readByte   it wont give any error compile and debug easily. I have attached image of eeprom data read and watch table for reference.Kindly suggest me how can i read internal eeprom read and write function.
if any example code is available please share link.
 
 
The eeprom_write and eeprom_read is being already declared in PIC18.h . I have tried including these header file but continues to give error. Cant i use these instruction directly. Is there any way to use this instruction
 
 
 
eeprom_write(0X00,0X10) ; 
       TempData=eeprom_Read(0X00);

 
 
Main code
/**
  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);
        
        
    }
}

#1

13 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 14946
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 06:04:08 (permalink)
    +1 (1)
    Those functions used to be in the compiler, but they were removed. If you are MCC then have MCC generate the eeprom code.
    #2
    ajitnayak87
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2017/06/20 03:53:02
    • Location: 0
    • Status: offline
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 06:15:58 (permalink)
    0
    Yes I have MCC. I have tried EEPROM enable in memory location.Above code i configured using MCC . But i could not able to get difference between
     
    eeprom_write(0X00,0X10) and
    DATAEE_WriteByte(0X01,0X05);

    As per above eeprom_write(addr,data) no more persist . In that case how can use EEPROM read and write operation using MCC. Can you give basic
    configuration idea for setting EEPROM . And sample working code to read /write data from EEPROM.
     
    #3
    ajitnayak87
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2017/06/20 03:53:02
    • Location: 0
    • Status: offline
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 06:15:58 (permalink)
    0
    Yes I have MCC. I have tried EEPROM enable in memory location.Above code i configured using MCC . But i could not able to get difference between
     
    eeprom_write(0X00,0X10) and
    DATAEE_WriteByte(0X01,0X05);

    As per above eeprom_write(addr,data) no more persist . In that case how can use EEPROM read and write operation using MCC. Can you give basic
    configuration idea for setting EEPROM . And sample working code to read /write data from EEPROM.
     
    #4
    1and0
    Access is Denied
    • Total Posts : 7087
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 06:45:11 (permalink)
    0
    Are you saying DATAEE_WriteByte() and DATAEE_ReadByte() are generated using MCC, and they resulted in build error?  What is the build error message?
     
     
    #5
    ajitnayak87
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2017/06/20 03:53:02
    • Location: 0
    • Status: offline
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 06:49:07 (permalink)
    0
    DATAEE_WriteByte() and DATAEE_ReadByte()  are MCC generated, It wont give build errror. you can see the my code and watch table where i could able to see data . But i cant able to see the data in EEPROM data register.
     
    Kindly refer attached image for reference

    Attachment(s)

    Attachments are not available: Download requirements not met
    #6
    1and0
    Access is Denied
    • Total Posts : 7087
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 06:59:44 (permalink)
    +1 (1)
    Okay, Digits[0] and Digits[1] got the correct data.  It looks like the EE Data Memory window is not updated -- I think it needs a refresh and I don't know how to do that in MPLAB X.
     
    <edit> It looks like the EEPROM cannot be read to update the EE Data Memory window while in run/debug mode: http://www.microchip.com/forums/FindPost/854830
     
     
    post edited by 1and0 - 2017/10/06 07:06:00
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 14946
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 07:00:16 (permalink)
    +2 (2)
    After you write to the eeprom it will not show up I MPLabX unless you click the read back button. It is not automatic
    #8
    ajitnayak87
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2017/06/20 03:53:02
    • Location: 0
    • Status: offline
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 07:03:25 (permalink)
    0
    Do you know difference between 
    eeprom_write(0X00,0X10) and
    DATAEE_WriteByte(0X01,0X05);

    Are both are same . IS DATAEE_WriteByte Used for Internal EEPROM ??? Have you tested the Internal EEPROM access using MPLAB X
    #9
    1and0
    Access is Denied
    • Total Posts : 7087
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 07:07:24 (permalink)
    0
    Post the code for DATAEE_WriteByte().
     
    #10
    ajitnayak87
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2017/06/20 03:53:02
    • Location: 0
    • Status: offline
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 07:10:34 (permalink)
    0
    The Below code generated from MCC. Here is my code.
    -
    But i would like to get confirm eeprom_write(addr,data) and DATAEE_WriteByte(uint8_t bAdd, uint8_t bData)
     are similar or not
     
    void DATAEE_WriteByte(uint8_t bAdd, uint8_t bData)
    {
        uint8_t GIEBitValue = INTCONbits.GIE;

        NVMADRL = (bAdd & 0xFF);
        NVMDAT = bData;
        NVMCON1bits.NVMREG = 0;
        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
    }

    uint8_t DATAEE_ReadByte(uint8_t bAdd)
    {
        NVMADRL = (bAdd & 0xFF);
        NVMCON1bits.NVMREG = 0;
        NVMCON1bits.RD = 1;
        NOP(); // NOPs may be required for latency at high frequencies
        NOP();

        return (NVMDAT);
    }

    post edited by ajitnayak87 - 2017/10/06 07:12:42
    #11
    1and0
    Access is Denied
    • Total Posts : 7087
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 07:34:40 (permalink)
    0
    Those functions are accessing the internal EEPROM.  IIRC, eeprom_write() and eeprom_read() access the internal EEPROM too.  That said, AND'ing 0xFF in (bAdd & 0xFF) is useless because bAdd is of type uint8_t already.
     
    #12
    1and0
    Access is Denied
    • Total Posts : 7087
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 07:37:58 (permalink)
    +2 (2)
    Does the 24K40 have the NVMREG errata?  If it does, I'd suggest restoring the NVMREG bits to flash memory access before returning from those functions.
     
     
    #13
    ajitnayak87
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2017/06/20 03:53:02
    • Location: 0
    • Status: offline
    Re: Read & write function Internal EEPROM PIC18F24K40 2017/10/06 19:07:10 (permalink)
    #14
    Jump to:
    © 2017 APG vNext Commercial Version 4.5