mihaita21

msp flash not working (MSP430F5529)

2 posts in this topic

Hello guys i wrote a simple code with a intrerupt on button 2 on MSP430F5529 when i hit the button 2 int should save in flash but when i disconect my microcontroler the variable reset please help me.

#include <Wire.h> 
#include "LiquidCrystal_I2C.h"

#include "MspFlash.h"
#define flash SEGMENT_D
#define flash1 SEGMENT_C

byte address = 0x27;      // LCD I2C address
int columns = 20;         // number of columns on LCD
int rows = 2;             // number of rows on LCD
LiquidCrystal_I2C lcd(address, columns, rows);

int i1=20;
int *pi1=&i1;
int i2=0;
int *pi2=&i2;

int i11=30;
int *pi11=&i11;
int i22=0;
int *pi22=&i22;

void setup()
{
  Serial.begin(9600);
  pinMode(GREEN_LED, OUTPUT);
  lcd.init();
  pinMode(PUSH2, INPUT_PULLUP);
  attachInterrupt(PUSH2, blink1, FALLING); // Interrupt is fired whenever button is pressed
}
void loop()
{
  i1=i1+1;
  i11=i11+1;
  digitalWrite(GREEN_LED,HIGH);
 delay(100);
 digitalWrite(GREEN_LED,LOW);
 delay(100);
 lcd.setCursor(0,0);
 lcd.print(i2);
 lcd.setCursor(0,1);
 lcd.print(i22);
}
void blink1()
{
 Flash.erase(flash); 
 Flash.write(flash,(unsigned char*) pi1,sizeof(int)); 
 Flash.read(flash,(unsigned char*) pi2,sizeof(int));

 Flash.erase(flash1); 
 Flash.write(flash1,(unsigned char*) pi11,sizeof(int)); 
 Flash.read(flash1,(unsigned char*) pi22,sizeof(int));
}

 

Share this post


Link to post
Share on other sites

The variables i2 and i22 are normal variables (in RAM), and are automatically reinitialized whenever the device resets.

The only place where you read from the flash is in the blink1() function. To get the values from the flash, you must read from the flash at the beginning of the program.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now