<?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>topic Re: Not getting correct values from SPI_ReadData() in Kinetis Software Development Kit</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Not-getting-correct-values-from-SPI-ReadData/m-p/663642#M7280</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gavin Smith,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Please modify your code:&lt;/P&gt;&lt;P&gt;BYTE SPIGet(void)&lt;BR /&gt;{&lt;BR /&gt;WORD RxData;&lt;BR /&gt;Delay10us(100);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;while (0 == (SPI_GetStatusFlags (SPI0) &amp;amp; kSPI_TxBufferEmptyFlag)); // wait for data to be sent.&lt;/P&gt;&lt;P&gt;SPI_WriteData(SPI0,SPI_DUMMYDATA);&lt;BR /&gt; while (0 == (SPI_GetStatusFlags (SPI0) &amp;amp; kSPI_RxBufferFullFlag)); // wait for data to be received.&lt;BR /&gt;RxData = SPI_ReadData(SPI0);&lt;BR /&gt; Delay10us(1000);&lt;BR /&gt; return (BYTE)(RxData);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Then test it again.&lt;/P&gt;&lt;P&gt;If you still have problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Please also give us the main code you write in the master and the SPI wave in the SPI bus.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Kerry&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>Tue, 10 Jan 2017 05:24:29 GMT</pubDate>
    <dc:creator>kerryzhou</dc:creator>
    <dc:date>2017-01-10T05:24:29Z</dc:date>
    <item>
      <title>Not getting correct values from SPI_ReadData()</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Not-getting-correct-values-from-SPI-ReadData/m-p/663641#M7279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, trying to use the SPI for single byte read / write operations using Kinetis&amp;nbsp;MKL16Z128VFM4 and sdk2.0&lt;/P&gt;&lt;P&gt;When using SPI_ReadData, the values seem to be one byte behind what I expect.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my config, send and receive functions.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Setup SPI for radio&lt;BR /&gt; spi_master_config_t config;&lt;BR /&gt; SPI_MasterGetDefaultConfig(&amp;amp;config);&lt;BR /&gt; config.pinMode = kSPI_SlaveSelectAsGpio;&lt;BR /&gt; config.baudRate_Bps = 50000;&lt;BR /&gt; SPI_MasterInit(SPI0, &amp;amp;config, CLOCK_GetFreq(kCLOCK_PllFllSelClk));&lt;BR /&gt; SPI_Enable (SPI0, true);&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void SPIPut(unsigned char v)&lt;BR /&gt;{&lt;BR /&gt; volatile DWORD StatusFlags;&lt;BR /&gt; DWORD ulDummy;&lt;BR /&gt; DWORD Byte;&lt;BR /&gt; //ulDummy = SPI_ReadData(SPI0);&lt;BR /&gt; Delay10us(1);&lt;BR /&gt; SPI_WriteData(SPI0,v);&lt;BR /&gt; while (0 == (SPI_GetStatusFlags (SPI0) &amp;amp; kSPI_TxBufferEmptyFlag)); // wait for data to be sent.&lt;BR /&gt; Delay10us(1000);&lt;BR /&gt; ulDummy = SPI_ReadData(SPI0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;BYTE SPIGet(void)&lt;BR /&gt;{&lt;BR /&gt;WORD RxData;&lt;BR /&gt;Delay10us(100);&lt;BR /&gt; SPI_WriteData(SPI0,SPI_DUMMYDATA);&lt;BR /&gt; while (0 == (SPI_GetStatusFlags (SPI0) &amp;amp; kSPI_TxBufferEmptyFlag)); // wait for data to be sent.&lt;BR /&gt; while (0 == (SPI_GetStatusFlags (SPI0) &amp;amp; kSPI_RxBufferFullFlag)); // wait for data to be received.&lt;BR /&gt; Delay10us(1000);&lt;BR /&gt; RxData = SPI_ReadData(SPI0);&lt;BR /&gt; Delay10us(1000);&lt;BR /&gt; return (BYTE)(RxData);&lt;BR /&gt;}&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To read a register from my slave device, i send it the register address using SPIPut, then do an SPIGet to read the register value.&lt;/P&gt;&lt;P&gt;when reading the registers say 0 - 5, I expect to get&lt;/P&gt;&lt;P&gt;0x28&lt;/P&gt;&lt;P&gt;0x88&lt;/P&gt;&lt;P&gt;0x03&lt;/P&gt;&lt;P&gt;0x07&lt;/P&gt;&lt;P&gt;0x0C&lt;/P&gt;&lt;P&gt;and my scope confirms that this is what is being sent.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but what I actually get from the SPI_ReadData function is&lt;/P&gt;&lt;P&gt;0x28&lt;/P&gt;&lt;P&gt;0x28&lt;/P&gt;&lt;P&gt;0x88&lt;/P&gt;&lt;P&gt;0x03&lt;/P&gt;&lt;P&gt;0x07&lt;/P&gt;&lt;P&gt;0x0C&lt;/P&gt;&lt;P&gt;So the 1st byte reads correctly, then all subsequent bytes are out by one. Its almost like there is a buffer somewhere. Any ideas what I am doing wrong?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jan 2017 16:33:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Not-getting-correct-values-from-SPI-ReadData/m-p/663641#M7279</guid>
      <dc:creator>gavinsmith</dc:creator>
      <dc:date>2017-01-05T16:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Not getting correct values from SPI_ReadData()</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Not-getting-correct-values-from-SPI-ReadData/m-p/663642#M7280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gavin Smith,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Please modify your code:&lt;/P&gt;&lt;P&gt;BYTE SPIGet(void)&lt;BR /&gt;{&lt;BR /&gt;WORD RxData;&lt;BR /&gt;Delay10us(100);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;while (0 == (SPI_GetStatusFlags (SPI0) &amp;amp; kSPI_TxBufferEmptyFlag)); // wait for data to be sent.&lt;/P&gt;&lt;P&gt;SPI_WriteData(SPI0,SPI_DUMMYDATA);&lt;BR /&gt; while (0 == (SPI_GetStatusFlags (SPI0) &amp;amp; kSPI_RxBufferFullFlag)); // wait for data to be received.&lt;BR /&gt;RxData = SPI_ReadData(SPI0);&lt;BR /&gt; Delay10us(1000);&lt;BR /&gt; return (BYTE)(RxData);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Then test it again.&lt;/P&gt;&lt;P&gt;If you still have problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Please also give us the main code you write in the master and the SPI wave in the SPI bus.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Kerry&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>Tue, 10 Jan 2017 05:24:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Not-getting-correct-values-from-SPI-ReadData/m-p/663642#M7280</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2017-01-10T05:24:29Z</dc:date>
    </item>
  </channel>
</rss>

