|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Writing an int to FlashHello,
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 [Non-text portions of this message have been removed] |
|
|
Re: Writing an int to FlashYou do not need any shifting or masking. In stead of:
Flash_Settings[0] = (command_time>>8) & 0xFF; Flash_Settings[1] = command_time & 0xFF; what you really need is: mov.w &command_time, &0x10C0; --- In msp430@..., dasGnu <dasgnudas@...> wrote: > > 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 > 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 > Maybe someone can help me out. Thanks, > > Mitch > > > __________________________________________________________ > Gesendet von Yahoo! Mail. > Dem pfiffigeren Posteingang. > http://de.overview.mail.yahoo.com > > [Non-text portions of this message have been removed] > |
|
|
Re: Writing an int to FlashTake a look in the code samples from TI:
http://www.ti.com/lit/zip/slac123 There are several examples that explain the flash writing procedure. You also should erase the flash before you write to it. But keep in mind that you only can erase a whole flash-segment (that is 64 or 128 Bytes) @OCY You are mixing assembler into C ;-) --- In msp430@..., "old_cow_yellow" <old_cow_yellow@...> wrote: > > You do not need any shifting or masking. In stead of: > Flash_Settings[0] = (command_time>>8) & 0xFF; > Flash_Settings[1] = command_time & 0xFF; > what you really need is: > mov.w &command_time, &0x10C0; > > --- In msp430@..., dasGnu <dasgnudas@> wrote: > > > > 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 & > > > > 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 > > > > [Non-text portions of this message have been removed] > > > |
|
|
|
|
|
Re: Writing an int to Flash(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 msp430@..., 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 > > > >"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 > > 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 > >Maybe someone can help me out. Thanks, > > > >Mitch > > __________________________________________________________ > >Gesendet von Yahoo! Mail. > >Dem pfiffigeren Posteingang. > >http://de.overview.mail.yahoo.com > > > >[Non-text portions of this message have been removed] > >------------------------------------ > > > > > |
|
|
|
| Free Forum Powered by Nabble | Forum Help |