This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC430F6137 Flash memory problem

Other Parts Discussed in Thread: CC430F6137

Hello.

i have problem with flash memory in CC430F6137. My code is:

char kod;

          Flash_ptr = (char *)0x1900;
           kod = *Flash_ptr;

       if(kod==0x02){lcd2(0x0A22);}
       if(kod==0x03){lcd3(0x0A22);}
       if(kod==0x07){lcd7(0x0A22);}
       if(kod==0x00){lcd0(0x0A22);}

// save to flash

      if((P2IN & BIT5)==0) // 1
      {      lcd4(0x0A27);
            FCTL3 = FWKEY;                       // Clear Lock bit
            FCTL1 = FWKEY + WRT;                 // Set WRT bit for write operation
          Flash_ptr = (char *)0x1900; // Initialize Flash pointer
          FCTL3 = FWKEY; // Clear Lock bit
          FCTL1 = FWKEY + LOCK; // Set Erase bit
          *Flash_ptr = 0x01; // Dummy write to erase Flash seg
          lcd2(0x0A27);
      }

if this is the correct code. does not read the value written?

best regards

  • Your code is wrong.

    First you have to erase the addressed segment, as in following snippet

    //5xx Workaround: Disable global interrupt while erasing.
    //local variable to store GIE status
    uint16_t gieStatus;
    //Store current SR register
    gieStatus = __get_SR_register() & GIE;
    //Disable global interrupt
    __disable_interrupt();
    //Clear Lock bit
    FCTL3 = FWKEY;
    //Set Erase bit
    FCTL1 = FWKEY + ERASE;
    //Dummy write to erase Flash seg
    *Flash_ptr = 0;
    //test busy
    while (FCTL3 & BUSY);
    //Clear WRT bit
    FCTL1 = FWKEY;
    //Set LOCK bit
    FCTL3 = FWKEY + LOCK;
    //Restore SR register
    __bis_SR_register(gieStatus);

    Then, the sequence to write is:

    FCTL3 = FWKEY;                       // Clear Lock bit
    
    FCTL1 = FWKEY + WRT;                 // Set WRT bit for write operation
    
    *Flash_ptr = 0xAA; // assuming you want to write 0xAA at that address
    
    FCTL3 = FWKEY; // Clear Lock bit
    
    FCTL1 = FWKEY + LOCK; // Set Erase bit

    Regards,

    Peppe

  • hmm tell me how to read flash. Maybe I wrong reading flash because i can't read memory

  • Nothing special is required to read from flash... e.g.:

    char c = *Flash_ptr;

    reads the byte pointed by Flash_ptr into local variable c wherever it is (RAM/ROM or flash).

    Regards,

    Peppe

  • I do like is. how must be set to the frequency of the microprocessor? maybe this is problem? how to set up frequency?

  • Why CPU frequency should be a problem?

    For sure you can always read from flash without any special trick: your code is in flash, your C constants are in flash, initial value of global variables are in flash...

    You could have program/erase issue if current drawn from Vdd is limited below that needed to perform flash program/erase.

    Max. average currents are about 5 mA for program and 11 mA for erase (see datasheet).

    Note that these are average currents, so if you don't have enough bulk capacitance at Vdd, peak current could be 10 times greater.

    Regards,

    Peppe

  • hmm. Please send me example program how to write and read with flash :)

  • Again, a complete example of erase/program is in my first answer to your initial post above, nothing special is required to read.

    Or you could download the TI code examples for your MCU.

    Regards,

    Peppe

**Attention** This is a public forum