EasyManuals Logo

Texas Instruments MSP430 User Manual

Texas Instruments MSP430
413 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #84 background imageLoading...
Page #84 background image
84
To write a byte, we need two things memory location and the value we wish to write. This memory
location is that piece of memory space where we wish to store the value.
void Flash_Write_Char(unsigned int address, char value)
{
char *FlashPtr = (char *)address;
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
FCTL3 = FWKEY; // Clear Lock bit
__bic_SR_register(GIE); // Disable Interrupts
*FlashPtr = value; // Save Data
while((FCTL3 & BUSY) == BUSY); // Busy
__bis_SR_register(GIE); // Enable Interrupts
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
Firstly, the address of the memory location where data is to be stored is pointed out. Flash write
process starts by setting the write bit, followed by removing the flash protection. Once these are done,
all interrupts are temporarily disabled to avoid any accidental write or illegal operation. The value to
be written is then pointed. Until the value is successfully written all other processes are halted. Once
the value to be stored is successfully written, interrupts are enabled, the write bit is cleared and the
flash lock is applied.
Reading the flash is simpler. We just have to point the location we wish to read.
char Flash_Read_Char(unsigned int address)
{
char value = 0x00;
char *FlashPtr = (char *)address;
value = *FlashPtr;
return value;
}
The process for erasing is similar to write processes. The only difference is Erase bit instead of Write
bit.
void Flash_Erase(unsigned int address)
{
char *FlashPtr;
FlashPtr = (char *)address;
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
__bic_SR_register(GIE); // Disable Interrupts
*FlashPtr = 0; // Dummy write to erase Flash
segment B
while((FCTL3 & BUSY) == BUSY); // Busy
__bis_SR_register(GIE); // Enable Interrupts
FCTL1 = FWKEY; // Lock
FCTL3 = FWKEY + LOCK; // Set Lock bit
}

Table of Contents

Other manuals for Texas Instruments MSP430

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Texas Instruments MSP430 and is the answer not in the manual?

Texas Instruments MSP430 Specifications

General IconGeneral
BrandTexas Instruments
ModelMSP430
CategoryMicrocontrollers
LanguageEnglish

Related product manuals