<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Byte Order in Struct in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Byte-Order-in-Struct/m-p/453016#M12098</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;struct TestStruct {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uint16_t itemOne;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uint16_t itemTwo;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uint16_t itemThree;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uint16_t itemFour; &lt;/P&gt;&lt;P&gt;}test;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;test.itemOne = 1000;&lt;/P&gt;&lt;P&gt;test.itemTwo = 1001;&lt;/P&gt;&lt;P&gt;test.itemThree = 1002;&lt;/P&gt;&lt;P&gt;test.itemFour = 1003;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The values are stored with LSB First. All other MCU I have used &lt;/P&gt;&lt;P&gt;and C++ Builder store the values MSB First. This has made simple &lt;/P&gt;&lt;P&gt;coding into more complicated as I have to swap the bytes before I &lt;/P&gt;&lt;P&gt;can use them when they are transferred to and from the PC software..&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the S12G128 if that matters.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I make CodeWarrior stop doing this.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ray. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 05 Jul 2015 03:05:18 GMT</pubDate>
    <dc:creator>rayhall</dc:creator>
    <dc:date>2015-07-05T03:05:18Z</dc:date>
    <item>
      <title>Byte Order in Struct</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Byte-Order-in-Struct/m-p/453016#M12098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;struct TestStruct {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uint16_t itemOne;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uint16_t itemTwo;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uint16_t itemThree;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uint16_t itemFour; &lt;/P&gt;&lt;P&gt;}test;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;test.itemOne = 1000;&lt;/P&gt;&lt;P&gt;test.itemTwo = 1001;&lt;/P&gt;&lt;P&gt;test.itemThree = 1002;&lt;/P&gt;&lt;P&gt;test.itemFour = 1003;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The values are stored with LSB First. All other MCU I have used &lt;/P&gt;&lt;P&gt;and C++ Builder store the values MSB First. This has made simple &lt;/P&gt;&lt;P&gt;coding into more complicated as I have to swap the bytes before I &lt;/P&gt;&lt;P&gt;can use them when they are transferred to and from the PC software..&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the S12G128 if that matters.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I make CodeWarrior stop doing this.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ray. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Jul 2015 03:05:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Byte-Order-in-Struct/m-p/453016#M12098</guid>
      <dc:creator>rayhall</dc:creator>
      <dc:date>2015-07-05T03:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: Byte Order in Struct</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Byte-Order-in-Struct/m-p/453017#M12099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe I have not explained clearly what the problem is.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;test.testOne = 1000;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When test.itemOne value is read after being transferred to the PC by SCI, the value is 59395 not 1000.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both the S12G128 and PC software have the same structure. The whole structure is transferred too a from S12 and PC via SCI.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have been using this method for many years with the Atmel MCU and no problems. The S12 compiler is storing the 16 bit values in memory with the byte around the other way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ray.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 21:21:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Byte-Order-in-Struct/m-p/453017#M12099</guid>
      <dc:creator>rayhall</dc:creator>
      <dc:date>2015-07-06T21:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Byte Order in Struct</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Byte-Order-in-Struct/m-p/453018#M12100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. S12 is big endian machine, which means &amp;gt;=16bit integers and floating point numbers are stored MSByte first. PC and Atmel MCU's are little endian machines, LSB first.&lt;/P&gt;&lt;P&gt;2. C structs are not portable. Even with the same byte order, one compiler may add more padding bytes to align struct members than another compiler may add.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edward&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 04:39:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Byte-Order-in-Struct/m-p/453018#M12100</guid>
      <dc:creator>kef2</dc:creator>
      <dc:date>2015-07-07T04:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Byte Order in Struct</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Byte-Order-in-Struct/m-p/453019#M12101</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;yes this problem is due to big endian.&lt;/P&gt;&lt;P&gt;in addition, in Freesacle MCU,&lt;/P&gt;&lt;P&gt;Big Endian : HCS12(X), HC(S)08, ColdFire, …&lt;/P&gt;&lt;P&gt;Little Endian : DSC and Kinetis.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;user can &lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;write convert code by themselves&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;The quickest way for converting 2-byte and 4-byte data&amp;nbsp; is to define macros:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*applicable to both integer or floating point number which originally written for HC12*/&lt;/P&gt;&lt;P&gt;#define EndianConvert16(w) ((w&amp;gt;&amp;gt;8)|(w&amp;lt;&amp;lt;8))&lt;/P&gt;&lt;P&gt;#define EndianConvert32(dw) ((dw&amp;lt;&amp;lt;24)|((dw&amp;gt;&amp;gt;8)&amp;amp;0xFF00)|((dw&amp;lt;&amp;lt;8)&amp;amp;0xFF0000)|(dw&amp;gt;&amp;gt;24))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can this help?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Zhang Jun&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 06:20:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Byte-Order-in-Struct/m-p/453019#M12101</guid>
      <dc:creator>ZhangJennie</dc:creator>
      <dc:date>2015-07-07T06:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Byte Order in Struct</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Byte-Order-in-Struct/m-p/453020#M12102</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Edward and Zhang.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ray.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 21:21:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Byte-Order-in-Struct/m-p/453020#M12102</guid>
      <dc:creator>rayhall</dc:creator>
      <dc:date>2015-07-07T21:21:08Z</dc:date>
    </item>
  </channel>
</rss>

