<?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: [Help]K64F SPI Bare Metal example</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-K64F-SPI-Bare-Metal-example/m-p/412110#M23348</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Earl,&lt;/P&gt;&lt;P&gt;I'm not using KSDK libraries purposely.&lt;/P&gt;&lt;P&gt;On really, I need to be able to manipulate the registers, because I'm trying to Develop my own SPI library, with some peculiarities specific to my project.&lt;/P&gt;&lt;P&gt;This is part of configuration for SPI0 in my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SPI0_INTERFACE:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SIM_SCGC5 |= MuxConfig[SPI_DeviceList[ID].RoutedPort].mask;// Enable PORT clock gating ctrl&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SIM_SCGC6 |= SIM_SCGC6_SPI0_MASK; //Turn on clock to SPI module&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;PORT_PCR_REG(MuxConfig[SPI_DeviceList[ID].RoutedPort].port, MuxConfig[SPI_DeviceList[ID].RoutedPort].sck_pin) = PORT_PCR_MUX(MuxConfig[SPI_DeviceList[ID].RoutedPort].mux);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;PORT_PCR_REG(MuxConfig[SPI_DeviceList[ID].RoutedPort].port, MuxConfig[SPI_DeviceList[ID].RoutedPort].sin_pin) = PORT_PCR_MUX(MuxConfig[SPI_DeviceList[ID].RoutedPort].mux);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;PORT_PCR_REG(MuxConfig[SPI_DeviceList[ID].RoutedPort].port, MuxConfig[SPI_DeviceList[ID].RoutedPort].sout_pin) = PORT_PCR_MUX(MuxConfig[SPI_DeviceList[ID].RoutedPort].mux);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;PORT_PCR_REG(MuxSCConfig[SPI_DeviceList[ID].ChipSelect].port,MuxSCConfig[SPI_DeviceList[ID].ChipSelect].pcs_pin) = PORT_PCR_MUX(MuxSCConfig[SPI_DeviceList[ID].ChipSelect].mux);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SPI0_MCR |= SPI_MCR_MSTR_MASK | SPI_DeviceList[ID].CSOption;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SPI0_MCR &amp;amp;= ~SPI_MCR_DIS_TXF_MASK; // enable FIFOs&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SPI0_CTAR0 |=&amp;nbsp; SPI_CTAR_FMSZ(8) | SPI_DeviceList[ID].CSOption | SPI_DeviceList[ID].Polarity | SPI_DeviceList[ID].Phase | SPI_DeviceList[ID].BaudRate;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;NVIC_EnableIRQ(SPI0_IRQn);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;I found some examples useful like this &lt;A href="https://community.nxp.com/message/500702"&gt;SPI Master always sends 16 bits words in non-continuous mode&lt;/A&gt; &lt;/P&gt;&lt;P&gt;But nothing significative.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need an functional example, configurating the port, pin, baud rate, sending and receiving data through SPI to verify my code and find my error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 Sep 2015 13:01:41 GMT</pubDate>
    <dc:creator>rafaeltoledo</dc:creator>
    <dc:date>2015-09-02T13:01:41Z</dc:date>
    <item>
      <title>[Help]K64F SPI Bare Metal example</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-K64F-SPI-Bare-Metal-example/m-p/412108#M23346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Someone has an SPI code example preferably with interrupt for FRDM-K64F?&lt;/P&gt;&lt;P&gt;It may be a example without interrupt also, already help me a lot because I can't make the SPI work only by reading the reference manual.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 17:47:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-K64F-SPI-Bare-Metal-example/m-p/412108#M23346</guid>
      <dc:creator>rafaeltoledo</dc:creator>
      <dc:date>2015-08-31T17:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: [Help]K64F SPI Bare Metal example</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-K64F-SPI-Bare-Metal-example/m-p/412109#M23347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Rafael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you interested in using the Kinetis SDK? It provides comprehensive software support for Kinetis MCUs. It includes a hardware abstraction layer (HAL) and drivers for each MCU peripheral, USB and connectivity stacks, middleware, real-time operating systems and example applications designed to simplify and accelerate application development on Kinetis MCUs. The Kinetis SDK is complimentary and includes full source code under a permissive open-source license for all hardware abstraction and peripheral driver software. The Kinetis SDK is offered for free, and support for it is provided here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course the SPI driver is supported by KSDK. Examples about its usage are located in the installation path in the folder &lt;STRONG&gt;C:\Freescale\KSDK_1.2.0\examples&lt;/STRONG&gt;, you can see the &lt;STRONG&gt;spi_sdcard&lt;/STRONG&gt; example in the folder &lt;STRONG&gt;C:\Freescale\KSDK_1.2.0\examples\twrk22f120m\driver_examples\spi_sdcard&lt;/STRONG&gt;, this is built for the K22 MCU but due to the portability that offers KSDK, this is exactly the same code for the K64 MCU. Also, you can take a look into the SPI driver examples built to the KL devices.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, you can take a look into the document &lt;A href="https://community.nxp.com/docs/DOC-103944"&gt;KSDK SPI Master-Slave with FRDM-K64F.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let me know if this information is useful or if I can do anything else for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Earl Orlando.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/* If this post answers your question please click the Correct Answer button. */&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Sep 2015 22:19:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-K64F-SPI-Bare-Metal-example/m-p/412109#M23347</guid>
      <dc:creator>EarlOrlando</dc:creator>
      <dc:date>2015-09-01T22:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: [Help]K64F SPI Bare Metal example</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-K64F-SPI-Bare-Metal-example/m-p/412110#M23348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Earl,&lt;/P&gt;&lt;P&gt;I'm not using KSDK libraries purposely.&lt;/P&gt;&lt;P&gt;On really, I need to be able to manipulate the registers, because I'm trying to Develop my own SPI library, with some peculiarities specific to my project.&lt;/P&gt;&lt;P&gt;This is part of configuration for SPI0 in my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SPI0_INTERFACE:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SIM_SCGC5 |= MuxConfig[SPI_DeviceList[ID].RoutedPort].mask;// Enable PORT clock gating ctrl&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SIM_SCGC6 |= SIM_SCGC6_SPI0_MASK; //Turn on clock to SPI module&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;PORT_PCR_REG(MuxConfig[SPI_DeviceList[ID].RoutedPort].port, MuxConfig[SPI_DeviceList[ID].RoutedPort].sck_pin) = PORT_PCR_MUX(MuxConfig[SPI_DeviceList[ID].RoutedPort].mux);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;PORT_PCR_REG(MuxConfig[SPI_DeviceList[ID].RoutedPort].port, MuxConfig[SPI_DeviceList[ID].RoutedPort].sin_pin) = PORT_PCR_MUX(MuxConfig[SPI_DeviceList[ID].RoutedPort].mux);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;PORT_PCR_REG(MuxConfig[SPI_DeviceList[ID].RoutedPort].port, MuxConfig[SPI_DeviceList[ID].RoutedPort].sout_pin) = PORT_PCR_MUX(MuxConfig[SPI_DeviceList[ID].RoutedPort].mux);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;PORT_PCR_REG(MuxSCConfig[SPI_DeviceList[ID].ChipSelect].port,MuxSCConfig[SPI_DeviceList[ID].ChipSelect].pcs_pin) = PORT_PCR_MUX(MuxSCConfig[SPI_DeviceList[ID].ChipSelect].mux);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SPI0_MCR |= SPI_MCR_MSTR_MASK | SPI_DeviceList[ID].CSOption;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SPI0_MCR &amp;amp;= ~SPI_MCR_DIS_TXF_MASK; // enable FIFOs&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;SPI0_CTAR0 |=&amp;nbsp; SPI_CTAR_FMSZ(8) | SPI_DeviceList[ID].CSOption | SPI_DeviceList[ID].Polarity | SPI_DeviceList[ID].Phase | SPI_DeviceList[ID].BaudRate;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 8pt; font-family: arial, helvetica, sans-serif;"&gt;NVIC_EnableIRQ(SPI0_IRQn);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;I found some examples useful like this &lt;A href="https://community.nxp.com/message/500702"&gt;SPI Master always sends 16 bits words in non-continuous mode&lt;/A&gt; &lt;/P&gt;&lt;P&gt;But nothing significative.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need an functional example, configurating the port, pin, baud rate, sending and receiving data through SPI to verify my code and find my error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Sep 2015 13:01:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-K64F-SPI-Bare-Metal-example/m-p/412110#M23348</guid>
      <dc:creator>rafaeltoledo</dc:creator>
      <dc:date>2015-09-02T13:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: [Help]K64F SPI Bare Metal example</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-K64F-SPI-Bare-Metal-example/m-p/412111#M23349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #303030;"&gt;I developed a example of Sending/Receiving data:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;#define SPI_PUSHR_PCS0_ON 0x10000&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;#define SPI_PUSHR_PCS1_ON 0x20000&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;#define SPI_PUSHR_PCS2_ON 0x40000&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;#define SPI_PUSHR_PCS3_ON 0x80000&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;#define SPI_PUSHR_PCS4_ON 0x100000&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;#define SPI_PUSHR_PCS5_ON 0x200000&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;#define SPI_CTAR_FMSZ_8BIT 0x38000000&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;#define SPI_CTAR_FMSZ_16BIT 0x78000000&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;int main(void)&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;{&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; unsigned char cmd = 0x01;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;unsigned char receiveBuffer[3];&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; //configure ports&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK; // Enable PORT clock gating ctrl&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SIM_SCGC6 |= SIM_SCGC6_SPI0_MASK;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; //PORT D&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; PORTD_PCR(0) = PORT_PCR_MUX(2); //PCS0&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; PORTD_PCR(1) = PORT_PCR_MUX(2); //SCK&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; PORTD_PCR(2) = PORT_PCR_MUX(2); //SOUT&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; PORTD_PCR(3) = PORT_PCR_MUX(2); //SIN&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; // Clear all registers&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_SR = (SPI_SR_TCF_MASK | SPI_SR_EOQF_MASK | SPI_SR_TFUF_MASK | SPI_SR_TFFF_MASK | SPI_SR_RFOF_MASK | SPI_SR_RFDF_MASK); //clear the status bits (write-1-to-clear)&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_TCR = 0;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_RSER = 0;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_PUSHR = 0; //Clear out PUSHR register. Since DSPI is halted, nothing should be transmitted&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_CTAR0 = 0;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; // configure registers&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_MCR |= SPI_MCR_MSTR_MASK | SPI_MCR_PCSIS_MASK;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_MCR &amp;amp;= (~SPI_MCR_DIS_RXF_MASK &amp;amp; ~SPI_MCR_DIS_TXF_MASK); // enable FIFOs&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_MCR &amp;amp;=&amp;nbsp; (~SPI_MCR_MDIS_MASK &amp;amp; ~SPI_MCR_HALT_MASK); //enable SPI and start transfer&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_CTAR0 |=&amp;nbsp; SPI_CTAR_FMSZ_8BIT | SPI_CTAR_CPOL_MASK | SPI_CTAR_CPHA_MASK | SPI_CTAR_BR(6); // 8 bits, 500khz at 120Mhz&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;// Send Steps:&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; while(1){&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_MCR |=&amp;nbsp; SPI_MCR_HALT_MASK;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_MCR |= (SPI_MCR_CLR_RXF_MASK | SPI_MCR_CLR_TXF_MASK); //flush the fifos&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_SR |= (SPI_SR_TCF_MASK | SPI_SR_EOQF_MASK | SPI_SR_TFUF_MASK | SPI_SR_TFFF_MASK | SPI_SR_RFOF_MASK | SPI_SR_RFDF_MASK); //clear the status bits (write-1-to-clear)&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_TCR |= SPI_TCR_SPI_TCNT_MASK;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_MCR &amp;amp;=&amp;nbsp; ~SPI_MCR_HALT_MASK;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_PUSHR = (SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS0_ON | cmd);&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; while(!(SPI0_SR &amp;amp; SPI_SR_TCF_MASK));&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_PUSHR = (SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS0_ON | 0xAA);&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; while(!(SPI0_SR &amp;amp; SPI_SR_TCF_MASK));&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_PUSHR = (SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS0_ON | 0xBB);&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; while(!(SPI0_SR &amp;amp; SPI_SR_TCF_MASK));&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_PUSHR = (SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS0_ON | 0xCC);&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; while(!(SPI0_SR &amp;amp; SPI_SR_TCF_MASK));&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_PUSHR = (SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS0_ON | 0xDD);&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; while(!(SPI0_SR &amp;amp; SPI_SR_TCF_MASK));&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_PUSHR = (SPI_PUSHR_EOQ_MASK | SPI_PUSHR_PCS0_ON | 0xEE); //send last byte&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_SR |= SPI_SR_TFFF_MASK; //clear the status bits (write-1-to-clear)&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; cmd++;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; }&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;//*****************************************************************************************************************************************&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;//Receive Steps: (tested with memory MX25L3206E)&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;while(1){&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_MCR |=&amp;nbsp; SPI_MCR_HALT_MASK;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_MCR |= (SPI_MCR_CLR_RXF_MASK | SPI_MCR_CLR_TXF_MASK); //flush the fifos&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_SR |= (SPI_SR_TCF_MASK | SPI_SR_EOQF_MASK | SPI_SR_TFUF_MASK | SPI_SR_TFFF_MASK | SPI_SR_RFOF_MASK | SPI_SR_RFDF_MASK); //clear the status bits (write-1-to-clear)&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_TCR |= SPI_TCR_SPI_TCNT_MASK;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_MCR &amp;amp;=&amp;nbsp; ~SPI_MCR_HALT_MASK;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_PUSHR = (SPI_PUSHR_CONT_MASK |&amp;nbsp; SPI_PUSHR_PCS_MASK | 0x9F); //command byte&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; while (!(SPI0_SR &amp;amp; SPI_SR_RFDF_MASK)&amp;nbsp; );&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_POPR; //dummy read&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_SR = SPI_SR_RFDF_MASK;&amp;nbsp;&amp;nbsp; // clear the reception flag (not self-clearing)&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_PUSHR = (SPI_PUSHR_CONT_MASK | &lt;EM style="color: #3334ca; font-family: arial, helvetica, sans-serif; font-size: 13.3333px;"&gt;SPI_PUSHR_PCS0_ON &lt;/EM&gt;| 0xFF); //dummy byte to read&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; while (!(SPI0_SR &amp;amp; SPI_SR_RFDF_MASK)&amp;nbsp; );&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; receiveBuffer[0] = SPI0_POPR; //read&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_SR = SPI_SR_RFDF_MASK;&amp;nbsp;&amp;nbsp; // clear the reception flag (not self-clearing)&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_PUSHR = (SPI_PUSHR_CONT_MASK |&amp;nbsp; &lt;EM style="color: #3334ca; font-family: arial, helvetica, sans-serif; font-size: 13.3333px;"&gt;SPI_PUSHR_PCS0_ON &lt;/EM&gt;| 0xFF); //dummy byte to read&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; while (!(SPI0_SR &amp;amp; SPI_SR_RFDF_MASK)&amp;nbsp; );&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; receiveBuffer[1] = SPI0_POPR; //read&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_SR = SPI_SR_RFDF_MASK;&amp;nbsp;&amp;nbsp; // clear the reception flag (not self-clearing)&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_PUSHR = (SPI_PUSHR_EOQ_MASK | &lt;EM style="color: #3334ca; font-family: arial, helvetica, sans-serif; font-size: 13.3333px;"&gt;SPI_PUSHR_PCS0_ON &lt;/EM&gt;| 0xFF); //send last dummy byte to read&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; while (!(SPI0_SR &amp;amp; SPI_SR_RFDF_MASK)&amp;nbsp; );&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; receiveBuffer[2] = SPI0_POPR; //read&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; SPI0_SR = SPI_SR_RFDF_MASK;&amp;nbsp;&amp;nbsp; // clear the reception flag (not self-clearing)&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca; font-size: 10pt;"&gt;&lt;EM&gt;&amp;nbsp; }&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;&amp;nbsp; return 0;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #3334ca;"&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Sep 2015 18:15:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-K64F-SPI-Bare-Metal-example/m-p/412111#M23349</guid>
      <dc:creator>rafaeltoledo</dc:creator>
      <dc:date>2015-09-03T18:15:37Z</dc:date>
    </item>
  </channel>
</rss>

