Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

EEPROM problem in PIC18F2320

Status
Not open for further replies.

arunbharathi.arasu

Full Member level 2
Full Member level 2
Joined
Feb 28, 2013
Messages
134
Helped
7
Reputation
14
Reaction score
6
Trophy points
1,298
Location
Chennai, Tamil Nadu, India
Activity points
2,151
Hi all,

I am using pic18f2320 for my project.
I want to store some value in INTERNAL EEPROM. I tried but could not get right result.

I cannot read data from EEPROM.
Even i dont know whether data is stored in to EEPROM or not.

here is the EEPROM coding for wright and read
Code:
#include <htc.h>#include <string.h>


#ifndef EEPROM_H
#define    EEPROM_H


unsigned char x,len,i,u;




void EEPROM_Write()
{
    EECON1bits.EEPGD = 0;    //Points to EEPROM
    EECON1bits.CFGS = 0;    //Points to Flash and EEPROM
    EECON1bits.WREN = 1;    //EEPROM Write Enable bit
    INTCONbits.GIE = 0;        //Disable all Interrupts
    EECON2 = 0x55;
    EECON2 = 0xAA;
    EECON1bits.WR = 1;        //WR Control bit initiates Write Operation
    INTCONbits.GIE = 1;
 
  // while(!PIR2bits.EEIF);
    Nop();
    Nop();
    Nop();


  //  PIR2bits.EEIF = 0;  
    EECON1bits.WREN = 0;
}


void EEPROM_Write_String(unsigned char msg[],unsigned char address)
{
    len = strlen(msg);
    for(i=0;i<len;i++)
    {
        EEADR = address + i;
        EEDATA = msg[i];
        EEPROM_Write();
    }
}
unsigned char EEPROM_Read(unsigned int add)
{
     
     EEADR=add;
    EECON1bits.EEPGD = 0;    //Point to EEPROM
    EECON1bits.CFGS = 0;    //Points to Flash and EEPROM
    EECON1bits.RD = 1;        //EEPROM Read Enable Bit
    u=EEDATA; 
    return(u);
}


#endif    /* EEPROM_H */


I used UART for other purpose, here im using UART for display read data.
main program is below
Code:
void main()
{
   UART_init();
   EEPROM_Write_String("Hello",0x500);    
   x = EEPROM_Read(0x500);
   trans_string(x);
   while(1);
}

UART is working fine. i can send some other data by using UART.


Please help me .
Thanks in advance.
 
Last edited:

Hi,

I assume 0x500 is the EEPROM address.
This is 1280 in decimal. Maybe the uC doesn't have that much EEPROM memory.

Additionally you write a whole string (6 bytes?), but read only one single byte


Klaus
 

Even i dont know whether data is stored in to EEPROM or not.

You can read EEPROM stored data with the programmer that you're using to download the firmware into target device.
 

here im using UART for display read data.
It is not yet clear whether you're facing to issues on reading or writing process (or both). As said above, use programmer capabilities to check at least if something was wrote there anywhere in EEPROM location, though wrong data.
 

Hi arunbharathi.arasu;

Your function EEPROM_Write() is wrong. Have to wait until the writing is done.
Try this one:
Code:
void EEPROM_Write()
{
    EECON1bits.EEPGD = 0;    //Points to EEPROM
    EECON1bits.CFGS = 0;    //Points to Flash and EEPROM
    EECON1bits.WREN = 1;    //EEPROM Write Enable bit
    INTCONbits.GIE = 0;        //Disable all Interrupts
    EECON2 = 0x55;
    EECON2 = 0xAA;
    EECON1bits.WR = 1;        //WR Control bit initiates Write Operation
    INTCONbits.GIE = 1; 

    While (EECON1bits.WR == 1); // wait until WR = 0 (6, max 10mS)

    EECON1bits.WREN = 0;
}
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top