Suyog

Saving Variable value in FRAM (MSP430Fr5969)

7 posts in this topic

Hello All!

This is my first post on this forum. So kindly excuse me if i do any faux pas! I am planning to shift to MSP430 after using arduino for long time. 

I have written a small code to read ADC value and when i press a button adc value gets stored in a variable. Now want I want is to make available this value even after microcontroller restarts. 

Can anyone tell me how to store variable in Non volatile FRAM? I am using MSP430FR5969 launchpad. 

I have looked into following examples but they are of not helping me. I am using Energia to program my launchpad. 

 

 


#define buttonPin1 PUSH1
#define buttonPin2 PUSH2 // analog input pin to use as a digital input
 
#define ledPin1 RED_LED
#define ledPin2 GREEN_LED // digital output pin for LED 1 indicator
 
#define debounce 20 // ms debounce period to prevent flickering when pressing or releasing the button
#define holdTime 5000 // ms hold period: how long to wait for press+hold event
 
// Button variables
int buttonVal1 = 0; // value read from button
int buttonVal2 = 0;
 
int buttonLast1 = 0; // buffered value of the button's previous state
int buttonLast2 = 0;
 
long btnDnTime1; // time the button was pressed down
long btnDnTime2;
 
long btnUpTime1; // time the button was released
long btnUpTime2;
 
boolean ignoreUp1 = false; // whether to ignore the button release because the click+hold was triggered
boolean ignoreUp2 = false;
 
// LED variables
boolean ledVal1 = LOW;
boolean ledVal2 = LOW;
 
int sensorPin = A10;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
int freq = 0;
int low;
int high;
 
 
void setup() 
{
Serial.begin(9600);
// Set button input pin
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
 
// Set LED output pins
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(A11, OUTPUT);
 
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
 
}
 
void loop(){
  sensorValue = analogRead(sensorPin);
  
  if (sensorValue>=low&&sensorValue<=high){
  freq = map(sensorValue, low, high, 0, 1000);
  tone(A11, freq);
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, LOW);
  }
  
  if(sensorValue<low){
    digitalWrite(RED_LED, HIGH);
    digitalWrite(GREEN_LED, LOW);
    noTone(A11);
  }
  
  if (sensorValue>high){
    digitalWrite(GREEN_LED, HIGH);
    digitalWrite(RED_LED, LOW);
    noTone(A11);
  }
  Serial.print("SensorValue= ");
  Serial.print(sensorValue);
  Serial.print("\n");
  Serial.print("Freq= ");
  Serial.print(freq);
  Serial.print("\n");
  Serial.print("High= ");
  Serial.print(high);
  Serial.print("\n");
  Serial.print("Low= ");
  Serial.print(low);
  Serial.print("\n");
  
buttonVal1 = digitalRead(buttonPin1);
buttonVal2 = digitalRead(buttonPin2);
 
if (buttonVal1 == LOW && buttonLast1 == HIGH && (millis() - btnUpTime1) > long(debounce))
{
btnDnTime1 = millis();
}
 
if (buttonVal2 == LOW && buttonLast2 == HIGH && (millis() - btnUpTime2) > long(debounce))
{
btnDnTime2 = millis();
}
 
if (buttonVal1 == LOW && (millis() - btnDnTime1) > long(holdTime))
{
Low();
ignoreUp1 = true;
btnDnTime1 = millis();
}
 
if (buttonVal2 == LOW && (millis() - btnDnTime2) > long(holdTime))
{
High();
ignoreUp2 = true;
btnDnTime2 = millis();
}
 
buttonLast1 = buttonVal1;
buttonLast2 = buttonVal2;
 //delay(5000);
}
 
void Low(){
Serial.println("Low Value Set");
Serial.println(low);
    low=sensorValue;
    tone(A11, 1500);
    digitalWrite(ledPin1, HIGH);
    delay(3000);
    digitalWrite(ledPin1, LOW);
}
 
void High(){
Serial.println("High Value Set");
Serial.println(high);
    high=sensorValue;
    tone(A11, 2000);
    digitalWrite(ledPin2, HIGH);
    delay(3000);
    digitalWrite(ledPin2, LOW);
  }
 

 

 

 

 

http://forum.43oh.com/topic/4148-reduce-startup-time-on-msp430fr5739/

http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/258443

http://processors.wiki.ti.com/index.php/Creating_MSP430_FRAM_Variables_Using_CCS#Example_Test_Code

 

Share this post


Link to post
Share on other sites

See here: http://forum.43oh.com/topic/5474-energia-and-wolverine-tips/

 

Sent from my Galaxy Note II with Tapatalk 4

I did following modification in my energia code but after restarting i am getting garbage value! Not the one which was saved when pressing button.

 

int low __attribute__ ((section (".noinit"))) = 0xC200;
int high __attribute__ ((section (".noinit"))) = 0xC400;

Share this post


Link to post
Share on other sites

Hi

with .text garbage value is getting saved when i press button. 

 

 

int low __attribute__((section(".infomem")));
int high __attribute__((section(".infomem"))); 
 
 
is working for me as of now let me power on launch pad after long time. And by tomorrow i will let you know if its still working or not :D Thanks man!

Share this post


Link to post
Share on other sites

That's odd, .text should save values fine across reset EXCEPT when you upload a new sketch- then it gets reinitialized.

 

Sent from my Galaxy Note II with Tapatalk 4

Share this post


Link to post
Share on other sites

i did started launchpad after a long time no loss of memory. as of now i am sticking with infomem. As i get familiar with MSP430 and embedded C we can investigate this issue further 

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