今天尝试 读写flash,改自TI官方代码,我准备了一个变量,可写入进去的和读出的不一致,请大家帮我看看。
void write_SegC (unsigned int *array)
{
unsigned char *Flash_ptr; // Flash pointer
Flash_ptr = (unsigned char *) 0x1040; // 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
*Flash_ptr++ = *array; // Write value to flash }
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
void read (void)
{
unsigned char *Flash_ptrC; // Segment C pointer
unsigned char *Flash_ptrD; // Segment D pointer
Flash_ptrC = (unsigned char *) 0x1040; // Initialize Flash segment C pointer
Flash_ptrD = (unsigned char *) 0x1000; // Initialize Flash segment D pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptrD = 0; // Dummy write to erase Flash segment D
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
*value = *Flash_ptrC++; // copy value segment C to segment D
Nor_Val = value[0];
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
//时钟初始化
void Clk_Init(void)
{
if (CALBC1_8MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_8MHZ; // Set range
DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation */
BCSCTL2 |= SELM_1 + DIVM_3;
FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
//BCSCTL3 |= XT2S0 + LFXT1S0 + XCAP_3; //配置ACLK匹配电容
}