MSP430 problem with flash memory using mspflash.h library

Discussion in 'Homework Help' started by superpanky, Mar 11, 2019.

  1. superpanky

    Thread Starter New Member

    Mar 11, 2019
    1
    0
    I have wrote an Energia program for MSP430G2553 and I want to save variable "counter" (an integer number from 0-255) in non-volatile memory using mspflash.h library in case of reset or power interrupt. But it doesn't saves it. Can anyone help, what is wrong with this part of my code?

    #include "MspFlash.h"
    #define flash SEGMENT_D

    int pos=0;
    int counter=0;
    int p=0;

    void loop() {

    Flash.read(flash+(pos * sizeof(int)), (unsigned char*)&p, sizeof(int));

    if (.............) {
    counter=++counter;
    } else {
    counter=--counter;

    }

    Flash.erase(flash);

    Flash.write(flash+(pos * sizeof(int)), (unsigned char*)&counter, sizeof(int));

    }
     
Loading...