<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>8-bit MicrocontrollersのトピックRe: Difficulty with SPI interface - MC9S08SG32</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Difficulty-with-SPI-interface-MC9S08SG32/m-p/205954#M17309</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello bigmac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Firstly thank you for your prompt reply. I really appreciate it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"&amp;nbsp;Since you are not waiting&amp;nbsp;for the SPRF flag&amp;nbsp;to become set before raising the SS signal at PTCD2,&amp;nbsp;SPI&amp;nbsp;communications will be prematurely aborted at the slave.&amp;nbsp; After the flag becomes set, you will then need to clear the flag.&amp;nbsp; In the process of doing this, you may as well return the received byte value (via MISO), to provide a more general SPI function. "&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on your suggestion atated above, I modified the code as&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;void SPISendChar(unsigned char data)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (!SPIS_SPTEF &amp;amp;&amp;amp; PTCD_PTCD3);&amp;nbsp;&amp;nbsp;/* Wait until transmit buffer is empty */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PTCD_PTCD2 = 0;&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; /* Select slave */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;read = SPIS;&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;/* read SPIS whe SPTEF = 1 to initiate a transfer */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SPID = data; &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; /* Start to send data */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (!SPIS_SPRF)&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; /* wait till the byte is recieved */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; (void)(SPIS == 0);&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; // clear flag&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PTCD_PTCD2 = 1;&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; /* Un-select slave */&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;If I do this I think I am getting stuck in a infinite loop as the SPRF flag is reset on the instruction "While(!SPIS_SPF)" (Refer the attachment No:1).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I tried to add a delay after writing to the SPID so that the data transfer is not prematurely aboted. It goes like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;void SPISendChar(unsigned char data)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (!SPIS_SPTEF &amp;amp;&amp;amp; PTCD_PTCD3);&amp;nbsp;&amp;nbsp;/* Wait until transmit buffer is empty */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PTCD_PTCD2 = 0;&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; /* Select slave */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;read = SPIS;&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;/* read SPIS whe SPTEF = 1 to initiate a transfer */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SPID = data; &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; /* Start to send data */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (tmp=0;tmp&amp;lt;50;tmp++);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* wait till the byte is recieved */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; (void)(SPIS == 0);&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; // clear flag&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PTCD_PTCD2 = 1;&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; /* Un-select slave */&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I see that I am not stuck in a loop, but as usual there is no clock and no data on the MOSI pin (Refer the attachment No:2).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any more suggestions please..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Kvkk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 14 May 2011 14:46:54 GMT</pubDate>
    <dc:creator>kvkk</dc:creator>
    <dc:date>2011-05-14T14:46:54Z</dc:date>
    <item>
      <title>Difficulty with SPI interface - MC9S08SG32</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Difficulty-with-SPI-interface-MC9S08SG32/m-p/205952#M17307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to Freescale family. Currently I am &amp;nbsp;facing a problem with interfacing "Intersil HIP9011"(Knock Signal Processing chip) to MC9S08SG32 Microcontroller through SPI. I am using DEMO9S08SH32-SG32 demo board featuring MC9S08SG32 MCU&amp;nbsp;for the purpose. I had gone through a lot of posts&amp;nbsp;related to &amp;nbsp;SPI on this Forum but could not solve the issue. Finally ended up posting this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually the HIP9011 chip is configured to perform its function by programming 5 configuration bytes through SPI by a microcontroller.&amp;nbsp;In addition to the Chip/slave select&amp;nbsp;(CS/SS) signal, the chip requires&amp;nbsp;INT/HOLD signal also to be held low for programming (the datasheet is attached for reference). I am presently using MCU as the master and the chip as the slave.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is, inspite of pulling the CS and INT/HOLD signal low and loading the SPID register with the data byte, I see no pulses/data on SCK and MOSI lines on the scope indicating there is no clock and hence no data is being transferred.&amp;nbsp;Also the SPTEF flag always remains 1 inspite of loading the data and the SPRF flag goes high immediately indicating a&amp;nbsp;byte shifted from the chip.&amp;nbsp;I have confirmed all the hardware connections.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Request&amp;nbsp;you guys to help me in figuring out what the problem is..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code and the datasheet of the chip are attached for reference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 May 2011 13:41:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Difficulty-with-SPI-interface-MC9S08SG32/m-p/205952#M17307</guid>
      <dc:creator>kvkk</dc:creator>
      <dc:date>2011-05-13T13:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulty with SPI interface - MC9S08SG32</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Difficulty-with-SPI-interface-MC9S08SG32/m-p/205953#M17308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, and welcome to the forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Firstly, the timing diagram for the slave device suggests that a setting of CPOL = 0 and CPHA = 1 is the required setting, i.e. the input data is read on the negative clock edge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now consider&amp;nbsp;your following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;void SPISendChar(unsigned char data)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (!SPIS_SPTEF &amp;amp;&amp;amp; PTCD_PTCD3);&amp;nbsp;&amp;nbsp;/* Wait until transmit buffer is empty */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PTCD_PTCD2 = 0;&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; /* Select slave */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SPID = data; &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; /* Start to send data */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(void)(SPIS == 0);&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; // clear flag&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PTCD_PTCD2 = 1;&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; /* Un-select slave */&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;BR /&gt;.&lt;BR /&gt;This would differ from other recent SPI posts on this forum.&amp;nbsp; Since you are not waiting&amp;nbsp;for the SPRF flag&amp;nbsp;to become set before raising the SS signal at PTCD2,&amp;nbsp;SPI&amp;nbsp;communications will be prematurely aborted at the slave.&amp;nbsp; After the flag becomes set, you will then need to clear the flag.&amp;nbsp; In the process of doing this, you may as well return the received byte value (via MISO), to provide a more general SPI function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would not include the test for PTCD3 set within the function, because if set, you would potentially enter an indefinite loop (subject to COP timeout).&amp;nbsp; Far better to make sure that PTCD3 is clear before calling the function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The delay loop, after the sending of each byte, may then be eliminated.&amp;nbsp; However, after the final byte is sent, you will need a delay of at least 8 us before again raising PTCD3, the INT/HOLD signal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, I do not see the need for the curr_byte global variable.&amp;nbsp; For example, the following would be more efficient.&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;SPISendChar( 0x40); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Send Prescaler byte */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 May 2011 21:31:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Difficulty-with-SPI-interface-MC9S08SG32/m-p/205953#M17308</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-05-13T21:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulty with SPI interface - MC9S08SG32</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Difficulty-with-SPI-interface-MC9S08SG32/m-p/205954#M17309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello bigmac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Firstly thank you for your prompt reply. I really appreciate it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"&amp;nbsp;Since you are not waiting&amp;nbsp;for the SPRF flag&amp;nbsp;to become set before raising the SS signal at PTCD2,&amp;nbsp;SPI&amp;nbsp;communications will be prematurely aborted at the slave.&amp;nbsp; After the flag becomes set, you will then need to clear the flag.&amp;nbsp; In the process of doing this, you may as well return the received byte value (via MISO), to provide a more general SPI function. "&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on your suggestion atated above, I modified the code as&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;void SPISendChar(unsigned char data)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (!SPIS_SPTEF &amp;amp;&amp;amp; PTCD_PTCD3);&amp;nbsp;&amp;nbsp;/* Wait until transmit buffer is empty */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PTCD_PTCD2 = 0;&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; /* Select slave */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;read = SPIS;&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;/* read SPIS whe SPTEF = 1 to initiate a transfer */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SPID = data; &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; /* Start to send data */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (!SPIS_SPRF)&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; /* wait till the byte is recieved */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; (void)(SPIS == 0);&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; // clear flag&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PTCD_PTCD2 = 1;&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; /* Un-select slave */&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;If I do this I think I am getting stuck in a infinite loop as the SPRF flag is reset on the instruction "While(!SPIS_SPF)" (Refer the attachment No:1).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I tried to add a delay after writing to the SPID so that the data transfer is not prematurely aboted. It goes like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;void SPISendChar(unsigned char data)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (!SPIS_SPTEF &amp;amp;&amp;amp; PTCD_PTCD3);&amp;nbsp;&amp;nbsp;/* Wait until transmit buffer is empty */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PTCD_PTCD2 = 0;&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; /* Select slave */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;read = SPIS;&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;/* read SPIS whe SPTEF = 1 to initiate a transfer */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SPID = data; &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; /* Start to send data */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (tmp=0;tmp&amp;lt;50;tmp++);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* wait till the byte is recieved */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; (void)(SPIS == 0);&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; // clear flag&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PTCD_PTCD2 = 1;&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; /* Un-select slave */&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I see that I am not stuck in a loop, but as usual there is no clock and no data on the MOSI pin (Refer the attachment No:2).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any more suggestions please..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Kvkk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 May 2011 14:46:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Difficulty-with-SPI-interface-MC9S08SG32/m-p/205954#M17309</guid>
      <dc:creator>kvkk</dc:creator>
      <dc:date>2011-05-14T14:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulty with SPI interface - MC9S08SG32</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Difficulty-with-SPI-interface-MC9S08SG32/m-p/205955#M17310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Kvkk,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The probable reason you encounter an infinite loop is that you are attempting to single step through the SPISendChar() function, whilst monitoring the state of the SPIS and SPID registers.&amp;nbsp; The debug process will therefore clear the SPRF flag before the loop test can occur.&amp;nbsp; The solution is to use a break point, rather than attempting to single step the function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Even so, your code does not actually clear the SPRF flag - the datasheet should describe the mechanism required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My take on your code might be as follows:&lt;/P&gt;&lt;PRE&gt;#define LED_ON    PTCD_PTCD1 = 0#define LED_OFF   PTCD_PTCD1 = 1#define CS_ON     PTCD_PTCD2 = 0#define CS_OFF    PTCD_PTCD2 = 1#define HOLD_MODE PTCD_PTCD3 = 0#define INT_MODE  PTCD_PTCD3 = 1void main(void){   word tmp;   MCU_init();               /* Device Initialization */   CS_OFF;                   /* SS Initial State */   INT_MODE;                 /* Set INTG Mode */   LED_OFF;                  /* Turoff LED */             HOLD_MODE;                /* Set HOLD mode */   (void)SPISend( Ox40);     /* Send Prescaler byte */   // LED2();     (void)SPISend( 0xE0);     /* Send Channel Select byte */   // LED2();   (void)SPISend( 0x2F);     /* Send BPF Center freq byte */   // LED2();   (void)SPISend( 0x8E);     /* Send Gain Control byte */   // LED2();   (void)SPISend( 0xD4);     /* Send Integrator Tc byte */   // LED2();      for (tmp = 0; tmp &amp;lt; 20; tmp++); // Wait 8us minimum   INT_MODE;                       /* Set INTG Mode */   LED2();       for ( ; ; ) {      __RESET_WATCHDOG();       } /* loop forever */}byte SPISend( byte data) {   CS_ON;     // Select slave device   while (!SPIS_SPTEF);    // Wait until ready to send   SPID = data;            // Send byte value   while (!SPIS_SPRF);     // Wait until transfer is complete   data = SPID;            // Also clears flag   CS_OFF;                 // Un-select slave device   return data; }void LED2( void){   word tmp;   LED_ON;   for (tmp = 0; tmp &amp;lt; 3500; tmp++);    LED_OFF;   for (tmp = 0; tmp &amp;lt; 3500; tmp++);}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 May 2011 09:16:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Difficulty-with-SPI-interface-MC9S08SG32/m-p/205955#M17310</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-05-16T09:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulty with SPI interface - MC9S08SG32</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Difficulty-with-SPI-interface-MC9S08SG32/m-p/205956#M17311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello bigmac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Modification in the code suggested by you&amp;nbsp;works and the chip is on and running well. Sorry for the delay in replying back, I was busy on some other project and could not verify the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your kindest help and invaluable guidance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;KVKK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 May 2011 18:59:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Difficulty-with-SPI-interface-MC9S08SG32/m-p/205956#M17311</guid>
      <dc:creator>kvkk</dc:creator>
      <dc:date>2011-05-20T18:59:03Z</dc:date>
    </item>
  </channel>
</rss>

