• AVR Freaks

Hot!Pic18f26k83 read and write internal eeprom

Author
FR3D
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2018/08/29 04:19:00
  • Location: 0
  • Status: offline
2019/06/26 06:12:11 (permalink)
0

Pic18f26k83 read and write internal eeprom

Hallo
XC8 Version 2.05
I tried
https://microchipdeveloper.com/faq:36
#include <xc.h>
int main ()
{
    volatile unsigned char value = 0x09;
    unsigned char address = 0xE5;
    eeprom_write(address, value);     // Writing value 0x9 to EEPROM address 0xE5        
    value = eeprom_read (address);    // Reading the value from address 0xE5
}
 
</xc.h>
and this

#include <xc.h>
int main ()
{
    volatile unsigned char value = 0x09;
    unsigned char address = 0xE5;
    EEPROM_WRITE(address, value);    // Writing value 0x9 to EEPROM address 0xE5 using the macro
    value = EEPROM_READ(address);    // Reading the value from address 0xE5 using the macro
}
 
</xc.h>
I always get
:0:: error: (500) undefined symbols:
    _Write_b_eep(dist/free/production\K83_CAN_senden_rs232_senden.X.production.o) _Busy_eep(dist/free/production\K83_CAN_senden_rs232_senden.X.production.o)
(908) exit status = 1

I installed
PIC18F Legacy Peripheral Libraries v2.0 - Windows
What is "Write_b_eep" and what is "Busy_eep" ?
Do I have something else to enable or to include before I can use the internal EEPROM ?
best regards FR3D
#1

