<?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: [MC68HC908QB4] Continuing SPI Woes in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125549#M656</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Code posted as requested.&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 22 Aug 2006 20:19:27 GMT</pubDate>
    <dc:creator>admin</dc:creator>
    <dc:date>2006-08-22T20:19:27Z</dc:date>
    <item>
      <title>[MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125543#M650</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;I cotinue having difficulties implementing my SPI app on the -908QB4.&amp;nbsp; The data sheet (attached) mentions "double-buffering" transmit data for the SPI (in sec. 15.3.4 if anybody's interested).&amp;nbsp; This would be really cool if I could get it to work, as I have to complete at total of two 16-bit read cycles in under 333 us.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;What I observed was this:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I tried to use the nifty-keen double-buffering transmit by writing my first byte to the SPDR, then sitting in a loop waiting for the SPTE (transmit empty) flag to be set, then shoving my second byte into the SPDR.&amp;nbsp; Then I have the receive-full interrupt set up to begin my second read-cycle.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When stepping through the code, after I put the first byte into the SPDR, the SPRF flags sets immediatly, but no matter what the next line of code is, the SPRF clears without my Rx interrupt being serviced.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I pondered this for awhile before hitting on an idea - I don't really care with that first byte of data clocked in from my slave device is, because it's garbage to me, I just care what the second byte of Rx'd data is.&amp;nbsp; I restructured my Rx interrupt around this theory, and it works great, exept that the overflow (OVRF) flag is set, indicating a Rx overflow, and my second byte of data is lost - even though the Rx interrupt was never serviced to take care of the first byte!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Help me Freescale Forums, you're my only hope!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.freescale.com%2Ffiles%2Fmicrocontrollers%2Fdoc%2Fdata_sheet%2FMC68HC908QB8.pdf" rel="nofollow" target="_blank"&gt;MC68HC908QB8.pdf&lt;/A&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by t.dowe on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-09-22&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;11:56 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Aug 2006 21:14:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125543#M650</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-02T21:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125544#M651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;After your code adjustment you're having problems with the overflow bit being set, and you're not seeing the second byte. Section 15.3.6.1 talks about overflow. The SPI is capturing 8 bits and then it waits for you to get them. If another 8 bits are read on the SPI before you read the first, those bits are lost, and the MCU sets the overflow flag to let you know that you don't have all of the information that was sent. To fix this, just read the contents of the SPI Data Register after the first byte is recieved, and write them to a temporary register - I'd just write them to the value that you'll be storing the second byte in as soon as you recieve it. This way, the recieve register will be cleared (along with the flag indicating that the receive register is full, SPRF), and the second byte will (should) be properly captured for access.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Aug 2006 22:55:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125544#M651</guid>
      <dc:creator>RedMountain</dc:creator>
      <dc:date>2006-08-02T22:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125545#M652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;But the point is that I'm not getting an SPI receive-full interrupt from the first byte!&amp;nbsp; So, I can't get rid of a potential overwrite because I have no signal as to when I receive the first byte.&amp;nbsp; Like I said before, when I write to the SPDA buffer to send a byte, something keeps whacking the SPRF flag so I never get the interrupt.&lt;/P&gt;&lt;P&gt;-Tomahawk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Aug 2006 00:08:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125545#M652</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-03T00:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125546#M653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, Tomahawk:&lt;BR /&gt;&lt;BR /&gt;I think the problem may be related to the fact that you are single stepping through the code.&lt;BLOCKQUOTE&gt;&lt;HR /&gt;When stepping through the code, after I put the first byte into the SPDR, the SPRF flags sets immediatly . . .&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;I would bet that it doesn't set imediatly, but that it is setting after the first transfer takes place. It appears imediate because you are stepping.&lt;BLOCKQUOTE&gt;&lt;HR /&gt;. . . but no matter what the next line of code is, the SPRF clears without my Rx interrupt being serviced.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;I suspect that, because you are stepping, the debugger is reading the registers in order to display them, and that is clearing the receive flag.&lt;BR /&gt;&lt;BR /&gt;What I would do is this:&lt;BR /&gt;&lt;BR /&gt;Load the first byte into the SPDR.&lt;BR /&gt;Wait for SPTE, and then load the second byte into the SPDR.&lt;BR /&gt;Now wait for the SPRF bit to set from the first byte, and read SPDR to fetch the data.&lt;BR /&gt;Wait for the SPRF bit to set from the second byte, and read SPDR to get that data.&lt;BR /&gt;&lt;BR /&gt;But if you try to step through this routine, you will get an overflow. You cannot breakpoint between the time that you load the second transmitted byte into the SPDR until after you have read the first received byte from the SPDR.&lt;BR /&gt;&lt;BR /&gt;hope that helps.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Aug 2006 04:24:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125546#M653</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-08-03T04:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125547#M654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I finally got back to my problem.&amp;nbsp; I had the code set a port pin when it thinks it receives the first byte, then clear it when it receives the second byte.&amp;nbsp; I ran the code (without stepping), and I never set the port pin.&amp;nbsp; This tells me that I'm not getting the first receive interrupt.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Has anyone used the "double-buffered" sheme successfully?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;Tomahawk&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Aug 2006 03:28:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125547#M654</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-22T03:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125548#M655</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, Tomahawk:&lt;BR /&gt;&lt;BR /&gt;Assuming that you are setting and clearing your 'debug' pin within the ISR, it doesn't quite mean that the interrupt isn't occurring, it means that the interrupt isn't getting into the ISR.&lt;BR /&gt;&lt;BR /&gt;I use a very similar double buffered approach to interface the SPI to a digi-pot (sixteen bit). I have also used the SPI for inter-HC08 communications, for communicating with FPGAs, interfacing with LCDs and driving long chains of shift-registers. So I can attest that it works exactly as the manual states (if the manual is correct &lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt; ).&lt;BR /&gt;&lt;BR /&gt;Can you post the code and have us look at it?&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Aug 2006 07:22:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125548#M655</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-08-22T07:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125549#M656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Code posted as requested.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Aug 2006 20:19:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125549#M656</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-22T20:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125550#M657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, Tomahawk:&lt;BR /&gt;&lt;BR /&gt;I have scanned everything, and have to say it is very easy to read. I have only looked at the below routine closely, and I have commented it. It may have the answer, but I'm not sure. I will look at the ISR next.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 04:07:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125550#M657</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-08-23T04:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125551#M658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Tomahawk,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;It is not clear what baud rate divisor you are using, but I suspect you&amp;nbsp;would be using either 2 or 8.&amp;nbsp; If this is so, I think that it is inappropriate to be using the SPI interrupt.&amp;nbsp; Here is the reason -&lt;/FONT&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT size="2"&gt;Assuming a divisor value of 2, each SPI&amp;nbsp;transaction will take 16 bus cycles for the sending and receiving of one byte.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;The interrupt handler would have a minimum overhead of 20 bus cycles&lt;/FONT&gt;&amp;nbsp;&lt;FONT size="2"&gt;in assembler, and may be more in C.&amp;nbsp; This is the&amp;nbsp;cycles required by&amp;nbsp;the ISR in addition to the actual processing cycles.&amp;nbsp; By default, nested interrupts do not occur, and should&amp;nbsp;be avoided if possible.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;Your ISR seems rather complex, and will probably require many cycles to complete, maybe the period of several SPI transactions.&amp;nbsp; I note that you have included &lt;FONT face="Courier New"&gt;while&lt;/FONT&gt; loops within the ISR, probably not a good idea.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;FONT size="2"&gt;In this case, there would be insufficient time to process several bytes, so later received data would be missed, particularly with two bytes in the SPI send buffer.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;The solutions -&lt;/FONT&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT size="2"&gt;Don't use the double buffering capability so that delays within the ISR are less critical - it does not save any bus cycles anyway, or&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;Reduce the baud rate to delay the completion of the second byte until after the ISR has completed, or&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;Don't use interrupts for the SPI (and only send one byte at a time in case there is a timer, or other interrupt that commences just prior to the&amp;nbsp;SPI receive flag beihg set).&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;FONT size="2"&gt;I would probably opt to not use interrupts - it would ultimately be quicker and simpler.&amp;nbsp; For master operation, the SPI interurrupt is really only useful for slow baud rates where other useful processing can occur during the SPI transaction.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;You can easily test whether this is the cause of your problem by reducing the baud rate, and seeing if data is still missed.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2006-08-23&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;10:05 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 18:57:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125551#M658</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-08-23T18:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125552#M659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;rocco wrote:&lt;BR /&gt;Hi, Tomahawk:&lt;BR /&gt;&lt;BR /&gt;I have scanned everything, and have to say it is very easy to read. I have only looked at the below routine closely, and I have commented it. It may have the answer, but I'm not sure. I will look at the ISR next.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;rocco,&lt;/P&gt;&lt;P&gt;Thanks for looking at that routine, but the I don't really care about the about the init routine, it's the regular read routines where I want to make use of the double-buffering.&lt;/P&gt;&lt;P&gt;-Tomahawk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 19:58:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125552#M659</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-23T19:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125553#M660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;bigmac wrote:&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Tomahawk,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;It is not clear what baud rate divisor you are using, but I suspect you&amp;nbsp;would be using either 2 or 8.&amp;nbsp; If this is so, I think that it is inappropriate to be using the SPI interrupt.&amp;nbsp; Here is the reason -&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;[snip]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I would probably opt to not use interrupts - it would ultimately be quicker and simpler.&amp;nbsp; For master operation, the SPI interurrupt is really only useful for slow baud rates where other useful processing can occur during the SPI transaction.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;You can easily test whether this is the cause of your problem by reducing the baud rate, and seeing if data is still missed.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2006-08-23&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;10:05 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Mac,&lt;/P&gt;&lt;P&gt;I am using a baud rate divisor of 2.&amp;nbsp; I will try out a couple of things you suggest.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Tomahawk&lt;BR /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 20:02:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125553#M660</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-23T20:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125554#M661</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;rocco wrote:&lt;BR /&gt;&lt;BR /&gt;I have scanned everything, and have to say it is very easy to read. &lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;BTW, rocco, thanks for the compliment.&amp;nbsp; I try.&amp;nbsp; &lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;P&gt;In other news, my timing requirments have changed slightly, so I can probably do away with using interrupts.&amp;nbsp; So, even with my baud rate divisor of 2, can I use the double-buffered scheme, or should I just avoid it?&lt;/P&gt;&lt;P&gt;Thanks again,&lt;BR /&gt;Tomahawk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 22:40:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125554#M661</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-23T22:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125555#M662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Tomahawk,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;The double buffering could probably be utilised provided you disable interrupts for the duration of the SPI transaction.&amp;nbsp; However, as I have previously said, the total number of cycles would not be significantly reduced because you still need to receive the two bytes before the read process is complete.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2006-08-24&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:36 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 23:33:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125555#M662</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-08-23T23:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125556#M663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;bigmac wrote:&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Tomahawk,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;The double buffering could probably be utilised provided you disable interrupts for the duration of the SPI transaction.&amp;nbsp; However, as I have previously said, the total number of cycles would not be significantly reduced because you still need to receive the two bytes before the read process is complete.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2006-08-24&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:36 AM&lt;/SPAN&gt;&lt;BR /&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;Mac,&lt;/P&gt;&lt;P&gt;I have no problem completely disabling SPI interrupts and doing everything from main code.&amp;nbsp; The slave part I'm communicating with requires 16 bit (two byte) transactions anyway, so I believe I will get some benefit out of using the double-buffered scheme.&amp;nbsp; The problem is how to do it in C.&amp;nbsp; Any suggestions/code snippets/etc.?&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Tomahawk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Aug 2006 00:09:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125556#M663</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-24T00:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125557#M664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, Tomahawk:&lt;BR /&gt;&lt;BR /&gt;I totally agree with Mac that you don't need interrupts, and that you could probably get it done faster with in-line code, and a clock-divider of 2 (assuming the C code is fast enough).&lt;BR /&gt;&lt;BR /&gt;To do this double buffered, you just need to think of the transmitter as being two bytes ahead of the receiver. Here is an outline:&lt;BR /&gt;&lt;BR /&gt;1) Write a byte to the transmitter.&lt;BR /&gt;2) Wait for transmitter-empty.&lt;BR /&gt;---&lt;BR /&gt;3) Write a another byte to the transmitter.&lt;BR /&gt;4) Wait for receiver-full.&lt;BR /&gt;5) Read the byte from the receiver.&lt;BR /&gt;6) Loop back to step-3.&lt;BR /&gt;&lt;BR /&gt;Note that you only need to check for transmitter-empty when you start double buffering.&lt;BR /&gt;&lt;BR /&gt;The transmitter will be an extra byte ahead, so you will need to skip step-3, and go to step-4 instead, after you receive your second-to-last byte. In other words, you will get TWO received bytes after you write your last transmitter byte.&lt;BR /&gt;&lt;BR /&gt;Hope that helps.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Aug 2006 03:50:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125557#M664</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-08-24T03:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125558#M665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;rocco wrote:&lt;BR /&gt;Hi, Tomahawk:&lt;BR /&gt;&lt;BR /&gt;I totally agree with Mac that you don't need interrupts, and that you could probably get it done faster with in-line code, and a clock-divider of 2 (assuming the C code is fast enough).&lt;BR /&gt;&lt;BR /&gt;To do this double buffered, you just need to think of the transmitter as being two bytes ahead of the receiver. Here is an outline:&lt;BR /&gt;&lt;BR /&gt;1) Write a byte to the transmitter.&lt;BR /&gt;2) Wait for transmitter-empty.&lt;BR /&gt;---&lt;BR /&gt;3) Write a another byte to the transmitter.&lt;BR /&gt;4) Wait for receiver-full.&lt;BR /&gt;5) Read the byte from the receiver.&lt;BR /&gt;6) Loop back to step-3.&lt;BR /&gt;&lt;BR /&gt;Note that you only need to check for transmitter-empty when you start double buffering.&lt;BR /&gt;&lt;BR /&gt;The transmitter will be an extra byte ahead, so you will need to skip step-3, and go to step-4 instead, after you receive your second-to-last byte. In other words, you will get TWO received bytes after you write your last transmitter byte.&lt;BR /&gt;&lt;BR /&gt;Hope that helps.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So, for a two-byte transaction I should:&lt;/P&gt;&lt;P&gt;1) Write a byte to the transmitter.&lt;BR /&gt;2) Wait for transmitter-empty.&lt;BR /&gt;---&lt;BR /&gt;3) Write a another byte to the transmitter.&lt;BR /&gt;4) Wait for receiver-full.&lt;BR /&gt;5) Read the byte from the receiver.&lt;BR /&gt;6) Wait for receiver-full again&lt;BR /&gt;7) Read the byte from the receiver again.&lt;BR /&gt;&lt;BR /&gt;Right?&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Tomahawk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Aug 2006 04:31:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125558#M665</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-08-24T04:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125559#M666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;You got it !&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Aug 2006 04:35:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125559#M666</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-08-24T04:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125560#M667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, Tomahawk. I just thought I should add this warning:&lt;BR /&gt;&lt;BR /&gt;Because of the buffering, even though you read those two bytes from the SPI &lt;B&gt;after&lt;/B&gt; having sent two bytes, they were both sent by your external device &lt;B&gt;before&lt;/B&gt; having received both of those bytes from you.&lt;BR /&gt;&lt;BR /&gt;So if the two bytes you sent were a request for data from the external device, you would need to send further bytes in order to receive the requested data.&lt;BR /&gt;&lt;BR /&gt;I hope that made sense . . .&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Aug 2006 07:31:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125560#M667</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-08-24T07:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125561#M668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello Tomahawk,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I think I should clarify my .last post -&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt; &lt;HR /&gt;&lt;FONT size="2"&gt;bigmac wrote:&lt;BR /&gt;&lt;/FONT&gt; &lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;The double buffering could probably be utilised provided you disable interrupts for the duration of the SPI transaction.&amp;nbsp; However, as I have previously said, the total number of cycles would not be significantly reduced because you still need to receive the two bytes before the read process is complete.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT size="2"&gt;I meant that all interrupts would need to be disabled using the in-line assembly instruction &lt;FONT face="Courier New"&gt;sei&lt;/FONT&gt;&amp;nbsp;, and then re-enabled using &lt;FONT face="Courier New"&gt;cli&lt;/FONT&gt; instruction when the transactions are complete.&amp;nbsp; I had actually assumed that you would &lt;U&gt;not&amp;nbsp;&lt;/U&gt; be using an ISR for the SPI.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;The reason is that, once the second character is loaded to the send buffer you have no control over when the second transaction occurs, and you have a 16 cycle window to read the first byte from the receive buffer, before the second byte is received.&amp;nbsp; So you cannot afford for &lt;U&gt;any&lt;/U&gt; interrupt to delay reading the first byte.&amp;nbsp; This critical timing occurs because there is double buffering for send, but not for receive.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;If you send only a single byte at a time (you wait until the first byte is read before commencing the second byte) the timing becomes non-critical, so you would not need to disable interrupts.&amp;nbsp; The timing penalty would only be the few cycles necessary to write the second byte to the send buffer.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;If your&amp;nbsp;data acquisition&amp;nbsp;requirements are time critical to this extent, there may be more advantage to use in-line assembly for all SPI operations, rather than to utilise the double buffered send.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;BR /&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Aug 2006 10:09:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125561#M668</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-08-24T10:09:09Z</dc:date>
    </item>
    <item>
      <title>Re: [MC68HC908QB4] Continuing SPI Woes</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125562#M669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Mac is right, if ANY interrupt occurs during the double-buffered transfer, the second byte will be lost. But both solutions that Mac pointed out will work.&lt;BR /&gt;&lt;BR /&gt;The real advantage of the double-buffered SPI is that it allows for contiguous transfers, meaning the SCLK line has a constant frequency over any number of bytes. A nice clean clock for devices that require it. Though it also improves throughput, the improvement is not necessarily significant.&lt;BR /&gt;&lt;BR /&gt;If the speed of communication with the external device is paramount, or if no other interrupts are enabled, then I would leave it double-buffered. But I would also bracket the routine with an SEI and CLI, as Mac said, to prevent any interruptions.&lt;BR /&gt;&lt;BR /&gt;If a few lost cycles between bytes won't hurt, then the single-buffer approach would be much safer. An interrupt during the transfer would cause the delay between bytes to be extended, but it won't cause you to loose any data.&lt;BR /&gt;&lt;BR /&gt;Here is the sequence for a single-buffer approach. Notice that it is also a little simpler:&lt;BR /&gt;&lt;BR /&gt;1) Write a byte to the transmitter.&lt;BR /&gt;2) Wait for receiver-full.&lt;BR /&gt;3) Read the byte from the receiver.&lt;BR /&gt;4) Loop back to step-1.&lt;BR /&gt;&lt;BR /&gt;Or for a two-byte transaction:&lt;BR /&gt;&lt;BR /&gt;1) Write a byte to the transmitter.&lt;BR /&gt;2) Wait for receiver-full.&lt;BR /&gt;3) Read the byte from the receiver.&lt;BR /&gt;4) Write a another byte to the transmitter.&lt;BR /&gt;5) Wait for receiver-full again.&lt;BR /&gt;6) Read the byte from the receiver again.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Aug 2006 13:44:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC68HC908QB4-Continuing-SPI-Woes/m-p/125562#M669</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-08-24T13:44:43Z</dc:date>
    </item>
  </channel>
</rss>

