<?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: Using SPI , a simple read from SPIDR</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Using-SPI-a-simple-read-from-SPIDR/m-p/147739#M4063</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The SPIDR register does not behave like a normal read-write register. Writing to the register initiates a send from the master (via MOSI). Then reading the same location gives the value just returned (via MISO). If the input pin is open circuit (with a pull-up present) the expected return would be 0xFF.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the purpose of the test, you might try connecting the MOSI pin to the MISO pin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The port M initialisation might set the relevant pins to inputs, with pull-ups enabled for when the SPI module is disabled.&amp;nbsp; The SPI module will determine the direction when it is enabled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by bigmac on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-10-19&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;04:08 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 19 Oct 2009 12:01:42 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2009-10-19T12:01:42Z</dc:date>
    <item>
      <title>Using SPI , a simple read from SPIDR</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Using-SPI-a-simple-read-from-SPIDR/m-p/147738#M4062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if there was a way to test my SPI without any slave modules.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I simply want to initialize SPI correctly, write data to SPIDR, and copy the same data to a variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following variables&lt;/P&gt;&lt;P&gt;volatile byte temp = 0;&lt;BR /&gt;volatile byte temp0 = 0;&lt;/P&gt;&lt;P&gt;volatile byte temp2 = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Port M&lt;BR /&gt;DDRM_DDRM5 = 1; // SCK on PM5 set to output&lt;BR /&gt;DDRM_DDRM4 = 1; // MOSI on PM4 set to output&lt;BR /&gt;DDRM_DDRM3 = 1; // SS on PM3 set to output&lt;BR /&gt;DDRM_DDRM2 = 0; // MISO on PM2 set to input&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* SPI SET UP */&lt;BR /&gt;SPICR1 = 0x50;&amp;nbsp;&amp;nbsp; /* MSB first, manual slave select, 0 phase, 0 polarity clock, Master mode, no interrupts on trasmit, enable SPI, no interrupts */&lt;BR /&gt;SPICR2 = 0x00;&amp;nbsp;&amp;nbsp; /* Normal uni directional mode */&lt;BR /&gt;SPIBR = 0x57;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Baud rate = Bus Clock / Baud Rate Division;&amp;nbsp; Check divisor table in SPI section pg 463.&amp;nbsp; Diving by 2048 to try to slow it down to see data on O-scope*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// SEND DATA&amp;nbsp;&lt;/P&gt;&lt;P&gt;while ( (SPISR &amp;amp; 0x20) == 0) { /* wait for SPTEF = 1 to know SPIDR is empty&amp;nbsp; */ }&lt;BR /&gt;temp = SPIDR = temp0 = 100;&lt;BR /&gt;while ( (SPISR &amp;amp; 0x80) == 0) { /* wait for SPIF = 1 to know new data has copied&amp;nbsp; */ }&lt;/P&gt;&lt;P&gt;temp2 = SPIDR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The end result is that temp0 is 100 or 'A'&lt;/P&gt;&lt;P&gt;and temp is&amp;nbsp;0, which I expected since SPIDR should be initially empty&lt;/P&gt;&lt;P&gt;But temp2 is 255 (I am guessing unsigned 11111111 )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I figured temp2 should be 100 or 'A'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is my understanding incorrect?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any info on SPI would help.&amp;nbsp; I am using a NanoCore with the Motorola 9S12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks all&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 18 Oct 2009 06:59:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Using-SPI-a-simple-read-from-SPIDR/m-p/147738#M4062</guid>
      <dc:creator>phaze</dc:creator>
      <dc:date>2009-10-18T06:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using SPI , a simple read from SPIDR</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Using-SPI-a-simple-read-from-SPIDR/m-p/147739#M4063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The SPIDR register does not behave like a normal read-write register. Writing to the register initiates a send from the master (via MOSI). Then reading the same location gives the value just returned (via MISO). If the input pin is open circuit (with a pull-up present) the expected return would be 0xFF.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the purpose of the test, you might try connecting the MOSI pin to the MISO pin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The port M initialisation might set the relevant pins to inputs, with pull-ups enabled for when the SPI module is disabled.&amp;nbsp; The SPI module will determine the direction when it is enabled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by bigmac on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-10-19&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;04:08 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Oct 2009 12:01:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Using-SPI-a-simple-read-from-SPIDR/m-p/147739#M4063</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-10-19T12:01:42Z</dc:date>
    </item>
  </channel>
</rss>

