<?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 Software Development Kit中的主题 Re: KL17 SPI always reads 0xff, scope shows valid MISO waveform.</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658674#M7147</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I recently learned some more about this problem.&amp;nbsp; When I update the code, I am using blhost.exe to do the update from the PC over RS232.&amp;nbsp; After the firmware update, I use the &lt;STRONG&gt;reset&lt;/STRONG&gt; command in blhost to get the CPU to jump back to the application and begin executing the new code.&amp;nbsp; What I discovered is when the CPU begins executing code from blhost, it does not read the SPI properly.&amp;nbsp; If I then reset the CPU by using the reset button on the eval board, the SPI reads properly.&amp;nbsp; If I do a cold boot by applying power to the board, the same code will boot up and work properly.&amp;nbsp; One other test I did was put the CPU in the boot code but instead of doing a firmware update, I only commanded the CPU to reset and when the code came out of reset, the SPI did not work properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I apply power and the board boots up and runs properly, I assume that everything that needs to be configured on the CPU that needs to be is configured properly by the application.&amp;nbsp; When the CPU goes &amp;nbsp;from boot to application, it appears that the boot is leaving something in a bad state.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI, use the following to put the CPU into the bootloader:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: #7f0055; font-size: 10.0pt;"&gt;void&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt; &lt;STRONG&gt;jumToBootloader&lt;/STRONG&gt;(&lt;/SPAN&gt;&lt;STRONG style="color: #7f0055; font-size: 10.0pt;"&gt;void&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt; runBootloaderAddress;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; runBootloaderAddress = **(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt; **) (0x1c00001c);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; runBootloader = (&lt;/SPAN&gt;&lt;STRONG style="color: #7f0055; font-size: 10.0pt;"&gt;void&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt; (*) (&lt;/SPAN&gt;&lt;STRONG style="color: #7f0055; font-size: 10.0pt;"&gt;void&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt; * arg)) runBootloaderAddress;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; runBootloader(NULL);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;Any ideas?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;Doug&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Feb 2017 13:29:49 GMT</pubDate>
    <dc:creator>dougbaker</dc:creator>
    <dc:date>2017-02-23T13:29:49Z</dc:date>
    <item>
      <title>KL17 SPI always reads 0xff, scope shows valid MISO waveform.</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658673#M7146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;I have a FRDM-KL-27Z eval board where we changed the CPU to a KL17.&amp;nbsp; We hooked up an ST h3lis331dl accelerometer that has a SPI interface and wired it to the KL27 board.&amp;nbsp; &amp;nbsp;On the KL27 board, we have the SPI from the ST h3lis331dl hooked up as follows.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;PTD0 is the chip select. &amp;nbsp;&amp;nbsp;&amp;nbsp;PTD0-1 On J1 connector&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;PTD1 is the SPI0 clock &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PTD1-3 On J1 connector&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;PTD2 is the SPI0 MOSI&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;PTD2-5 On J1 connector&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;PTD3 is the SPI0 MISO&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;PTD3-7 On J1 connector&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;I am using KDS 3.2.0 as a dev environment am I am starting from an example SPI_polling_transfer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;On the ST h3lis331dl, there is a register I can read called the WHO_AM_I that will reply a fixed reply of 0x32.&amp;nbsp; Based on some sample code and the documentation for the Kinetis, I can confirm that the SPI is working properly by looking at the waveforms on a scope.&amp;nbsp; The scope shows is the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;1 The chip select asserted&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;2 The SPI clock starts and the MOSI has the correct waveform for the address for the WHO_AM_I register. &amp;nbsp;&amp;nbsp;This is an 8 bit burst on the bus.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;3 there is a slight pause in the SPI clock&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;4 The SPI clock starts again and the correct reply is seen on the MISO pin.&amp;nbsp; The scope shows that MISO had the data 0x32.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;5 The chip select is de asserted&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;6 the problem I have is when I get the data from the SPI, I do not get the data value I expect.&amp;nbsp; I expect to see the value 0x32 but I see 0xff.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;My Pin mux is:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CLOCK_EnableClock(&lt;/SPAN&gt;&lt;EM style="color: #0000c0; font-size: 8.0pt;"&gt;kCLOCK_PortD&lt;/EM&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #3f7f5f;"&gt;//PORT_SetPinMux(PORTD, 0U, kPORT_MuxAlt2);&amp;nbsp;&amp;nbsp; // SPI chip select&amp;nbsp;&amp;nbsp; //automatic CS&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORT_SetPinMux(PORTD, 1U, &lt;/SPAN&gt;&lt;EM style="color: #0000c0; font-size: 8.0pt;"&gt;kPORT_MuxAlt2&lt;/EM&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;); &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #3f7f5f;"&gt;// SPI0-SCK&amp;nbsp; PTD1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORT_SetPinMux(PORTD, 2U, &lt;/SPAN&gt;&lt;EM style="color: #0000c0; font-size: 8.0pt;"&gt;kPORT_MuxAlt2&lt;/EM&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;); &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #3f7f5f;"&gt;// SPI0-MOSI PTD2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORT_SetPinMux(PORTD, 3U, &lt;/SPAN&gt;&lt;EM style="color: #0000c0; font-size: 8.0pt;"&gt;kPORT_MuxAlt2&lt;/EM&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;); &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #3f7f5f;"&gt;// SPI0-MISO PTD3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: #3f7f5f;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;My SPI config is:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp; SPI_MasterGetDefaultConfig(&amp;amp;masterConfig);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp; sourceClock = CLOCK_GetFreq(EXAMPLE_SPI_MASTER_SOURCE_CLOCK);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp; SPI_MasterInit(SPI_0_MASTER, &amp;amp;masterConfig, sourceClock);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;My code to read the SPI is the following:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;#define BUFFER_SIZE 64U&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;uint8_t spi_data_IN[BUFFER_SIZE];&amp;nbsp; // &amp;lt;&amp;lt;&amp;lt; this is a global.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: .5in;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;spi_transfer_t xfer = {0};&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: .5in;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: .5in;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: .5in;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;lt;SNIP&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: .5in;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: .5in;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;memset(spi_data_IN, 0x55, sizeof(spi_data_IN));&amp;nbsp; // init the data to a known value&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: .5in;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt; text-indent: .5in;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;/* SPI master start transfer */&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; xfer.txData = (uint8_t *) SPI_data.sendDataSPI;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;//xfer.rxData = (uint8_t *) &amp;amp;SPI_data.receivedDataSPI[0];&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; xfer.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;rxData&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; = spi_data_IN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; xfer.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;dataSize&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt; = SPI_data.&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #0000c0;"&gt;totalDataBytes&lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; spi_accel_chipselect(TRUE); &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #3f7f5f;"&gt;// select the device to read/write (chip select)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; reuturnValue = SPI_MasterTransferBlocking(SPI_MASTER, &amp;amp;xfer); // note the return value is OK&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; spi_accel_chipselect(FALSE); &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; color: #3f7f5f;"&gt;// select the device to read/write (chip select)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PRINTF("post read Data rx = %x %x %x&amp;nbsp; %x %x\r\n",&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; spi_data_IN[0],&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; spi_data_IN[1],&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; spi_data_IN[2],&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; spi_data_IN[3],&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; spi_data_IN[4]);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&amp;nbsp; OUTPUT data from above print statement:&amp;nbsp; &lt;STRONG&gt;post read Data rx = ff ff 55&amp;nbsp; 55 55&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12.0pt;"&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12.0pt;"&gt;My question is why do I read in the buffer a value of 0xff and not 0x32 when the scope shows I should be reading 0x32?&amp;nbsp; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #7f0055; font-size: 8.0pt;"&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI style="margin-left: .5in; text-indent: -.25in;"&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;I can confirm that the MISO pin has a good connection between the PTD3-7 pin on the eval board and the physical pin 60 on the CPU.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI style="margin-left: .5in; text-indent: -.25in;"&gt;&lt;SPAN style="font-size: 12.0pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 12.0pt;"&gt;If I use masterConfig.pinMode = kSPI_PinModeOutput;, the waveforms on the scope are still good but I read 0x8f. The 0x8f is what I write on the first byte.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2017 15:57:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658673#M7146</guid>
      <dc:creator>dougbaker</dc:creator>
      <dc:date>2017-02-22T15:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: KL17 SPI always reads 0xff, scope shows valid MISO waveform.</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658674#M7147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I recently learned some more about this problem.&amp;nbsp; When I update the code, I am using blhost.exe to do the update from the PC over RS232.&amp;nbsp; After the firmware update, I use the &lt;STRONG&gt;reset&lt;/STRONG&gt; command in blhost to get the CPU to jump back to the application and begin executing the new code.&amp;nbsp; What I discovered is when the CPU begins executing code from blhost, it does not read the SPI properly.&amp;nbsp; If I then reset the CPU by using the reset button on the eval board, the SPI reads properly.&amp;nbsp; If I do a cold boot by applying power to the board, the same code will boot up and work properly.&amp;nbsp; One other test I did was put the CPU in the boot code but instead of doing a firmware update, I only commanded the CPU to reset and when the code came out of reset, the SPI did not work properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I apply power and the board boots up and runs properly, I assume that everything that needs to be configured on the CPU that needs to be is configured properly by the application.&amp;nbsp; When the CPU goes &amp;nbsp;from boot to application, it appears that the boot is leaving something in a bad state.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI, use the following to put the CPU into the bootloader:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: #7f0055; font-size: 10.0pt;"&gt;void&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt; &lt;STRONG&gt;jumToBootloader&lt;/STRONG&gt;(&lt;/SPAN&gt;&lt;STRONG style="color: #7f0055; font-size: 10.0pt;"&gt;void&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt; runBootloaderAddress;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; runBootloaderAddress = **(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; color: #005032;"&gt;uint32_t&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt; **) (0x1c00001c);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; runBootloader = (&lt;/SPAN&gt;&lt;STRONG style="color: #7f0055; font-size: 10.0pt;"&gt;void&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt; (*) (&lt;/SPAN&gt;&lt;STRONG style="color: #7f0055; font-size: 10.0pt;"&gt;void&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt; * arg)) runBootloaderAddress;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; runBootloader(NULL);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;Any ideas?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; color: black;"&gt;Doug&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Feb 2017 13:29:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658674#M7147</guid>
      <dc:creator>dougbaker</dc:creator>
      <dc:date>2017-02-23T13:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: KL17 SPI always reads 0xff, scope shows valid MISO waveform.</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658675#M7148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Doug,&lt;/P&gt;&lt;P&gt;I have checked the required spi timing of the slave spi STM product, you have to set both the CPHA bit and CPOL bit in &lt;SPAN style="font-size: 8.0pt; color: black;"&gt;masterConfig&lt;/SPAN&gt; so that the spi timing are matched. I copy the spi timing of both slave and master devices.&lt;/P&gt;&lt;P&gt;Pls check the two bits.&lt;/P&gt;&lt;P&gt;Hope it can help you&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Xiangjun Rong&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/13932iFAF1579868FD4AE7/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Feb 2017 08:43:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658675#M7148</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2017-02-27T08:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: KL17 SPI always reads 0xff, scope shows valid MISO waveform.</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658676#M7149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As far as the SPI not working following a reset from boot, there is no change by changing the clock phase and polarity.&amp;nbsp; To restate the problem, if I jump to boot, then&amp;nbsp; I do a reset in boot to get the CPU to begin executing the application code, the SPI does not work properly.&amp;nbsp; If I hit the reset button on the board or just power up the board and run, the SPI will work properly. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Doug&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Feb 2017 15:23:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658676#M7149</guid>
      <dc:creator>dougbaker</dc:creator>
      <dc:date>2017-02-27T15:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: KL17 SPI always reads 0xff, scope shows valid MISO waveform.</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658677#M7150</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've just experienced a similar problem with the KL27 &amp;amp; found the root cause.&amp;nbsp; The BootLoader leaves PortC (pins 4,5,6 &amp;amp; 7) assigned for SPI0 use.&amp;nbsp; Configuring SPI0 for the PortD pins results in a conflict which, in particular, prevents MISO data from being latched into the SPI0 data register from the PortD pin.&amp;nbsp; The solution is to re-assign the PortC pins to GPIO (or anything other than SPI0 duty!) during the init phase of your code, allowing the PortD SPI0 definitions to actually work!&lt;/P&gt;&lt;P&gt;(Beware -- the Boot also leaves pins defined for LPUART0 &amp;amp; I2C0 use upon exit.....&amp;nbsp; Refer to the Kinetis Bootloader Peripheral Pinmux table in the manual.)&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Randy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Jun 2017 15:02:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658677#M7150</guid>
      <dc:creator>randythomas</dc:creator>
      <dc:date>2017-06-16T15:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: KL17 SPI always reads 0xff, scope shows valid MISO waveform.</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658678#M7151</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the info!&lt;/P&gt;&lt;P&gt;Doug&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Jun 2017 19:44:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL17-SPI-always-reads-0xff-scope-shows-valid-MISO-waveform/m-p/658678#M7151</guid>
      <dc:creator>dougbaker</dc:creator>
      <dc:date>2017-06-22T19:44:23Z</dc:date>
    </item>
  </channel>
</rss>

