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.

CC2530 Writing to CODE memory from CPU



I am attempting to write to the CODE memory amidst my program, and the writes seem to be having no effect on the data stored in the flash, here is my code for writing:

 

uint8 writePairID(uint16 pairID)
{
   uint8 datas[2];
  
   //Break input down into bytes for fast transfer to FWDATA
   datas[0] = (uint8)(pairID & 0xFF);
   datas[1] = (uint8)((pairID >> 8) & 0xFF);
 
   //Disable interrupts
   EA = 0;
  
   //Erase Block 14 (starts @ 0x7000)
   FADDRH = (uint8)(14 << 1);
   FCTL |= ERASE;
   while(FCTL & BUSY);
  
   //Load address to write first byte of word to (0x7000)
   FADDRH = 0x70;
   FADDRL = 0x00;
  
   //Perform write of pair ID
   FCTL |= WRITE;
   FWDATA = datas[0];
   FWDATA = datas[1];
   FWDATA = 0x00;
   FWDATA = 0x00;
  
   //Wait for operation to finish
   while(FCTL & FULL);
   while(FCTL & WRITE);
  
   //Re-enable interrupts
   EA = 1;
  
   //Return 0 if operation fail
   if(FCTL & ABORT)
     return 0;
  
   else
     return 1;
}

 

I know the block is erased properly and when I attempt to read out the value I am attempting to store I read 0xFF, which is the "reset value"

 

Any helpful hints?

  • Hi,

    What about changing to

      //Load address to write first byte of word to (0x7000)
      
    FADDRH = (uint8)(14 << 1);
       FADDRL = 0x00;

    Best regards

  • Hello

    The code above works? I have the same code and I can not write

    unsigned char erase_page_num = 15; //page to erase

    ///* Erase one flash page - This works
    EA = 0; ///* disable interrupts
    while (FCTL & 0x80); //Busy
    FADDRH = erase_page_num << 1; // select the flash page via FADDRH[7:1] bits
    FCTL |= 0x01; // set FCTL.ERASE bit to start page erase
    while (FCTL & 0x80); //* optional: wait until flash write has completed (~20 ms)
    EA = 1; ///* enable interrupts
    //apagar páginas

    //Write into memory page 15 - This don't work
    EA = 0; // disable interrupts
    //Load address to write first byte of word to (0x7800)
    FADDRH =(uint8)(erase_page_num << 1);
    FADDRL = 0x00;

    //Perform write of pair ID
    FCTL |= 0x02;//Write
    FWDATA = 0x55;
    FWDATA = 0x44;
    FWDATA = 0x00;
    FWDATA = 0x00;

    //Wait for operation to finish
    while(FCTL & 0x40);//Full
    while(FCTL & 0x02);//Write
    EA = 1;

    //Read into Code memory 0x7800 - - This works
    uint16 offset=0xF800;
    uint8 *pData =(uint8 *)(offset);

    value = *pData;

    What I'm doing wrong?

    Thank you

  • Hello,

    Did you get any solution to write in flash.

    I cannot write in flash using above code. I also not getting FCTL .FULL or FCTL.BUSY set in case of erase, but it erage 0 or 1 page. Below is the code:

                                         /* disable interrupts */

       EA =0;
        while (FCTL & 0x80);                     /* poll FCTL.BUSY and wait until flash controller is ready */
        FADDRH = erase_page_num << 1;             /* select the flash page via FADDRH[7:1] bits */

        FCTL |= 0x01;                             /* set FCTL.ERASE bit to start page erase */


        while(FCTL & 0x80)                         /* optional: wait until flash write has completed (~20 ms) */
        {
            LAMP2 = 1;          // output pin led
        }
        EA = 1;

    LAMP2 will never glow, but page number 1 is erased.

    What may be reason. Can anyone help me?

    Thank you.