how to write a variable in rl78g15 in dataflash/eeprom (save even after power off) and read it?

i am using rl78g15 new 20 pin controller , in application need to store the varible in eeprom and fetch after power transition (last state of the varible),please support

thanks in advance..... 

  • Hello,

    thank you for sharing details here will see how much i can help you 

    To store a variable in EEPROM on the RL78G15 microcontroller, you can use the built-in data flash memory, which can be programmed in-system. Here's a general overview of the steps you can follow:

    Define a variable to be stored in EEPROM. Let's say this variable is called "myVar".

    Declare a pointer to the EEPROM location where you want to store the variable. For example, if you want to store the variable at address 0x4000 in data flash memory, you can declare a pointer as follows:

    Copy code
    volatile unsigned char *eeprom_ptr = (volatile unsigned char *) 0x4000;
    Write the variable to EEPROM using the pointer. You can use the built-in data flash programming functions to do this. Here's an example:
    Copy code
    * eeprom_ptr = myVar;
    FLASH.DFLRE = 0x0A; // set DFLRE bit to start programming
    while(FLASH.DFLRE != 0); // wait for programming to complete
    Note that you need to set the DFLRE bit to start programming, and wait for the programming to complete before accessing the data flash memory again.

    To read the variable from EEPROM after power transition, you can simply read it from the same EEPROM location using the pointer. Here's an example:
    Copy code
    myVar = * eeprom_ptr;
    Make sure to initialize the variable to a known value before reading from EEPROM, in case it has not been previously programmed.

    I hope this helps! Let me know if you have any further questions. 

  • Thanks sir it is working for read perfectly .

Reply Children
No Data