MC9S12XET256 - Emulated EEPROM Word aligned access

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

MC9S12XET256 - Emulated EEPROM Word aligned access

Jump to solution
995 Views
LeandroLeite
Contributor II

Hello,

 

I'm working with the emulated EEPROM of MC9S12XET256 device. I followed the instructions in Application Note AN3743 and was able to emulate the EEPROM and read and write Bytes in it, using pointers, like it does in the application note.

 

Then I've read in Application Note AN3490 that "EEE is designed for optimal use with align word (16-bit) data", so I'm trying to do operations of read and write in EEPROM using pointers to Word instead of pointers to Byte. But seems that only the Low Byte can be read or written, the High Byte goes to zero or some garbage.

 

Below are some example of code I'm using. When I use this code with "unsigned char" instead of "unsigned int" it works perfectly.

 

//Declaration of pointer and variables

unsigned int *pointer;

unsigned int value_read, value_written;

  

//To read the value in position 0x0F00 of EEPROM, for example

pointer = (unsigned int *) 0x0F00;

value_read = *pointer;

 

//To write in position 0x0F02 of EEPROM, for example

pointer = (unsigned int *) 0x0F02;

*pointer = value_written;

 

So, what am I doing wrong? Can I access the EEPROM by word or only by bytes? 

Is the pointer association correct?

 

Thanks in advance,

Leandro

Labels (1)
0 Kudos
1 Solution
659 Views
LeandroLeite
Contributor II

Both the partitioning and the EEPROM emulation were correct.

 

But by a disregard I was pointing to odd addresses. When I tried to write and read only to even addresses the code worked fine!

 

Thanks for the help Kef!

Leandro

 

View solution in original post

0 Kudos
3 Replies
659 Views
kef
Specialist I

Your code looks fine and should work.

Are you sure DFLASH is properly partitioned and eeprom emulation enabled? You need to issue Enable Eeprom Emulation command on each reset.

0 Kudos
660 Views
LeandroLeite
Contributor II

Both the partitioning and the EEPROM emulation were correct.

 

But by a disregard I was pointing to odd addresses. When I tried to write and read only to even addresses the code worked fine!

 

Thanks for the help Kef!

Leandro

 

0 Kudos
659 Views
LeandroLeite
Contributor II

By the way, I'm using CodeWarrior IDE Version 5.9.0.

0 Kudos