The TI documentation implies that bytes can be written as readily as words,
however, there are no specific instructions are in the programming information
that differentiates between the two different word lengths (integer or byte).

Since the MSP block diagram shows 16 bit access to the internal data paths, I
can only assume that byte write instructions must leave/program the un-accessed
byte with 1's. (and thus programs the unaccessed byte, although nothing
"appears" to happen.)

As was correctly stated previously, writing ones to flash will have no effect,
leaving the bits alone so that they may be programmed low in the future (also
true for many "true" flash memory devices, although some are "backwards", In
that erasure leaves the cell reading back a '0', so you need to check the data
sheets before committing yourself!) I can only assume that bit access is part of
a read, modify write cycle, and that this will also leave bits already set to
"one" in the same state.

What nobody seems to have discussed is the flash timing generator. There are
specific upper and lower limits placed on the flash timing generator. Having
said that, I have had no difficulties programming the flash with whatever the
defaults for this are after reset, It was quit some time before I discovered
there was a way of setting the flash timing. (Data manual? Who completely reads
that?), although I now set the divisor to 17 for the flash timing clock just to
be on the safe side! (I am using an 8 MHz MCLK as the source)

IE: The following are the 'C' routines I use. There are undoubtably more
efficient ways to do this, but this is a least "general", and I have had no
problems using MSP430f149's using these routines. (But, these devices do have a
lot a flash ...) Notice that the only difference between byte and word operation
lies in the declarations, no difference in the code (except that the compiler
will use either a byte or a word operation)


//------------------------------------------------------------------------------
----------------------
// Set up the Flash Timing Generator
//
// Appears that the Flash requires the timing generator to be set for a
frequency between
// 257 .. 476 kilohertz. (See Page 37 of SLAS272C - JULY 2000 - REVISED FEBRUARY
2001)(msp430f149.pdf)
//------------------------------------------------------------------------------
----------------------


void SetupFlashWrite(void)
{

  FCTL2 = FWKEY | FSSEL0 | 17;   // MCLK for Flash Timing Generator, MCLK/17 =
470 kHz = flclk
  FCTL3 = FWKEY + LOCK;          // Reset LOCK bit (prohibit writes) (This
should not really be required.)
}

//------------------------------------------------------------------------------
----------------------
// Erase one segment of flash memory.
//------------------------------------------------------------------------------
----------------------

// Note: writing to flash could disturb the real time clock (interrupts are
disabled.)

void EraseFlashSeg(unsigned int *addr)
{

  _DINT();                                                              // 
Disable interrupts absolutely required
  FCTL1 = FWKEY + ERASE;         // Set Erase bit
  FCTL3 = FWKEY;                 // Clear Lock bit
  *addr = 0xFF;                         // Dummy write to erase Flash segment
  FCTL1 = FWKEY;                 // Clear WRT bit
  FCTL3 = FWKEY + LOCK;          // Reset LOCK bit
  _EINT();                                                              // 
Re-enable the ints
}

//------------------------------------------------------------------------------
----------------------
// programs 1 BYTE (8 bits) into the flash memory
//------------------------------------------------------------------------------
----------------------

void WriteFlashByte(unsigned char *addr, unsigned char data)
{

  _DINT();                                                              // 
Disable interrupts absolutely required
  FCTL1 = FWKEY + WRT;           // Set WRT bit for write operation
  FCTL3 = FWKEY;                 // Clear Lock bit
  *addr = data;                  // Write byte value to flash
  FCTL1 = FWKEY;                 // Clear WRT bit
  FCTL3 = FWKEY + LOCK;          // Reset LOCK bit
  _EINT();                                                              // 
Re-anable the interrupts
}


//------------------------------------------------------------------------------
----------------------
// programs 1 word (16 bits) into the flash memory
//------------------------------------------------------------------------------
----------------------

void WriteFlashWord(unsigned int *addr, unsigned int data)
{

  _DINT();                                                              // 
Disable interrupts absolutely required
  FCTL1 = FWKEY + WRT;           // Set WRT bit for write operation
  FCTL3 = FWKEY;                 // Clear Lock bit
  *addr = data;                  // Write word value to flash
  FCTL1 = FWKEY;                 // Clear WRT bit
  FCTL3 = FWKEY + LOCK;          // Reset LOCK bit
  _EINT();                                                              // 
Re-anable the interrupts
}


//------------------------------------------------------------------------------
----------------------


Appendix C of the TI document "slau049.pdf" seems to cover the flash thoroughly.

Cheers
Harry


-----Original Message-----
From: mspgcc-users-ad...@lists.sourceforge.net
[mailto:mspgcc-users-ad...@lists.sourceforge.net]on Behalf Of Steve Underwood
Sent: Sunday, December 07, 2003 1:02 PM
To: mspgcc-users@lists.sourceforge.net
Subject: Re: [Mspgcc-users] Re: 2x 128Bytes self read/write

Daniel Néri wrote:

>Steve Underwood <ste...@coppice.org> writes:
>
>
>
>>You can't write bytes. You have to write whole 16 bit words.
>>
>>
>
>Sorry, but this is simply not true. MSP430 flash memory is bit-, byte-
>and word-programmable.
>
>
Then tell us how. The rest of us only know how to program whole 16 bit
words, including the chip's designers. Everyone else gets the effect of
programming a bit or byte in the way I described. You write a whole
word, where the bit you don't want to change are set to 1.

Regards,
Steve




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id78&alloc_id371&opÌk
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users


Reply via email to