<?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 Re: Data sets inside a union in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185237#M6426</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I did try the code snippet you have provided on CodeWarrior for HC12 V4.6.&lt;/DIV&gt;&lt;DIV&gt;It is working well.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Also CodeCompletion is working like a charm in there.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;- Which version of CodeWarrior are you using?&lt;BR /&gt;To retrieve that info:&lt;BR /&gt;- Start CodeWarrior&lt;BR /&gt;- Select Help -&amp;gt; About Freescale CodeWarrior&lt;BR /&gt;- Click on "Install Products"&lt;BR /&gt;- CodeWarrior version used is displayed on top in the Installed Products dialog.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;CrasyCat&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 04 Feb 2008 20:38:45 GMT</pubDate>
    <dc:creator>CrasyCat</dc:creator>
    <dc:date>2008-02-04T20:38:45Z</dc:date>
    <item>
      <title>Data sets inside a union</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185231#M6420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I want to make a union of to data sets (a structure and an array).&lt;/P&gt;&lt;P&gt;My code is as follows:&lt;/P&gt;&lt;P&gt;#define COMMS_BUFFER_SIZE 80&lt;BR /&gt;#define PROTOCOL_HEADER_SIZE 5&lt;BR /&gt;#define PROTOCOL_DATA_SIZE (COMMS_BUFFER_SIZE - PROTOCOL_HEADER_SIZE)&lt;/P&gt;&lt;P&gt;typedef struct {&lt;BR /&gt;&amp;nbsp; u8 StartByte;&lt;BR /&gt;&amp;nbsp; u8 Route;&lt;BR /&gt;&amp;nbsp; u8 Command;&lt;BR /&gt;&amp;nbsp; u8 Length;&lt;BR /&gt;&amp;nbsp; u8 HCS;&lt;BR /&gt;&amp;nbsp; u8 Data[PROTOCOL_DATA_SIZE];&lt;BR /&gt;}TProtocol;&lt;/P&gt;&lt;P&gt;typedef union {&lt;BR /&gt;&amp;nbsp; TProtocol Protocol;&lt;BR /&gt;&amp;nbsp; u8 Data[COMMS_BUFFER_SIZE];&lt;BR /&gt;}TCommsBuffer;&lt;/P&gt;&lt;P&gt;extern TCommsBuffer CommsBuffer;&lt;/P&gt;&lt;P&gt;I want to access the contents of "TCommsBuffer" in the protocol format (strucrure) or as a array.&lt;/P&gt;&lt;P&gt;CommsBuffer.Data[x] = x;&lt;BR /&gt;CommsBuffer.Protocol.StartByte = x;&lt;/P&gt;&lt;P&gt;But it gives me problems.&lt;/P&gt;&lt;P&gt;When I read data into the Protocol structure, it repeats the contents of the 1st 5 bytes of the protocol structure into its data section.&lt;/P&gt;&lt;P&gt;Is this the correct way to define the union?&lt;/P&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Feb 2008 21:55:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185231#M6420</guid>
      <dc:creator>fusion2344</dc:creator>
      <dc:date>2008-02-02T21:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Data sets inside a union</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185232#M6421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The first 5 bytes of CommsBuffer.Data[x] are the header bytes, if you want the data bytes of the protocol without the header, that would be CommsBuffer.Protocol.Data[x].&lt;BR /&gt;Or maybe I miss the problem?&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Feb 2008 22:46:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185232#M6421</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-02-02T22:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Data sets inside a union</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185233#M6422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;Yes, you misunderstood.&lt;BR /&gt;&lt;BR /&gt;I am actually asking if the structure and union defenition is correct, will it work as it is?&lt;BR /&gt;&lt;BR /&gt;Then there is 2 other problems.&lt;BR /&gt;&lt;BR /&gt;Problem 1:&lt;BR /&gt;&lt;BR /&gt;Say I do the following, fill the &lt;B&gt;CommsBuffer.Data&lt;/B&gt; with sequential numbers:&lt;BR /&gt;&lt;BR /&gt;for (Loop = 0; Loop &amp;lt; COMMS_BUFFER_SIZE; Loop ++) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CommsBuffer.Data[Loop] = Loop;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Then if I read the contents of the &lt;B&gt;CommsBuffer.Protocol&lt;/B&gt; structure&lt;BR /&gt;&lt;BR /&gt;P1 = CommsBuffer.Protocol.StartByte;&lt;BR /&gt;P2 = CommsBuffer.Protocol.Route;&lt;BR /&gt;P3 = CommsBuffer.Protocol.Command;&lt;BR /&gt;P4 = CommsBuffer.Protocol.Length;&lt;BR /&gt;P5 = CommsBuffer.Protocol.HCS;&lt;BR /&gt;P6 = CommsBuffer.Protocol.Data[0];&lt;BR /&gt;P7 = CommsBuffer.Protocol.Data[1];&lt;BR /&gt;P8 = CommsBuffer.Protocol.Data[2];&lt;BR /&gt;P9 = CommsBuffer.Protocol.Data[3];&lt;BR /&gt;P10 = CommsBuffer.Protocol.Data[4];&lt;BR /&gt;P11 = CommsBuffer.Protocol.Data[5];&lt;BR /&gt;P12 = CommsBuffer.Protocol.Data[5];&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Then the &lt;B&gt;protocol header&lt;/B&gt; section (5 bytes) is repeated in 1st 5 bytes of the &lt;B&gt;protocol data&lt;/B&gt; section and then only the actual protocol data. Like this:&lt;BR /&gt;&lt;BR /&gt;P1 = 0&lt;BR /&gt;P2 = 1&lt;BR /&gt;P3 = 2&lt;BR /&gt;P4 = 3&lt;BR /&gt;P5 = 4&lt;BR /&gt;P6 = 0&lt;BR /&gt;P7 = 1&lt;BR /&gt;P8 = 2&lt;BR /&gt;P9 = 3&lt;BR /&gt;P10 = 4&lt;BR /&gt;P11 = 10&lt;BR /&gt;P12 = 11&lt;BR /&gt;&lt;BR /&gt;Problem 2:&lt;BR /&gt;&lt;BR /&gt;With normal type defined structures the editor will auto complete if I type&lt;BR /&gt;&lt;BR /&gt;CommsBuffer&lt;B&gt;.&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;and it will show the list where you can select the variables of CommsBuffer.&lt;BR /&gt;&lt;BR /&gt;But with the current type defined union it doesn'y display the autocomplete list, making me think that there might be something wrong with the way I defined the union and structure.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by fusion2344 on &lt;SPAN class="date_text"&gt;2008-02-02&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;03:32 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by fusion2344 on &lt;SPAN class="date_text"&gt;2008-02-02&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;03:33 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Feb 2008 23:31:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185233#M6422</guid>
      <dc:creator>fusion2344</dc:creator>
      <dc:date>2008-02-02T23:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: Data sets inside a union</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185234#M6423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I tried your code under full chip simulation, and obtained the expected result, as supported by a check of RAM contents after execution.&amp;nbsp; The array &lt;FONT face="Courier New"&gt;CommsBuffer.Protocol.Data&lt;/FONT&gt; definitely commenced with a value of 5, whereas &lt;FONT face="Courier New"&gt;CommsBuffer.Data&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;commenced with value zero.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 03 Feb 2008 17:46:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185234#M6423</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-02-03T17:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Data sets inside a union</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185235#M6424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Mmmmmmh........? I wonder. I can give you a screenshot of the variables in full chip simulation.&lt;BR /&gt;It defenitely repeats the header section into the data section.&lt;BR /&gt;&lt;BR /&gt;Do you have any comments on the other 2 problems?&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Feb 2008 05:47:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185235#M6424</guid>
      <dc:creator>fusion2344</dc:creator>
      <dc:date>2008-02-04T05:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Data sets inside a union</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185236#M6425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The union is defined correctly. Are you sure you are looking at the right values? One could easily confuse CommsBuffer.Data with CommsBuffer.Protocol.Data, for example.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Feb 2008 15:39:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185236#M6425</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2008-02-04T15:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Data sets inside a union</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185237#M6426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I did try the code snippet you have provided on CodeWarrior for HC12 V4.6.&lt;/DIV&gt;&lt;DIV&gt;It is working well.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Also CodeCompletion is working like a charm in there.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;- Which version of CodeWarrior are you using?&lt;BR /&gt;To retrieve that info:&lt;BR /&gt;- Start CodeWarrior&lt;BR /&gt;- Select Help -&amp;gt; About Freescale CodeWarrior&lt;BR /&gt;- Click on "Install Products"&lt;BR /&gt;- CodeWarrior version used is displayed on top in the Installed Products dialog.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;CrasyCat&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Feb 2008 20:38:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Data-sets-inside-a-union/m-p/185237#M6426</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2008-02-04T20:38:45Z</dc:date>
    </item>
  </channel>
</rss>

