Jump to content
43oh

msp flash not working (MSP430F5529)


Recommended Posts

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));
}

 

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...