S12G128 Writing Struct to EEPROM

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

S12G128 Writing Struct to EEPROM

1,239件の閲覧回数
rayhall
Contributor V

If I use this code, which is from the EEPROM example for the S12G128, the values in buf are written to EEPROM correctly.

 

#define EEPROM_START    0x000400

 

byte err;

word buf[4] = {0xAABB, 0xCCDD, 0x1122, 0x3344};

 

err = EEPROM_Program(EEPROM_START, buf, 4);

 

 

When I try to write my structure to EEPROM it does not write anything. This is my method.

 

struct StructData {

   byte startChar;

   byte packetSize;

   byte packetId;

   byte freq;

   byte frame1Enabled;

   byte frame2Enabled;

   byte frame3Enabled;

   word idEgt1to4;

   word idEgt5to8;

   word idVoltInput;

   byte setupMode;

}data;   // 14 bytes or 7 words

 

unsigned int size = sizeof(data) / 2;

 

err = EEPROM_Program(EEPROM_START, (word *)&data, size);

 

 

What am I missing

 

Ray.

ラベル(1)
0 件の賞賛
返信
4 返答(返信)

987件の閲覧回数
rayhall
Contributor V

I think I have found the problem...I will confirm this and report back in a few hours.

It is the EEPROM_Program() function has this statement that would stop sending any more then four words. Why it is there is a mystery to me and is just a trap for many people.

if((number_of_words < 1) || (number_of_words > 4))

    return LENGTH_OUT_OF_RANGE;

0 件の賞賛
返信

987件の閲覧回数
rayhall
Contributor V

That did not fix the problem. It looks like the maximum number of words you can write to EEPROM is 4. What is the use of EEPROM if it is so limited, or is there something I am missing.

Ray.

0 件の賞賛
返信

987件の閲覧回数
rayhall
Contributor V

I have got it now...The EEPROM must be written in blocks of 8 bytes (4 x words). The start address needs to be indexed by 8 bytes before the next write.

Ray.

0 件の賞賛
返信

986件の閲覧回数
RadekS
NXP Employee
NXP Employee

Hi Ray,

you are right.

Example code describes how to access flash module. It is not directly driver.

Programming trough maximum four words (P-flash phrase) is limitation given by flash module. Valid range for FCCOBIX is 0..5, values 6 and 7 are ignored. For Program P-Flash Command, the first two words contain Flash command and Global address. The next four words presents data (FCCOB content meaning depends on flash command).

So, you will need some upper layer which will call EEPROM_Program() function in loop, until all data will be written.


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信