请问各位大哥,F149要对FLASH写时。是不是把430程序停了就可以进行 ,请各位详细指点一下,小弟谢谢。
程序的要求是第一次程序用JTAG口烧到430里。然后程序进行到一定时间时要对FLASH里的几个数进行修改,下次RESET时CPU程序直接用新的参数。
请问可否实现。。。谢谢!!!
可以实现
1、先清后写,清除时需要一次清除整个段(128b)。
2、写时,最好一个个字节写入,连续进行就能写多字节。
3、在进行FLASH清除和写操作时,关掉所有中断,并且电源电压不要低于2.7V
4、以后直接读就可以了(向RAM变量一样)。
参考下面程序:
//****************************************************************************
// MSP-FET430P140 Demo - Flash In-System Programming
//
// Description; This program first erases flash seg A, then it increments all
// values in seg A, then it erases seg B, then copies seg A to seg B.
// Assumed MCLK 550kHz - 900kHz.
//
// MSP430F149
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
//
// M. Mitchell
// Texas Instruments, Inc
// September 2003
// Built with IAR Embedded Workbench Version: 1.26B
// December 2003
// Updated for IAR Embedded Workbench Version: 2.21B
//******************************************************************************
#include <msp430x14x.h>
char value; // 8-bit value to write to segment A
// Function prototypes
void write_SegA (char value);
void copy_A2B (void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FCTL2 = FWKEY + FSSEL0 + FN0; // MCLK/2 for Flash Timing Generator
value = 0; // initialize value
while(1) // Repeat forever
{
write_SegA(value++); // Write segment A, increment value
copy_A2B(); // Copy segment A to B
}
}
void write_SegA (char value)
{
char *Flash_ptr; // Flash pointer
unsigned int i;
Flash_ptr = (char *) 0x1080; // Initialize Flash pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<128; i++)
{
*Flash_ptr++ = value; // Write value to flash
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
}
void copy_A2B (void)
{
char *Flash_ptrA; // Segment A pointer
char *Flash_ptrB; // Segment B pointer
unsigned int i;
Flash_ptrA = (char *) 0x1080; // Initialize Flash segment A pointer
Flash_ptrB = (char *) 0x1000; // Initialize Flash segment B pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptrB = 0; // Dummy write to erase Flash segment B
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<128; i++)
{
*Flash_ptrB++ = *Flash_ptrA++; // copy value segment A to segment B
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
}