<?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>8-bit MicrocontrollersのトピックRe: Simple SPI driver</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124291#M248</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Sorry about the confusion.&amp;nbsp; When I was speaking of addresses, I was talking about the internal registers of my slave part.&amp;nbsp; I have to send it a register address byte, then a command to that register, then the slave will send a response byte.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;After looking at your code, and looking at what I wrote based off of sec. 15.3.4 "Queuing Transmission Data" from my micro's data sheet (attached), I may have "over-engineered" my code in order to follow the diagram in 15.3.4.&amp;nbsp; I now realize that the diagram is constructed for maximum efficency with continuous communication.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;Tomahawk&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC68HC908QB8.pdf" rel="nofollow" target="_self"&gt;MC68HC908QB8.pdf&lt;/A&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by t.dowe on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-09-16&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;10:26 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Jul 2006 19:55:27 GMT</pubDate>
    <dc:creator>admin</dc:creator>
    <dc:date>2006-07-26T19:55:27Z</dc:date>
    <item>
      <title>Simple SPI driver</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124287#M244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Anyone have a simple SPI driver written in C for an HC08?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;Tomahawk&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Jul 2006 21:45:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124287#M244</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-07-17T21:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SPI driver</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124288#M245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Tomahawk,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;As SPI master or slave?&amp;nbsp; The solutions would be quite different - master is simpler.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jul 2006 02:59:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124288#M245</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-07-18T02:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SPI driver</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124289#M246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Master - and I'm only talking to one slave.&amp;nbsp; I'm experienced with I2C, but new to SPI.&amp;nbsp; Some examples would be helpful, too.&amp;nbsp; I have some basic questions, too, for example:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;1) when you're addressing the slave is the R/W bit the MSB or the LSB?&amp;nbsp; None of the app notes/literature says - they all assume I already know.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2) when I want to read from the slave, I first send it the address in the device from which I want to read.&amp;nbsp; OK, fine.&amp;nbsp; Now, in order to actually get the data from the device, do I need to send out some dummy data in order to clock the data in from the device?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;btw, I'm using the MC68HC908QB4.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thanks,&lt;/DIV&gt;&lt;DIV&gt;Tomahawk&lt;/DIV&gt;&lt;P&gt;Message Edited by Tomahawk on &lt;SPAN class="date_text"&gt;2006-07-25&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;09:54 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2006 21:51:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124289#M246</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-07-25T21:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SPI driver</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124290#M247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Tomahawk,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Firstly, there seems to be a little confusion with the SPI operation.&lt;/FONT&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT size="2"&gt;With SPI there is no "address".&amp;nbsp; You directly enable a slave device by activating its /SS (slave select) line.&amp;nbsp; In many cases, this&amp;nbsp;will be a GPIO line at the master.&amp;nbsp; For the master, data is simultaneously sent from the MOSI line and received via the MISO line - there is no "RW bit" like in I2C.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;For the master to receive data from a SPI slave, you would send a dummy byte to initiate the transfer of data from the slave.&amp;nbsp; The returned byte value would need to be within the slave send buffer prior to the dummy byte being sent, so it is not possible for data to be returned in response to a command, within a single byte transaction.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;FONT size="2"&gt;I am not sure what your slave device is, but as an example, assume you wish to read data from a SPI compatible EEPROM.&amp;nbsp; The following steps would typically be involved.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Send READ command - ignore return&lt;BR /&gt;Send first address byte - ignore return&lt;BR /&gt;Send second address byte - ignore return&lt;BR /&gt;Send dummy byte - first data byte returned&lt;BR /&gt;Send dummy byte - second data byte returned&lt;BR /&gt;etc.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;When initialising the SPI module as a master you will need to match the CPOL and CPHA parameters to the requirements of the slave device.&amp;nbsp; Whether or not you need to de-activate and then re-activate the /SS signal after each byte will also depend on the slave requirements.&amp;nbsp; Pr&lt;/FONT&gt;&lt;FONT size="2"&gt;ovided a relatively fast SPI clock rate is selected, it is usually not necessary to use SPI interrupts for a master.&amp;nbsp; This is not the case for the MCU operating as a slave.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;For each master SPI transaction, you need to write a byte to SPDR, and a short while later you will have received a returned byte from the SPI slave. So the SPI function might be similar to the following code, but does not include control of the /SS line,&amp;nbsp;that may need to be added.&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;byte SPI_proc (byte data)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; while (!SPSCR_SPTE);&amp;nbsp; /* Wait for Tx buffer empty */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; SPDR = data;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Send byte */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; while (!SPSCR_SPRF);&amp;nbsp;&amp;nbsp;/* Wait for Rx buffer full */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; return (SPDR);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Received byte value */&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;For the EEPROM example given above -&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;SPI_proc (READ_CMD);&lt;BR /&gt;SPI_proc (address1);&lt;BR /&gt;SPI_proc (address2);&lt;BR /&gt;value1 = SPI_proc (0);&lt;BR /&gt;value2 = SPI_proc (0);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jul 2006 03:06:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124290#M247</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-07-26T03:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SPI driver</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124291#M248</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Sorry about the confusion.&amp;nbsp; When I was speaking of addresses, I was talking about the internal registers of my slave part.&amp;nbsp; I have to send it a register address byte, then a command to that register, then the slave will send a response byte.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;After looking at your code, and looking at what I wrote based off of sec. 15.3.4 "Queuing Transmission Data" from my micro's data sheet (attached), I may have "over-engineered" my code in order to follow the diagram in 15.3.4.&amp;nbsp; I now realize that the diagram is constructed for maximum efficency with continuous communication.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;Tomahawk&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC68HC908QB8.pdf" rel="nofollow" target="_self"&gt;MC68HC908QB8.pdf&lt;/A&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by t.dowe on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-09-16&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;10:26 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jul 2006 19:55:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124291#M248</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-07-26T19:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SPI driver</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124292#M249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Tomahawk,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I could be more specific if I knew what&amp;nbsp;slave device you are using.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I can only repeat that I have never found it necessary to use interrupts for master operation.&amp;nbsp; Typically, I would use SPI when I require&amp;nbsp;serial EEPROM, but more often I use SPI for&amp;nbsp;communicating with shift register chains, both parallel input and parallel output, for the purpose of I/O expansion.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Since I have been able to use a fast SPI clock rate, that each data transaction takes a few microseconds to complete has not been an issue for me.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jul 2006 22:18:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124292#M249</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-07-26T22:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SPI driver</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124293#M250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;Here's my slave part.&amp;nbsp; I implemented your code, and my functions are much cleaner now.&amp;nbsp; I think the possible performance hit will be negligible compared to the example in the master data sheet.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;Tomahawk&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="http://www.freescale.com/files/community_files/8BITCOMM/2202_11279.pdf" rel="nofollow" target="_self"&gt;11279.pdf&lt;/A&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by t.dowe on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-10-27&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;12:33 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jul 2006 23:12:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124293#M250</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-07-26T23:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SPI driver</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124294#M251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Tomahawk,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;For the accelerometer device, I guess you are already aware of the settings CPHA = 1, CPOL =1 as the requirement.&amp;nbsp; The data sheet is rather confusing when it identifies the bit associated with the first clock pulse as "bit 0".&amp;nbsp; SPI is normally MS bit first, and this&amp;nbsp;matches the&amp;nbsp;data sent to and&amp;nbsp;received from&amp;nbsp;SPDR.&amp;nbsp; For the first send byte, the R/W bit is therefore the MS bit of the address byte.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;For&amp;nbsp;the read/write protocol, the following sequence would apply -&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Enable /CS&lt;BR /&gt;Send address byte, ignore return byte&lt;BR /&gt;Send input data, return byte is the output data&lt;BR /&gt;Disable /CS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I would also&amp;nbsp;suggest fitting an external pull-up resistor for MISO line, say 10k, since it appears that SPDO pin of the device is high-Z for some of the time.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jul 2006 04:30:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124294#M251</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-07-27T04:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Simple SPI driver</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124295#M252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Thanks for the help, mac.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jul 2006 20:05:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Simple-SPI-driver/m-p/124295#M252</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-07-27T20:05:39Z</dc:date>
    </item>
  </channel>
</rss>

