About the read and write operation method of MSP430-Flash exceeding 64K
#include "msp430xG46x.h"
void WriteFlashErrorNum(void);
//----------------------------------------------------------------------
//Function: Read data from flash, just need to give the first address and the number of data to be retrieved
// Input: waddr is the address of the flash, length is the data length
// Output: None
//----------------------------------------------------------------------
void ReadFlash(unsigned long int waddr,unsigned int length)
{
unsigned char i=0;
if(FlashMangleFlag==0)
{
while(FCTL3 & BUSY);
if(length>64) length=64;
while(length--)
{
Internal_flashdata[i++]=__data20_read_char(waddr++);
}
}
}
//----------------------------------------------------------------------
//Function: segment erase;
//Date: 2006.12.13
// Input: waddr is the address of the flash,
// Output: None
//----------------------------------------------------------------------
//void EraseFlashOneBlock(unsigned long int waddr)
void EraseFlash(unsigned long int waddr)
{
if(FlashMangleFlag==0)
{
if((waddr>=0x1f400) && (waddr<0x20000))
{
while(FCTL3 & BUSY);
_DINT();
FCTL2 = FWKEY + FSSEL1 + FN4;
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY + ERASE; // Set Erase bit
__data20_write_char(waddr,0); // Dummy write to erase Flash segment
while(FCTL3 & BUSY);
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
_UNITE();
}
}
}
//----------------------------------------------------------------------
//Function: write data to flash;
//Date: 2006.12.13
// Input: waddr is the address of the flash, length is the data length, *buf is the pointer to the data
// Output: None
//----------------------------------------------------------------------
unsigned char WriteFlash(unsigned long int waddr,unsigned char *buf,unsigned int length)
{
unsigned int i;
unsigned char temp,ErrorFlag = 0;
if(FlashMangleFlag==0)
{
if((waddr>=0x1f400) && (waddr<0x20000))
{
while(FCTL3 & BUSY);
_DINT();
FCTL2 = FWKEY + FSSEL1 + FN4;
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for(i=0;i { __data20_write_char(waddr,*buf); // Write value to flash temp = __data20_read_char(waddr); // Read one byte if(temp!=(*buf)) // Determine whether the read data is equivalent to the written data { ErrorFlag = 1; //Write flash operation error flag ErrorFlashNum ++ ; } waddr++;buf++; } while(FCTL3 & BUSY); FCTL1 = FWKEY; FCTL3 = FWKEY + LOCK; // Reset LOCK bit _UNITE(); if(ErrorFlag == 1) WriteFlashErrorNum(); } } return ErrorFlag; }
Previous article:About the operation of internal Flash of Msp430 Flash microcontroller
Next article:MSP430 FLASH structure InfoA (1080H-10FFh) and InfoB (1000H-10FFH)
Recommended ReadingLatest update time:2024-11-15 14:32
- Popular Resources
- Popular amplifiers
- Automotive Electronics S32K Series Microcontrollers: Based on ARM Cortex-M4F Core
- EDA Technology Practical Tutorial--Verilog HDL Edition (Sixth Edition) (Pan Song, Huang Jiye)
- ARM Embedded System Principles and Applications (Wang Xiaofeng)
- Deep Understanding of Linux Driver Design (Tsinghua Developer Library) (Wu Guowei, Yao Lin, Bi Chenglong)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- EEWORLD University Hall----Project Production: Intelligent Access Control System
- Ask for advice
- Which domestic half-bridge driver product is the best?
- Study on TMS570LS3137
- AT32F425-Evaluation Report-Upper Computer Development 04
- The quickest way to set the plug-in through-hole pin pad of a multi-layer board to appear on only one side in Altium Designer
- Can 'ice' be used as a semiconductor material?
- 【NUCLEO-L552ZE Review】- 8 : TrustZone
- 【Qinheng Trial】8. FlashROM
- The Agilent oscilloscope cannot be started and keeps stopping at the self-test position. What should I do?