S32K148 EEPROM write double type when data error?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

S32K148 EEPROM write double type when data error?

1,921 次查看
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;
}

标签 (1)
标记 (3)
4 回复数

1,734 次查看
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

1,734 次查看
kongdetao
Contributor III

Thanks very much!!

Can you give an example for writing double type?

0 项奖励
回复

1,734 次查看
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

1,734 次查看
kongdetao
Contributor III

Thanks very much!

Fixed the Issue!!

0 项奖励
回复