Sign in

Not a member? | Forgot your Password?

Search msp430

Search tips

Subscribe to msp430

Free PDF Downloads

Beginning Microcontrollers with the MSP430

Advanced Linux Programming

What Every Programmer Should Know About Memory

Introduction to Embedded Systems

C++ Tutorial

Embedded Systems - Theory and Design Methodology

Microcontroller Programming and Interfacing

Introduction to Microcontrollers


More Free PDF Downloads

Discussion Groups

See Also

ElectronicsDSPFPGA

Discussion Groups | MSP430 | Writing an int to Flash

The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.

Writing an int to Flash - dasGnu - Jul 11 9:15:57 2008

Hello,

I'm trying to store an int in Flash.... and reading it back after switching the device (a MSP430F2274) on.

"int command_time;" - is a global declared integer
"Flash_Settings" is specified in lnk_msp430f2274.cmd as "Flash_Settings = 0x10C0;"
and within the module as "extern volatile char Flash_Settings[2];"

The function to write is:

void settings_to_flash(){

_disable_interrupts();

BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
FCTL3 = FWKEY + LOCKA; // Clear LOCK & LOCKA bits
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
// write int to Flash
Flash_Settings[0] = (command_time>>8) & 0xFF;
Flash_Settings[1] = command_time & 0xFF;
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCKA + LOCK; // Set LOCK & LOCKA bit

init_dco(); // Set DCO back to working value

_enable_interrupts();
}

when reading back the int I never get the right values....?

Reading is done as:
command_time = Flash_Settings[0];
command_time |= Flash_Settings[1] >> 8;

What am I doing wrong? First I thought my shifting is wrong, but while debugging the values read from Flash are totally incorrect.
Maybe someone can help me out. Thanks,

Mitch
__________________________________________________________
Gesendet von Yahoo! Mail.
Dem pfiffigeren Posteingang.
http://de.overview.mail.yahoo.com




Re: Writing an int to Flash - sbur...@netvision.net.il - Jul 11 11:45:21 2008

One thing I see offhand, that you are setting the LOCKA bit where you are commenting that you are clearing it...if 0x10C0 is in INFO A on the device in question, that's at least part of the problem.

This is code for a 169, that works. Note lack of a LOCKA bit.

void WriteToFlash(char *addr, char *block,int len)
{
_DINT();
FCTL1 = FWKEY + WRT;
FCTL3 = FWKEY; // Clear Lock bit
memcpy(addr,block,len);
FCTL1 = FWKEY; // Clear Erase bit
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
_EINT();
}
Hello,
>
>I'm trying to store an int in Flash.... and reading it back after switching the device (a MSP430F2274) on.
>
>"int command_time;" - is a global declared integer
>"Flash_Settings" is specified in lnk_msp430f2274.cmd as "Flash_Settings = 0x10C0;"
>and within the module as "extern volatile char Flash_Settings[2];"
>
>The function to write is:
>
>void settings_to_flash(){
>
> _disable_interrupts();
>
> BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
> DCOCTL = CALDCO_1MHZ;
> FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
> FCTL3 = FWKEY + LOCKA; // Clear LOCK & LOCKA bits
> FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
> // write int to Flash
> Flash_Settings[0] = (command_time> > 8) & 0xFF;
> Flash_Settings[1] = command_time & 0xFF;
> FCTL1 = FWKEY; // Clear WRT bit
> FCTL3 = FWKEY + LOCKA + LOCK; // Set LOCK & LOCKA bit
>
> init_dco(); // Set DCO back to working value
>
> _enable_interrupts();
>}
>
>when reading back the int I never get the right values....?
>
>Reading is done as:
>command_time = Flash_Settings[0];
>command_time |= Flash_Settings[1] > > 8;
>
>What am I doing wrong? First I thought my shifting is wrong, but while debugging the values read from Flash are totally incorrect.
>Maybe someone can help me out. Thanks,
>
>Mitch
> __________________________________________________________
>Gesendet von Yahoo! Mail.
>Dem pfiffigeren Posteingang.
>http://de.overview.mail.yahoo.com
>
>
>


_____________________________
 Free pdf download: Beginning Microcontrollers with the MSP430.


Re: Writing an int to Flash - old_cow_yellow - Jul 11 12:25:36 2008

(1) LOCKA for F2xx is tricky. To unlock, use:
if (FCTL3 & LOCKA) FCTL3 |= (FXKEY | LOCK);
To lock, use:
if (~(FCTL3 & LOCKA)) FCTL3 |= (FXKEY | LOCK);

