3287 views|0 replies
- Last login
- 2023-11-13
- Online Time
- 65 hours
- Prestige
- 132 points
- Points
- 8 points
|
The data written into the flash memory is inconsistent with the data read out. Why?
[Copy link]
Today I tried to read and write flash, modified from TI official code, I prepared a variable, but what was written in and what was read out were inconsistent. Please help me find out. 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 } //Clock initialization 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; // Configure ACLK matching capacitor }
|
|