I'm trying to save some floating values to the Data flash of my Nuc220(ARM-M0 32 bit) Microcontroller using ISP procedure.
FMC->ISPCMD = FMC_ISPCMD_PROGRAM; /* Set ISP Command Code */
FMC->ISPADR = 0x10000; /* Set Target ROM Address. The address must be word alignment. */
FMC->ISPDAT = 22.5; /* Set Data to Program */
FMC->ISPTRG = 0x1; /* Trigger to start ISP procedure */
__ISB(); /* To make sure ISP/CPU be Synchronized */
while(FMC->ISPTRG); /* Waiting for ISP Done */
FMC->ISPCMD = FMC_ISPCMD_READ; /* Set ISP Command Code */
FMC->ISPADR = 0x10000; /* Set Target ROM Address. The address must be word alignment. */
FMC->ISPTRG = 0x1; /* Trigger to start ISP procedure */
__ISB(); /* To make sure ISP/CPU be Synchronized */
while(FMC->ISPTRG); /* Waiting for ISP Done */
dataFloat = (float)(FMC->ISPDAT);
But the value read is 22.0 instead of 22.5 , I also get a warning of, 'implicit conversion to integer' while compilation. How can I do this without error?
float
andint
have the same size and alignment requirements:float f = 2.5f; int *p = (int *) &f ; FMC->ISPDAT = *p;
Using a union is probably cleaner though; I'm sure you can find a full example with some searching - you can probably set it up with int, float, and raw bytes fields, etc. \$\endgroup\$