(2) In your F169 code, did you set FCTL2?

(3) If "addr" is odd and "len">1, does it work?

(4) If "addr" is even and "len">2, does it work?

--- In m..., sburck@... wrote:
>
> One thing I see offhand, that you are setting the LOCKA bit where
you are commenting that you are clearing it...if 0x10C0 is in INFO A
on the device in question, that's at least part of the problem.
>
> This is code for a 169, that works. Note lack of a LOCKA bit.
>
> void WriteToFlash(char *addr, char *block,int len)
> {
> _DINT();
> FCTL1 = FWKEY + WRT;
> FCTL3 = FWKEY; // Clear Lock bit
> memcpy(addr,block,len);
> FCTL1 = FWKEY; // Clear Erase bit
> FCTL3 = FWKEY + LOCK; // Reset LOCK bit
> _EINT();
> }
> Hello,
> >
> >I'm trying to store an int in Flash.... and reading it back after
switching the device (a MSP430F2274) on.
> >
> >"int command_time;" - is a global declared integer
> >"Flash_Settings" is specified in lnk_msp430f2274.cmd as
"Flash_Settings = 0x10C0;"
> >and within the module as "extern volatile char Flash_Settings[2];"
> >
> >The function to write is:
> >
> >void settings_to_flash(){
> >
> > _disable_interrupts();
> >
> > BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
> > DCOCTL = CALDCO_1MHZ;
> > FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash
Timing Generator
> > FCTL3 = FWKEY + LOCKA; // Clear LOCK &
LOCKA bits
> > FCTL1 = FWKEY + WRT; // Set WRT bit for
write operation
> > // write int to Flash
> > Flash_Settings[0] = (command_time> > 8) & 0xFF;
> > Flash_Settings[1] = command_time & 0xFF;
> > FCTL1 = FWKEY; // Clear WRT bit
> > FCTL3 = FWKEY + LOCKA + LOCK; // Set LOCK & LOCKA bit
> >
> > init_dco(); //
Set DCO back to working value
> >
> > _enable_interrupts();
> >}
> >
> >when reading back the int I never get the right values....?
> >
> >Reading is done as:
> >command_time = Flash_Settings[0];
> >command_time |= Flash_Settings[1] > > 8;
> >
> >What am I doing wrong? First I thought my shifting is wrong, but
while debugging the values read from Flash are totally incorrect.
> >Maybe someone can help me out. Thanks,
> >
> >Mitch
> > __________________________________________________________
> >Gesendet von Yahoo! Mail.
> >Dem pfiffigeren Posteingang.
> >http://de.overview.mail.yahoo.com
> >
> >
> >
> >
>

_____________________________
 Free pdf download: Beginning Microcontrollers with the MSP430.


Re: Writing an int to Flash - sbur...@netvision.net.il - Jul 12 17:18:15 2008

Old cow yellow -

I do set the FCTL2 in my code, but the value there is determined by the speed of his MCLK, so I left it out of the example.

The code works on a 169 in both of the cases you asked about.

Hello,
>
>I'm trying to store an int in Flash.... and reading it back after switching the device (a MSP430F2274) on.
>
>"int command_time;" - is a global declared integer
>"Flash_Settings" is specified in lnk_msp430f2274.cmd as "Flash_Settings = 0x10C0;"
>and within the module as "extern volatile char Flash_Settings[2];"
>
>The function to write is:
>
>void settings_to_flash(){
>
> _disable_interrupts();
>
> BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
> DCOCTL = CALDCO_1MHZ;
> FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
> FCTL3 = FWKEY + LOCKA; // Clear LOCK & LOCKA bits
> FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
> // write int to Flash
> Flash_Settings[0] = (command_time> > 8) & 0xFF;
> Flash_Settings[1] = command_time & 0xFF;
> FCTL1 = FWKEY; // Clear WRT bit
> FCTL3 = FWKEY + LOCKA + LOCK; // Set LOCK & LOCKA bit
>
> init_dco(); // Set DCO back to working value
>
> _enable_interrupts();
>}
>
>when reading back the int I never get the right values....?
>
>Reading is done as:
>command_time = Flash_Settings[0];
>command_time |= Flash_Settings[1] > > 8;
>
>What am I doing wrong? First I thought my shifting is wrong, but while debugging the values read from Flash are totally incorrect.
>Maybe someone can help me out. Thanks,
>
>Mitch
> __________________________________________________________
>Gesendet von Yahoo! Mail.
>Dem pfiffigeren Posteingang.
>http://de.overview.mail.yahoo.com
>
>
>