3287 views|0 replies

51

Posts

1

Resources
The OP

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 }
This post is from Microcontroller MCU

Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

    Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list