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.

Reading data from flash?

Should there be a problem to read data  directly from the flash in CC1110?

 I wrote a function that writes data to the flash and it works fine(I see the memory with the debugger).

Now I want to read it in order to verify it so I wrote a very simple checksum function.

I wrote a whole page (page 31) with 0x1 and then  ran this code.For some reason it returns junk and not 1024 which it should.

 ChkSum(0x7C00,1024)

 UINT16 ChkSum(UINT16 address,UINT16 NumOfBytes)
{
     UINT16 i,checksum=0;
     UINT8* FlashPtr=(UINT8*) address;
    
     for (i=0;i<NumOfBytes;i++)
      checksum+=(UINT16) FlashPtr[i];

    return checksum;
}

 

any idea? 

 

thanks 

  • Address and data pointer should be defined as "unsigned char code *".

     

    Different assembly instruction to read from CODE area of memory and therefore returned junk.

  • Does anyone know of some good conceptual articles/documentation that describes working with flash memory? It doesn't have to be specific to an MSP430..just looking for concepts on how to manage it and so forth.

     Thanks

  • mj: Yes, I see you figured it out yourself. The 8051 architecture has separate instructions for reading/loading data from 16-bit address. To load from CODE and XDATA memory space one will have to use "MOVC A, @DPTR" and "MOVX A, @DPTR", respectively. To make sure the compiler uses the correct instruction for accessing the memory (MOVC vs MOVX) one can specify whether a pointer points to CODE space or to XDATA space in the pointer declaration.

    For the Keil C51 compiler  this is done by adding the memory attribute keyword "code" or "xdata", while for the IAR C compiler these memory attributes are named "__code" and "__xdata", respectively. (If nothing is specified, I guess xdata is assumed as long as one uses a large memory model).