<?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>Kinetis MicrocontrollersのトピックRe: SPI example on Kinetis KL16</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295661#M12166</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just as &lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/ZhangJennie"&gt;ZhangJennie&lt;/A&gt; mentioned, you can download the &lt;A href="http://cache.freescale.com/files/32bit/software/KL25_SC.exe?fasp=1&amp;amp;WT_TYPE=Lab%20and%20Test%20Software&amp;amp;WT_VENDOR=FREESCALE&amp;amp;WT_FILE_FORMAT=exe&amp;amp;WT_ASSET=Downloads"&gt;&lt;STRONG&gt;FRDM-KL25Z and TWRKL25Z48M Sample Code Package&lt;/STRONG&gt;&lt;/A&gt; and use the IAR example code as base for your development, you will find it in this path:&lt;/P&gt;&lt;P&gt;C:\(your download path)\KL25 Sample Code\kl25_sc_rev10\klxx-sc-pex\projects\spi_demo\iar&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a nice day :P,&lt;BR /&gt;Perla&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>Wed, 16 Apr 2014 21:52:33 GMT</pubDate>
    <dc:creator>perlam_i_au</dc:creator>
    <dc:date>2014-04-16T21:52:33Z</dc:date>
    <item>
      <title>SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295652#M12157</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;&amp;nbsp;&amp;nbsp;&amp;nbsp; does anybody know where to find an example for configuring SPI as a master and performing write/read synchronously (no interrupts, no dma) on KL16 devices? I've only found a thread showing some tips for DSPI on K10 and similar MCUs, but the peripheral on KL devices seems totally different.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Mar 2014 15:47:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295652#M12157</guid>
      <dc:creator>marcopalestro</dc:creator>
      <dc:date>2014-03-13T15:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295653#M12158</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;The SPI in the KL devices is different from the DSPI in the K devices; it doesn't have FIFOs and doesn't automatically control the chip select line in the same way.&lt;/P&gt;&lt;P&gt;Below is configuration code for master use of SPI1 on a certain set of pins (you can interpret it for the names since the code is from the uTaker project which uses some special configuration macros).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;POWER_UP(4, SIM_SCGC4_SPI1); // enable the SPI&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;_CONFIG_PERIPHERAL(E, 2, PE_2_SPI1_SCK); // configure interface lines&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;_CONFIG_PERIPHERAL(E, 1, (PE_1_SPI1_MOSI | PORT_SRE_FAST | PORT_DSE_HIGH));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;_CONFIG_PERIPHERAL(E, 3, (PE_3_SPI1_MISO | PORT_PS_UP_ENABLE));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;_CONFIG_DRIVE_PORT_OUTPUT_VALUE(E, CS0_LINE, CS0_LINE, (PORT_SRE_FAST | PORT_DSE_HIGH));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SPI1_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE); // configure master mode&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SPI1_BR = (SPI_BR_SPPR_PRE_1 | SPI_BR_SPR_DIV_2); // set speed&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(volatile unsigned char)SPI1_S; // read status register and data register to prepare for operation&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(volatile unsigned char)SPI1_D;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To write and read a byte:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SPI1_D = byte; // write a byte that is sent&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;while (!(SPI1_S &amp;amp; (SPI_S_SPRF))) {} // wait for the byte to be completely transmitted&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;byte = SPI1_D; // read the byte that was read&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Repeate for additional data.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only tricky bit is the fact that the status and data register should be read "once" before starting. If this is not performed the first loop will hang since the status will not be set accordingly.&lt;/P&gt;&lt;P&gt;Also, never let the debugger view the SPI registers when stepping such code since it will also read the data register and reset status flags in the process (causing the loop to hang).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 01:24:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295653#M12158</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2014-03-14T01:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295654#M12159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi Palestro,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; You can use PE to create a SPI example for KL16. PE is best for helping you study how to use Kinetis MCU. You can download PE at &lt;A href="http://www.freescale.com/webapp/sps/site/homepage.jsp?code=BEAN_STORE_MAIN&amp;amp;tid=SWnT&amp;amp;uc=true&amp;amp;lang_cd=en" title="http://www.freescale.com/webapp/sps/site/homepage.jsp?code=BEAN_STORE_MAIN&amp;amp;tid=SWnT&amp;amp;uc=true&amp;amp;lang_cd=en"&gt;Processor Expert Software and Embedded Components&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 02:02:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295654#M12159</guid>
      <dc:creator>xiaodong_zhang</dc:creator>
      <dc:date>2014-03-14T02:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295655#M12160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;please refer the processor expert sample code under CW10.5 install\MCU\CodeWarrior_Examples\Processor_Expert\Kinetis\TWR-KL25Z48M\SPI&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this helps!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 02:29:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295655#M12160</guid>
      <dc:creator>ZhangJennie</dc:creator>
      <dc:date>2014-03-14T02:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295656#M12161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, I tried PE but found it way too difficult to use, so I'm looking for a simple example that just explain how to do things!&lt;/P&gt;&lt;P&gt;Thank you anyway for the help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 08:59:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295656#M12161</guid>
      <dc:creator>marcopalestro</dc:creator>
      <dc:date>2014-03-14T08:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295657#M12162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, I'm using IAR Embedded Workbench for developing on Kinetis, is there another way to access the example you're referring to?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 09:00:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295657#M12162</guid>
      <dc:creator>marcopalestro</dc:creator>
      <dc:date>2014-03-14T09:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295658#M12163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mark,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thank you for the help, I'm trying to implement this; one thing I don't understand is how is driven the Chip Select pin: It seems to me from reading the datasheet that I should use MODFEN = 1 and SSOE = 1 to use SS as "slave select output", but I don't see any flag regarding SS on your example. Maybe it must be driven by software?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I'm writing the DSPI driver for K series, and I found the usual problems with hardware SPI devices: I cannot use various queue/buffer flags to successfully enqueue next byte without waiting the end of transmission; the result is that, even with high speed, resulting throughput is very low, because the bytes get transmitted fast but there is a long pause between two bytes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is an example of a communication made of 1 byte tx (value CMD_READ_ID) and 3 bytes rx, with chip select asserted during the whole communication:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI0_PUSHR = (CMD_READ_ID | SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS(1));&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((SPI0_SR &amp;amp; SPI_SR_RXCTR_MASK) == 0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; manufacturer_id = SPI0_POPR;&amp;nbsp;&amp;nbsp;&amp;nbsp; // dummy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI0_PUSHR = (0xFF | SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS(1));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((SPI0_SR &amp;amp; SPI_SR_RXCTR_MASK) == 0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; manufacturer_id = SPI0_POPR;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI0_PUSHR = (0xFF | SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS(1));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((SPI0_SR &amp;amp; SPI_SR_RXCTR_MASK) == 0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; device_id1 = SPI0_POPR;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI0_PUSHR = (0xFF | SPI_PUSHR_PCS(1));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((SPI0_SR &amp;amp; SPI_SR_RXCTR_MASK) == 0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; device_id2 = SPI0_POPR;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you know how to speed up the process? I'm expecting the same problem with SPI driver in KL series. In fact I wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;SIM_SCGC4 |= SIM_SCGC4_SPI1_MASK;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTD_PCR4 = PORT_PCR_MUX(2) | PORT_PCR_DSE_MASK;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; // alt2: spi1 cs&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTD_PCR5 = PORT_PCR_MUX(2) | PORT_PCR_DSE_MASK;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; // alt2: spi1 clk&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTD_PCR6 = PORT_PCR_MUX(2) | PORT_PCR_DSE_MASK;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; // alt2: spi1 mosi&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTD_PCR7 = PORT_PCR_MUX(2) | PORT_PCR_DSE_MASK;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; // alt2: spi1 miso&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1_C1 = SPI_C1_MSTR_MASK | SPI_C1_CPHA_MASK | SPI_C1_CPOL_MASK | SPI_C1_SPE_MASK;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1_BR = SPI_BR_SPR(1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1_DL = CMD_READ_ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (SPI1_S &amp;amp; SPI_S_SPRF_MASK);&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; manufacturer_id = SPI1_DL;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; // dummy&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1_DL = 0xFF;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (SPI1_S &amp;amp; SPI_S_SPRF_MASK);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; manufacturer_id = SPI1_DL;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1_DL = 0xFF;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (SPI1_S &amp;amp; SPI_S_SPRF_MASK);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; device_id1 = SPI1_DL;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1_DL = 0xFF;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (SPI1_S &amp;amp; SPI_S_SPRF_MASK);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; device_id2 = SPI1_DL;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But the execution freezes in the last while.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you again&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Marco&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 15:14:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295658#M12163</guid>
      <dc:creator>marcopalestro</dc:creator>
      <dc:date>2014-03-14T15:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295659#M12164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Marco&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I simply control the CS line using an output with the KL's SPI:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;_CLEARBITS(E, PORTE_BIT4); // assert the CS line&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;write/read a number of bytes&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;_SETBITS(E, PORTE_BIT4); // negate the chip select line&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I see no reason why your KL driver should freeze in the last while - as pointed out previously, make sure that this is not due to the debugger reading its status register and clearing the flag that the code is waiting for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the case of the DSPI you can slightly improve performance by making use of the 4 deep FIFO. This allows 4 bytes to be sent at maximum speed (no space between them) but you will still need to wait on the final byte to be completely read in before extracting the final rx data byte. In your case, when reading the manufacturer's ID of an SPI Flash device, you can do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SPI0_PUSHR = (CMD_READ_ID | SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS(1)); // queue 4 writes, controlling the CS line to be asserted at the start and negated after transmission&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SPI0_PUSHR = (0xFF | SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS(1));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SPI0_PUSHR = (0xFF | SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS(1));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SPI0_PUSHR = (0xFF | SPI_PUSHR_PCS(1));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;while ((SPI0_SR &amp;amp; SPI_SR_RXCTR_MASK) &amp;lt; (3 &amp;lt;&amp;lt; 4)); // wait until 3 bytes have been received&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;device_id2 = SPI0_POPR; // 3 dummy reads&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;device_id2 = SPI0_POPR;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;device_id2 = SPI0_POPR;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;while ((SPI0_SR &amp;amp; SPI_SR_RXCTR_MASK) == 0); // wait until the final byte has been received&lt;BR /&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;device_id2 = SPI0_POPR; // the result&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is also possible to wait for all 4 bytes, read 3 dummy ones and then keep the fourth. The above will just be two or three instructions faster (a few ns...) since the 3 byte flush is performed during the fourth byte transmission/reception.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the SPI in the KL doesn't have FIFOs the techniques to improve performance are:&lt;/P&gt;&lt;P&gt;1. Send the first byte.&lt;/P&gt;&lt;P&gt;2. Wait for the TX status to indicate that a further byte can be written. This is before the Rx byte has been received (maybe after about 2 bits transmission - I didn't measure this though).&lt;/P&gt;&lt;P&gt;3. Send the next byte (if there is further data to be sent)&lt;/P&gt;&lt;P&gt;4. Wait for the Rx and read when it is ready.&lt;BR /&gt;5. Go to 2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Configure DMA for Tx and Rx. Let the DMA controller send and receive and wait until the DMA controller informs that the requested number of bytes have been transmitted and received. Then read the 4th byte from the DMA Rx buffer in the example case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S.&amp;nbsp; I use the DSPI and SPI for SD card and AT45DBxxx, ST25P(E)xxx, SSTxxx SPI Flash.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Mar 2014 00:04:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295659#M12164</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2014-03-15T00:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295660#M12165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Mark, I'm slowly getting this thing to work. In the last test, I confused the test condition:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;while ((SPI1_S &amp;amp; SPI_S_SPRF_MASK) == 0);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // read buffer empty&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, it still works weird:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I put a breakpoint just after turning on the peripheral:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SIM_SCGC4 |= SIM_SCGC4_SPI1_MASK;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then the test works fine; if I don't put the breakpoint or execute it without the debugger it stops looping on the first while:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;SIM_SCGC4 |= SIM_SCGC4_SPI1_MASK;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTD_PCR4 = PORT_PCR_MUX(1);&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //PORTD_PCR4 = PORT_PCR_MUX(2) | PORT_PCR_DSE_MASK;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; // alt2: spi1 cs&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTD_PCR5 = PORT_PCR_MUX(2);&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; // alt2: spi1 clk&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTD_PCR6 = PORT_PCR_MUX(2);&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; // alt2: spi1 mosi&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTD_PCR7 = PORT_PCR_MUX(2);&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; // alt2: spi1 miso&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1_C1 = SPI_C1_MSTR_MASK | SPI_C1_CPHA_MASK | SPI_C1_CPOL_MASK | SPI_C1_SPE_MASK;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1_BR = SPI_BR_SPR(1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // test&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F_CS_H;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F_CS_L;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1_DL = CMD_READ_ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((SPI1_S &amp;amp; SPI_S_SPRF_MASK) == 0);&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; manufacturer_id = SPI1_DL;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; // dummy&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI1_DL = 0xFF;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((SPI1_S &amp;amp; SPI_S_SPRF_MASK) == 0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; manufacturer_id = SPI1_DL;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Really can't get how it's supposed to be... &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Mar 2014 14:50:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295660#M12165</guid>
      <dc:creator>marcopalestro</dc:creator>
      <dc:date>2014-03-17T14:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295661#M12166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just as &lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/ZhangJennie"&gt;ZhangJennie&lt;/A&gt; mentioned, you can download the &lt;A href="http://cache.freescale.com/files/32bit/software/KL25_SC.exe?fasp=1&amp;amp;WT_TYPE=Lab%20and%20Test%20Software&amp;amp;WT_VENDOR=FREESCALE&amp;amp;WT_FILE_FORMAT=exe&amp;amp;WT_ASSET=Downloads"&gt;&lt;STRONG&gt;FRDM-KL25Z and TWRKL25Z48M Sample Code Package&lt;/STRONG&gt;&lt;/A&gt; and use the IAR example code as base for your development, you will find it in this path:&lt;/P&gt;&lt;P&gt;C:\(your download path)\KL25 Sample Code\kl25_sc_rev10\klxx-sc-pex\projects\spi_demo\iar&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a nice day :P,&lt;BR /&gt;Perla&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>Wed, 16 Apr 2014 21:52:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295661#M12166</guid>
      <dc:creator>perlam_i_au</dc:creator>
      <dc:date>2014-04-16T21:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295662#M12167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Perla&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any SPI example for the KL26Z MCu? I am configuring the KL25Z SPI example to Kl26Z board not succeeded.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for you are help,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ram.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Aug 2014 10:12:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295662#M12167</guid>
      <dc:creator>microeval</dc:creator>
      <dc:date>2014-08-14T10:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: SPI example on Kinetis KL16</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295663#M12168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ram&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See &lt;A _jive_internal="true" href="https://community.nxp.com/message/427243?et=watches.email.thread" title="https://community.freescale.com/message/427243?et=watches.email.thread"&gt;https://community.freescale.com/message/427243?et=watches.email.thread&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SPI peripheral in the KL26 is not fully compatible with the one in the KL25. You need KL46 example code, which is compatible in relation to the SPI, or you can take complete working code from the uTasker project which works on all KL and K parts (automatically adapts itself accordingly).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.utasker.com/kinetis.html" title="http://www.utasker.com/kinetis.html"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Aug 2014 13:49:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SPI-example-on-Kinetis-KL16/m-p/295663#M12168</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2014-08-14T13:49:24Z</dc:date>
    </item>
  </channel>
</rss>