9 Replies Related Threads

    pcbbc
    Super Member
    • Total Posts : 1096
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Pic18f26k83 read and write internal eeprom 2019/06/26 06:30:46 (permalink)
    +1 (1)
    See here
     
    unsigned char eeprom18_read(unsigned int offset) {
        EECON1bits.EEPGD = 0; //accesses data EEPROM memory
        EECON1bits.CFGS = 0; //accesses data EEPROM memory

        EEADRH = offset >> 8;
        EEADR = offset;

        EECON1bits.RD = 1; //initiates an EEPROM read
        Nop(); //it can be read after one NOP instruction

        return EEDATA;
    }
     
    void eeprom18_write(unsigned int offset, unsigned char value) {
        EECON1bits.EEPGD = 0; //accesses data EEPROM memory
        EECON1bits.CFGS = 0; //accesses data EEPROM memory

        EEADRH = offset >> 8;
        EEADR = offset;

        EEDATA = value;

        EECON1bits.WREN = 1; //allows write cycles
        unsigned char value oldGIE = GIE; //interrupts be disabled during this code segment

        EECON2 = 0x55; //write sequence unlock
        EECON2 = 0xAA; //write sequence unlock

        EECON1bits.WR = 1; //initiates a data EEPROM erase/write cycle
        while(EECON1bits.WR); //waits for write cycle to complete

        GIE = oldGIE; //restore interrupts
        EECON1bits.WREN = 0; //disable write
    }

    #2
    1and0
    Access is Denied
    • Total Posts : 9291
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Pic18f26k83 read and write internal eeprom 2019/06/26 08:05:09 (permalink)
    +1 (1)
    pcbbc
    See here

    That eeprom18_write() misses this:
    GIE = 0; // disable interrupts

    and what is "value" doing here:
    unsigned char value oldGIE = GIE; //interrupts be disabled during this code segment

    ?
     
    #3
    pcbbc
    Super Member
    • Total Posts : 1096
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Pic18f26k83 read and write internal eeprom 2019/06/26 08:50:05 (permalink)
    +1 (1)
    1and0
    pcbbc
    See here

    That eeprom18_write() misses this:
    GIE = 0; // disable interrupts

    and what is "value" doing here:
    unsigned char value oldGIE = GIE; //interrupts be disabled during this code segment

    ?

    Good points - feedback to the pages owner please! pink: pink
     
    TBH all I did was confirm that this was an issue by compiling the project for myself, and then Googled the OPs error message.
    Which would have answered his question for him had he tried (and yielded the above page and code in the results).
    #4
    mbrowning
    Just a Member
    • Total Posts : 1422
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: Pic18f26k83 read and write internal eeprom 2019/06/26 08:53:42 (permalink)
    +1 (1)
    K83 register names are different. This code needs a lot of adapting.

    Oh well - there's always next year
    #5
    FR3D
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2018/08/29 04:19:00
    • Location: 0
    • Status: offline
    Re: Pic18f26k83 read and write internal eeprom 2019/06/26 22:29:19 (permalink)
    0
    Thank you for so much help,
     
    but the pic18f26k83 does not have these registers ...
     
    best regards FR3D
    #6
    mbrowning
    Just a Member
    • Total Posts : 1422
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: Pic18f26k83 read and write internal eeprom 2019/06/27 01:59:50 (permalink)
    +2 (2)
    I suggest you set up a minimal MCC project with just the Mem section. MCC will generate functions to read and write EE and Flash. Just copy the mem.c and mem.h files into your project. MCC generates reasonably concise and readable functions for this purpose - you can rename them if you want

    Oh well - there's always next year
    #7
    FR3D
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2018/08/29 04:19:00
    • Location: 0
    • Status: offline
    Re: Pic18f26k83 read and write internal eeprom 2019/06/27 05:20:17 (permalink)
    0
    Thank you,
     
    I wrote my own functions ... ok they are simple - but they seem to work for me ...
     
    void _NVMREG_EEPROM_WRITE(unsigned int addr, unsigned char value)                    
    {                                                        
         NVMCON1bits.REG0 = 0;
         NVMCON1bits.REG1 = 0;
         while (NVMCON1bits.WR)
        {                                
            continue;                                            
        }                                                        
        
        NVMADRL = addr;// + 0x18);
        NVMADRH = addr << 8;        
     
        NVMDAT = value;                                
        STATUSbits.CARRY = 0;                                    
        
        if (INTCON0bits.GIE)
        {                                    
            STATUSbits.CARRY = 1;                                
        }                                                        
        INTCON0bits.GIE = 0;                                        
        NVMCON1bits.WREN = 1;                                    
        NVMCON2 = 0x55;                                            
        NVMCON2 = 0xAA;                                            
        NVMCON1bits.WR = 1;                                        
        while (NVMCON1bits.WR) {                                
            continue;                                            
        }                                                        
        NVMCON1bits.WREN = 0;                                    
        if (STATUSbits.CARRY) {                                    
            INTCON0bits.GIE = 1;                                    
        }                                                        
    }            


    unsigned char _NVMREG_EEPROM_READ(unsigned int addr)
    {
        
            NVMCON1bits.REG0 = 0;
            NVMCON1bits.REG1 = 0;
        
            NVMADRL = addr;
            NVMADRH = addr << 8;    
          
            NVMCON1bits.RD = 1;
            return(NVMDAT);
    }                


    best regards
    #8
    ric
    Super Member
    • Total Posts : 22677
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Pic18f26k83 read and write internal eeprom 2019/06/27 05:31:07 (permalink)
    +1 (1)
    FYI, if you move the "wait for WR" loop to the start of the write function, and add it to the start of the read function too, then you will be able to write multiple bytes much faster.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    pcbbc
    Super Member
    • Total Posts : 1096
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Pic18f26k83 read and write internal eeprom 2019/06/27 05:44:11 (permalink)
    +1 (1)
    Using the carry flag to preserve the GIE state over compiler generated code seems fraught with danger.  Could you really not afford a single byte of storage?!
    Granted none of the intervening code LOOKS like it would generate a carry modifying instruction.  Luckily the while loop condition will probably use a BTF and not a compare.
    #10
    Jump to:
    © 2019 APG vNext Commercial Version 4.5