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..... 

Parents
  • Define the variable you want to store in dataflash or EEPROM. For example, if you want to store an integer value, you can define it like this:
    int myVar = 1234;
    Declare the memory location where you want to store the variable. For example, if you want to store the variable in EEPROM, you can declare a memory address like this:
    c

    #pragma location = 0xF000
    __root const int myVar_eeprom = myVar;
    Here, we've used the #pragma directive to specify the memory location 0xF000 for the myVar_eeprom variable. We've also used the __root attribute to ensure that the variable is not optimized out by the compiler.

    If you want to store the variable in dataflash, you can use a similar approach but with a different memory location. For example:
    c
    #pragma location = 0x4000
    __root const int myVar_dataflash = myVar;
    Here, we've used the #pragma directive to specify the memory location 0x4000 for the myVar_dataflash variable.

    Finally, you can write the variable to the appropriate memory location using a function like DataFlash_Write or EEPROM_Write. The specific function you use will depend on the type of memory you're using and how you've configured it. For example, if you're using EEPROM, you could write the variable like this:
    scss

    EEPROM_Write(&myVar_eeprom, &myVar, sizeof(myVar));
    Here, we're using the EEPROM_Write function to write the myVar variable to the myVar_eeprom memory location. We're also specifying the size of the variable using sizeof(myVar).

Reply
  • Define the variable you want to store in dataflash or EEPROM. For example, if you want to store an integer value, you can define it like this:
    int myVar = 1234;
    Declare the memory location where you want to store the variable. For example, if you want to store the variable in EEPROM, you can declare a memory address like this:
    c

    #pragma location = 0xF000
    __root const int myVar_eeprom = myVar;
    Here, we've used the #pragma directive to specify the memory location 0xF000 for the myVar_eeprom variable. We've also used the __root attribute to ensure that the variable is not optimized out by the compiler.

    If you want to store the variable in dataflash, you can use a similar approach but with a different memory location. For example:
    c
    #pragma location = 0x4000
    __root const int myVar_dataflash = myVar;
    Here, we've used the #pragma directive to specify the memory location 0x4000 for the myVar_dataflash variable.

    Finally, you can write the variable to the appropriate memory location using a function like DataFlash_Write or EEPROM_Write. The specific function you use will depend on the type of memory you're using and how you've configured it. For example, if you're using EEPROM, you could write the variable like this:
    scss

    EEPROM_Write(&myVar_eeprom, &myVar, sizeof(myVar));
    Here, we're using the EEPROM_Write function to write the myVar variable to the myVar_eeprom memory location. We're also specifying the size of the variable using sizeof(myVar).

Children
No Data