AnsweredAssumed Answered

Little Endians Issue...

Question asked by Pablo Suarez on Oct 15, 2012
Latest reply on Oct 16, 2012 by TomE

Hi there, I'm trying to adapt a C code wrote for an ATMEL uC to my MCF51CN128 ColdFire. The code was made to read an SD Card whose data is written like little Indians, in a word field the first byte correspond to the lower byte of this word. For example, if I read from the memory 0xE7, 0x00, 0x00, 0x00 (in this order) it means 0x000000E7 long word. When I read the SD card from SPI interface, I fill a buffer with the same structure.

The code use struct format to identify diferent kind of fields and word on the complete buffer, like this:

 

//Structure to access Master Boot Record for getting info about partioions

struct MBRinfo_Structure{

unsigned char nothing [446];             //ignore, placed here to fill the gap in the structure    

unsigned char partitionData [64];      //partition records (16x4)

unsigned int signature;                   //0xaa55

};

 

In my first try I realized that in the signature struct, defined like above, it don't represented the right data so I change the definition like this,

 

unsigned short int signature;                   //0xaa55


in order to take just 2 bytes to make the int word, but, and naw my problem, when the uC read this data it read like 0x55AA (like is stored) when it have to take 0xAA55.

Why in the ATMEL code the data are correctly interpreted? It don't have any extra code to change the data format.


mbr = (struct MBRinfo_Structure *) buffer;       //if it is not boot sector, it must be MBR

 

if(mbr->signature != 0xaa55) return 1;       //if it is not even MBR then it's not FAT32

 

 

 

How I can solve this problem?


Thanks for your time.


Best regards.


Pablo.


Outcomes