<?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>S12 / MagniV MicrocontrollersのトピックRe: Floating point storing</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140281#M3062</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Bigmac..&lt;/DIV&gt;&lt;DIV&gt;it worked !!!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thanks a lot..&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;one more thing please..&lt;/DIV&gt;&lt;DIV&gt;I am trying to send 24bits to SPI0. first 13 bits then 11 bits . to form the write command and address of the flash memory to which the SPI0 is connected.&lt;/DIV&gt;&lt;DIV&gt;can you help me in arranging these bits from 4byte.&lt;/DIV&gt;&lt;DIV&gt;in other words.&lt;/DIV&gt;&lt;DIV&gt;I have to send 13 bits for the page address and 11 bits for the byte address.&lt;/DIV&gt;&lt;DIV&gt;those addresses are in 2 integers (2x2bytes=4bytes). in this case, I need the to take the last 13bits of the 2byte for the page address and then take the last 11bits of the 2byte (the byte address) and send them togther without any other bits.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;do you have an idea about how to do so?&lt;/DIV&gt;&lt;DIV&gt;thanks again for the help..&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;EM1.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 16 Dec 2006 00:01:29 GMT</pubDate>
    <dc:creator>EM1</dc:creator>
    <dc:date>2006-12-16T00:01:29Z</dc:date>
    <item>
      <title>Floating point storing</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140279#M3060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;I am using an external serial flash memory for my HCS12.&lt;/DIV&gt;&lt;DIV&gt;I want to store&amp;nbsp;floating point numbers in this flash. can anybody please tell me if the following&lt;/DIV&gt;&lt;DIV&gt;is the right way to deal with floating point storage.&lt;/DIV&gt;&lt;DIV&gt;suppose we have "d" as a floating point number.&lt;/DIV&gt;&lt;DIV&gt;float d ;&lt;/DIV&gt;&lt;DIV&gt;float *pt ;&lt;/DIV&gt;&lt;DIV&gt;pt=&amp;amp;d;&lt;/DIV&gt;&lt;DIV&gt;char i;&lt;/DIV&gt;&lt;DIV&gt;for (i=0; i&amp;lt;=3;i++)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;{&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;send_serial (*(pt++)); // send_serial, is a function to send a byte through the SPI0.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Now for reading the stored floating point number and send it to the SCI0&lt;/DIV&gt;&lt;DIV&gt;char buffer[4];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// a temporary buffer to store the 4bytes of the stored floating point number.&lt;/DIV&gt;&lt;DIV&gt;float *pt=&amp;amp;buffer;&lt;/DIV&gt;&lt;DIV&gt;for (i=0;i&amp;lt;=3;i++)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;{&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;get_serial (*(pt++));&amp;nbsp;// get_serial is a function to receive one byte from the SPI0.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;printf ("%6.3F",pt);&amp;nbsp;&amp;nbsp; // send the received floating point number to the SCI0.&lt;/DIV&gt;&lt;DIV&gt;\\**********************************************************************************&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thanks a lot and I appriciate any help here.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;EM1.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Dec 2006 21:48:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140279#M3060</guid>
      <dc:creator>EM1</dc:creator>
      <dc:date>2006-12-15T21:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: Floating point storing</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140280#M3061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello EM1,&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;Since you have declared pt to be a pointer to a float, when you increment the pointer, this will not give your intended result since the increment would occur over four bytes.&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;Perhaps you could form a union between a float value and a char array (of 4 bytes length).&amp;nbsp; This way you could identify the value of the individual bytes.&amp;nbsp; The following untested code is shown for the write process.&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 face="Courier New" size="2"&gt;typedef union {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;byte byteval[4];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;float val;&lt;BR /&gt;} float_val;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;char i;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;float_val d;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;d.val = 123.456;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;/* Enable /SS line (slave select)&amp;nbsp;to SPI slave device */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;/* Additional code&amp;nbsp;required here to set up serial flash write */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;for (i=0; i&amp;lt;4; i++)&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;send_serial(d.byteval[i]);&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;/* Disable /SS line */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;The additional code requirements will depend on the serial flash device used.&amp;nbsp; For reading the stored data, the get_serial() function might simply return a char value.&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;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;/* Enable /SS line (slave select)&amp;nbsp;to SPI slave device */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;/* Additional code&amp;nbsp;required here to set up serial flash&amp;nbsp;read */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;for (i=0; i&amp;lt;4; i++)&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;d.byteval[i] = get_serial();&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;/* Disable /SS line */&lt;/FONT&gt;&lt;/DIV&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>Fri, 15 Dec 2006 23:12:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140280#M3061</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-12-15T23:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Floating point storing</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140281#M3062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Bigmac..&lt;/DIV&gt;&lt;DIV&gt;it worked !!!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thanks a lot..&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;one more thing please..&lt;/DIV&gt;&lt;DIV&gt;I am trying to send 24bits to SPI0. first 13 bits then 11 bits . to form the write command and address of the flash memory to which the SPI0 is connected.&lt;/DIV&gt;&lt;DIV&gt;can you help me in arranging these bits from 4byte.&lt;/DIV&gt;&lt;DIV&gt;in other words.&lt;/DIV&gt;&lt;DIV&gt;I have to send 13 bits for the page address and 11 bits for the byte address.&lt;/DIV&gt;&lt;DIV&gt;those addresses are in 2 integers (2x2bytes=4bytes). in this case, I need the to take the last 13bits of the 2byte for the page address and then take the last 11bits of the 2byte (the byte address) and send them togther without any other bits.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;do you have an idea about how to do so?&lt;/DIV&gt;&lt;DIV&gt;thanks again for the help..&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;EM1.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Dec 2006 00:01:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140281#M3062</guid>
      <dc:creator>EM1</dc:creator>
      <dc:date>2006-12-16T00:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Floating point storing</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140282#M3063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Try it this way:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// These values contain the bits&lt;BR /&gt;unsigned short bits13;&lt;BR /&gt;unsigned short bits11;&lt;BR /&gt;&lt;BR /&gt;// shift them together to form a 24 bit value&lt;BR /&gt;// the upper byte is not used&lt;BR /&gt;unsigned long joint_value = ((unsigned long)bits13)&amp;lt;&amp;lt;11 | (bits11 &amp;amp; 0x7ff);&lt;BR /&gt;&lt;BR /&gt;// send three bytes&lt;BR /&gt;send_to_spi (((unsigned char*)&amp;amp;joint_value)[2]);&lt;BR /&gt;send_to_spi (((unsigned char*)&amp;amp;joint_value)[1]);&lt;BR /&gt;send_to_spi (((unsigned char*)&amp;amp;joint_value)[0]);&lt;BR /&gt;&lt;BR /&gt;Don't know if that code works, but it shows the principle&lt;BR /&gt;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Dec 2006 01:30:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140282#M3063</guid>
      <dc:creator>pittbull</dc:creator>
      <dc:date>2006-12-16T01:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Floating point storing</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140283#M3064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello EM1,&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;The following code might be a possibility,&amp;nbsp;with some similarities to my previous post&amp;nbsp;-&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 face="Courier New" size="2"&gt;#define dword unsigned long&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;typedef union {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;byte byteval[4];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;dword val;&lt;BR /&gt;} Address;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;char i;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;word flash_page;&amp;nbsp; /* 13-bit value, right justified */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;word flash_addr;&amp;nbsp; /* 11-bit value, right justified */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;Address addr;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;addr.val = ((dword)flash_page &amp;lt;&amp;lt; 11) | ((dword)flash_addr &amp;amp; 0x000007FF);&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;for (i=0; i&amp;lt;3; i++)&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;send_serial(addr.byteval[i+1]);&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>Sat, 16 Dec 2006 01:58:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140283#M3064</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-12-16T01:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: Floating point storing</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140284#M3065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello Bigmac, what's up?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thanks for your replies..&lt;/DIV&gt;&lt;DIV&gt;I developed some manual sifting to get the serial bit stream for the addresses.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thanks a lot for your time and for the new ideas.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;take care..&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;EM1.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Dec 2006 03:46:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Floating-point-storing/m-p/140284#M3065</guid>
      <dc:creator>EM1</dc:creator>
      <dc:date>2006-12-16T03:46:36Z</dc:date>
    </item>
  </channel>
</rss>

