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.

CCS/MSP430G2553: Store Float value into flash

Part Number: MSP430G2553


Tool/software: Code Composer Studio

Hi,

I wanted to know hoe to store float value into flash, into 2 words or 4 bytes? 

thank you all.

  • const double var1;

    Or

    const float var1;

    Stephen
  • Thank you for the reply
    But, i want to write it in information memory or main memory
    for now i establish to write char short and long (2 shorts) into the memory.
  • Hello Joe,

    I am confused. In your initial post, you said you wanted to place the floating point number in flash.  Adding const to the variable declaration will place the variable in flash.

    Could you please post a small snippet of code that shows what you are currently doing.

    Thanks,

    Stephen

  • here's an example of writing char data into memory

    void WriteToFlash(char* address, char val)
    {
    	char* flash_ptr;
    	FCTL3 = FWKEY;
    	flash_ptr = address;              // Initialize Flash pointer
    	while(FCTL3 & BUSY);
    	FCTL1 = FWKEY + WRT;
    	*flash_ptr = val;
    	while(FCTL3 & BUSY);
    	FCTL1 = FWKEY;                            // Clear WRT bit
    	FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
    }
    

    her's another example to write long data:

    	WriteShortToFlash((short*)MEM_SLOPE_H,(short)(wt_slope & 0xFFFF));// Slope
    	WriteShortToFlash((short*)MEM_SLOPE_L,(short)((wt_slope >> 16) & 0xFFFF));// Slope
    
    void WriteShortToFlash(short* address, short val)
    {
    	short* flash_ptr;
    	FCTL3 = FWKEY;
    	flash_ptr = address;              // Initialize Flash pointer
    	while(FCTL3 & BUSY);
    	FCTL1 = FWKEY + WRT;
    	*flash_ptr = val;
    	while(FCTL3 & BUSY);
    	FCTL1 = FWKEY;                            // Clear WRT bit
    	FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
    }
    

    I want to know how to write a float to memory

    Thank you for your help

  • Ok. I think the following should work.

    Stephen

    float var1 = 3.14159;
    unsigned long int wt_slope;
    
    
    int main(void)
    {
        wt_slope =  *(unsigned long int*)&var1;
        WriteShortToFlash((short*)MEM_SLOPE_H,(short)(wt_slope & 0xFFFF));// Slope
        WriteShortToFlash((short*)MEM_SLOPE_L,(short)((wt_slope >> 16) & 0xFFFF));// Slope
    }

  • Did that solve your issue? If so, please select verify.

    Thanks,
    Stephen