S32K148 EEPROM write double type when data error?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K148 EEPROM write double type when data error?

863 Views
kongdetao
Contributor III

Now start the EEPROM function on the S32K148 EVB board, then write double type data to the area and report an error.

 

The system has entered the default ISR. Has any of the experts encountered this problem?

 

code show as below:

{

Double doubleW = 2.1f;

...

EEE_WriteDouble(0x14000000, doubleW);

}

Int EEE_WriteDouble(uint32_t globalAddr, double val)
{

  While ((FTFC-> FSTAT & FTFC_FSTAT_CCIF_MASK) == 0){}

  *((double *)globalAddr) = val;
  Return 0;
}

Labels (1)
4 Replies

676 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

you can write to EEEPROM data up to 4 bytes. If you have more bytes (array or double value in your case) you need to split your data into 4 byte parts. Here is example how to write byte array:

int EEE_Write_ByteArray(char* source,char* target,unsigned int size)
{
   unsigned int cycles=size/4;
   unsigned int remain=size%4;
   unsigned int offset=0;
   for (int i=0;i<cycles;i++)
   {
      while ((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0){}
      *(int*)(target+offset)=*(int*)(source+offset);
      offset+=4;
   }

   for (int i=0;i<remain;i++)
   {
      while ((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0){}
      *(target+offset)=*(char*)(source+offset);
      offset+=1;
   }

   return 0;
}

Jiri

676 Views
kongdetao
Contributor III

Thanks very much!!

Can you give an example for writing double type?

0 Kudos

676 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

you can use function for ByteArray write mentioned above: 

double YourDoubleValue=3.141592


EEE_Write_ByteArray((char*)(&YourDoubleValue),(char*)&YourDoubleTarget,8);

Or feel free to write your own function. Don't forget that YourDoubleTarget should be located in EEERAM section. 

Jiri

676 Views
kongdetao
Contributor III

Thanks very much!

Fixed the Issue!!

0 Kudos