<?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: Calling SPI_MasterTransferNonBlocking(): FIFOINTENSET slow? in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Calling-SPI-MasterTransferNonBlocking-FIFOINTENSET-slow/m-p/1763667#M54792</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Regarding the SPI FIFO interrupt enable register&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-c"&gt;&lt;CODE&gt;base-&amp;gt;FIFOINTENSET&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I suppose that the register is FIFO Interrupt Enable Register instead of FIFO Interrupt Enable Register set register, because the setting the FIFOINTENCLR reg can clear the corresponding bit in FIFOINTENSET reg.&lt;/P&gt;
&lt;P&gt;So the driver code is correct, you have to use &lt;FONT face="courier new,courier"&gt;|=&lt;/FONT&gt; operator.&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xiangjun_rong_0-1701052914299.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/251510i88BE0CEE6B1AC4BE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="xiangjun_rong_0-1701052914299.png" alt="xiangjun_rong_0-1701052914299.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Nov 2023 02:44:40 GMT</pubDate>
    <dc:creator>xiangjun_rong</dc:creator>
    <dc:date>2023-11-27T02:44:40Z</dc:date>
    <item>
      <title>Calling SPI_MasterTransferNonBlocking(): FIFOINTENSET slow?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Calling-SPI-MasterTransferNonBlocking-FIFOINTENSET-slow/m-p/1763435#M54789</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm using a LPC5536 which I connected to an external part via SPI.&lt;/P&gt;&lt;P&gt;The SPI clock is 5 MHz and on the scope I can see that an SPI transfer of 16 bit takes less than &lt;STRONG&gt;4 microseconds&lt;/STRONG&gt;&amp;nbsp;with this clock (i.e., scope is on chip select signal). However, doing consecutive SPI transfers, I see on the scope that they are at least &lt;STRONG&gt;50 microseconds&lt;/STRONG&gt; apart. I wondered where that latency comes from and therefore profiled the SDK driver code.&lt;/P&gt;&lt;P&gt;To initiate the transfer, at some point the code calls&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;SPI_MasterTransferNonBlocking()&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;in &lt;EM&gt;drivers/fsl_spi.c&lt;/EM&gt;, see&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;A href="https://github.com/nxp-mcuxpresso/mcux-sdk/blob/main/drivers/flexcomm/spi/fsl_spi.c#L699" target="_self"&gt;https://github.com/nxp-mcuxpresso/mcux-sdk/blob/main/drivers/flexcomm/spi/fsl_spi.c#L699&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The last statement in this function is&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    base-&amp;gt;FIFOINTENSET |= SPI_FIFOINTENSET_TXLVL_MASK | SPI_FIFOINTENSET_RXLVL_MASK;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;DWT-&amp;gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;CYCCNT&lt;/FONT&gt;&amp;nbsp;&lt;/SPAN&gt;cycle counter, I measured that this statement takes &lt;STRONG&gt;35 microseconds&lt;/STRONG&gt; for execution.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Why is this?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The driver sets and resets the FIFO interrupt flags before and after every SPI transfer. This delay adds up causing a substantial latency.&lt;/P&gt;&lt;P&gt;Further, can I replace the &lt;FONT face="courier new,courier"&gt;|=&lt;/FONT&gt; operator with just &lt;FONT face="courier new,courier"&gt;=&lt;/FONT&gt; as follows?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    base-&amp;gt;FIFOINTENSET = SPI_FIFOINTENSET_TXLVL_MASK | SPI_FIFOINTENSET_RXLVL_MASK;&lt;/LI-CODE&gt;&lt;P&gt;That would save a couple of microseconds. It is my understanding that the&amp;nbsp; "SET" registers are special registers where every "1" bit written to the&amp;nbsp; "SET" register will be set in the underlying register. Writing a "0" bit will not change or clear the bit in the underlying register. So to set a certain bit a simple assignment is sufficient and a read is not required.&lt;/P&gt;&lt;P&gt;So why does the driver use "&lt;FONT face="courier new,courier"&gt;|=&lt;/FONT&gt;" with these special registers?&lt;/P&gt;&lt;P&gt;Thanks.&lt;BR /&gt;Dan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2023 15:24:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Calling-SPI-MasterTransferNonBlocking-FIFOINTENSET-slow/m-p/1763435#M54789</guid>
      <dc:creator>danielholala</dc:creator>
      <dc:date>2023-11-24T15:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calling SPI_MasterTransferNonBlocking(): FIFOINTENSET slow?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Calling-SPI-MasterTransferNonBlocking-FIFOINTENSET-slow/m-p/1763667#M54792</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Regarding the SPI FIFO interrupt enable register&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-c"&gt;&lt;CODE&gt;base-&amp;gt;FIFOINTENSET&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I suppose that the register is FIFO Interrupt Enable Register instead of FIFO Interrupt Enable Register set register, because the setting the FIFOINTENCLR reg can clear the corresponding bit in FIFOINTENSET reg.&lt;/P&gt;
