AN2616 Freescale Semiconductor / Motorola, AN2616 Datasheet - Page 56

no-image

AN2616

Manufacturer Part Number
AN2616
Description
Getting Started with HCS08 and CodeWarrior Using C
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
AN2616
Big Endian or Little
Endian?
Check core and
compiler for Big
Endianness
56
NOTE:
The Endianness of a processor refers to the order in which it stores multiple
byte values in memory. Big Endian processors store the most significant byte
at the lowest address, whereas Little Endian processors store the least
significant byte at the lowest address. This can cause issues if it is not taken
into account.
For a more thorough discussion of Endianness refer to:
The HCS08 (like all 68HCxx) is a Big Endian processor.
Endianness is also used to express the order of bits within a byte, and is
typically used within serial communications. Serial communications may
expect data least significant bit (Little Endian) or most significant bit (Big
Endian) first. RS232 expects bits to be sent in Little Endian format. The SCI on
an HCS08 transmits data in Little Endian format; the SPI on an HCS08 is
selectable as Big Endian or Little Endian. An example of a Big Endian serial
protocol is MIL-STD-1553B, where data transmissions are most significant bit
first.
If connecting external peripherals, check the Endianness to ensure
compatibility.
The following piece of code checks the processor and compiler for Big
Endianness.
First, create a union/structure to allow word or byte access to a union/structure
for a 16-bit integer:
Next, define required variables, one using the union/structure, an error counter,
and a byte pointer:
// Declare union to access word as word or two bytes
typedef union {
} TEMP;
TEMP t;
byte err;
byte *p;
Getting Started with HCS08 and CodeWarrior Using C
word w;
struct {
} bytes;
Freescale Semiconductor, Inc.
byte h;
byte l;
For More Information On This Product,
http://www.wikipedia.org/wiki/Endianness
//declare temporary variable using union
//error count
//pointer to access bytes within word
Go to: www.freescale.com
MOTOROLA

Related parts for AN2616