&lt;P&gt;So the driver code is correct, you have to use &lt;FONT face="courier new,courier"&gt;|=&lt;/FONT&gt; operator.&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xiangjun_rong_0-1701052914299.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/251510i88BE0CEE6B1AC4BE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="xiangjun_rong_0-1701052914299.png" alt="xiangjun_rong_0-1701052914299.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 02:44:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Calling-SPI-MasterTransferNonBlocking-FIFOINTENSET-slow/m-p/1763667#M54792</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2023-11-27T02:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calling SPI_MasterTransferNonBlocking(): FIFOINTENSET slow?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Calling-SPI-MasterTransferNonBlocking-FIFOINTENSET-slow/m-p/1763962#M54796</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/26034"&gt;@xiangjun_rong&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thank you for your response.&lt;/P&gt;&lt;P&gt;Regarding the disputed &lt;STRONG&gt;use of the '|=' operator&lt;/STRONG&gt;, I understand that you claim that the&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;base-&amp;gt;FIFOINTENSET&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;register also allows to clear bits and thus disable interrupt sources.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The reference manual's description of &lt;STRONG&gt;FIFOINTENSET&lt;/STRONG&gt; reads:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielholala_0-1701073427868.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/251561i05E45F5E53E95DE9/image-size/large?v=v2&amp;amp;px=999" role="button" title="danielholala_0-1701073427868.png" alt="danielholala_0-1701073427868.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It does not explicitly state how the CPU handles writing '0' bits to&amp;nbsp;&lt;SPAN&gt;FIFOINTENSET. It does insinuate that to clear bits the user should use FIFOINTENCLR, though.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Then there's the explanation of each bit in the register, e.g., RXLVL and TXLVL:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielholala_1-1701074138570.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/251567i4D46D327F522C620/image-size/large?v=v2&amp;amp;px=999" role="button" title="danielholala_1-1701074138570.png" alt="danielholala_1-1701074138570.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The reference manual does not distinguish between reading and writing to this register. The explanation for a "0" bit could apply to reading from the register, only. This is ambiguous.&lt;/P&gt;&lt;P&gt;Thus I tried it by example: I set some bits and then cleared all bits with setting FIFOINTENSET to 0 as follows&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    base-&amp;gt;FIFOINTENSET |= SPI_FIFOINTENSET_TXLVL_MASK | SPI_FIFOINTENSET_RXLVL_MASK;
    base-&amp;gt;FIFOINTENSET = 0;
    RTT_WriteStringf("03 clear %08x\n", base-&amp;gt;FIFOINTENSET );&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The output is "&lt;FONT face="courier new,courier"&gt;03 clear 0000000c&lt;/FONT&gt;". Also "peripherals+" view in MCUXpresso IDE shows the&amp;nbsp; value&amp;nbsp; &lt;FONT face="courier new,courier"&gt;0x0000000c&amp;nbsp;&lt;/FONT&gt;(when stepping through these instructions using the debugger).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;From this observation I conclude that writing 0 bits to FIFOINTENSET does NOT clear bits.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Please comment.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Daniel&lt;/P&gt;&lt;P&gt;PS: Regarding "FIFOINTENSET slow?", I now know why writing to FIFOINTENSET is supposedly slow. The transfer is started by the empty TXFIFO interrupt and this interrupt is fired as soon as the&amp;nbsp;FIFOINTENSET is written to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 11:32:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Calling-SPI-MasterTransferNonBlocking-FIFOINTENSET-slow/m-p/1763962#M54796</guid>
      <dc:creator>danielholala</dc:creator>
      <dc:date>2023-11-27T11:32:54Z</dc:date>
    </item>
  </channel>
</rss>

