<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59635/spi-handler-getting-triggered-when-spi-is-not-running</link><description>Hi, 
 I&amp;#39;ve built a project out of the USBD_ACM_CDC example in which I have added a SPI master driver. This project has a timer interrupt that will shoot off every ~500us and trigger a 520 bit SPI transfer. The received packets undergo *very* minor processing</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 01 Apr 2020 18:15:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59635/spi-handler-getting-triggered-when-spi-is-not-running" /><item><title>RE: SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/thread/243041?ContentTypeID=1</link><pubDate>Wed, 01 Apr 2020 18:15:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f243362-6b19-46e7-9a49-5df9ce8226bb</guid><dc:creator>ryerye120</dc:creator><description>&lt;p&gt;Sorry, I should have mentioned that! I have indeed disconnected the FPGA and am just working with two NRF52 dev kits. One is operating&amp;nbsp;as a slave and is logging data over UART. The other dev kit has a SPI_master + USB driver running on it.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll tie the MISO line to GND as a sanity check.&lt;/p&gt;
&lt;p&gt;Could it be that that leaving logging enabled on the SPI is slowing down the slave&amp;#39;s response? The SPI should be controlled via hardware so maybe that doesn&amp;#39;t make sense.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit: It was indeed&amp;nbsp;related to logging. Setting the slave&amp;#39;s NRF_LOG_ENABLED to 0 fixed everything!&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/thread/242822?ContentTypeID=1</link><pubDate>Wed, 01 Apr 2020 04:04:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6947d5f1-0d96-4070-862a-d5bb39f00b05</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;First step is always disconnect MISO pin from the FPGA (without touching or changing anything else); connect MISO to nRF52 to Gnd and every returned packet should be all 0x00, connect &lt;span&gt;MISO to nRF52&amp;nbsp;&lt;/span&gt;to Vcc and every returned packet should be 0xFF. If so, then the issue is with the FPGA not the nRF52, I would&amp;nbsp;propose ..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/thread/242800?ContentTypeID=1</link><pubDate>Tue, 31 Mar 2020 22:21:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:999d17a0-3706-4fd2-8bcf-6faafe3d6ffd</guid><dc:creator>ryerye120</dc:creator><description>&lt;p&gt;So I fixed an issue with the USB but I&amp;#39;m not able to read out&amp;nbsp;all the SPI packets on the master end still. I can confirm now that this is a SPI issue because I put a watch on my spi rx buffer in the debug and most of the packets being read out are FFFFFFF. It also seems that I am indeed missing packets as well.&lt;/p&gt;
&lt;p&gt;Everything SPI related works at slow speeds still so it&amp;#39;s not like the whole thing is messed up. It&amp;#39;s purely when I try pushing the SPI to faster speeds. I&amp;#39;m still using an 8MHz clock and the pins are configured in high drive mode:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    nrf_gpio_cfg(SPI_SS_PIN,   NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
    nrf_gpio_cfg(SPI_MOSI_PIN, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
    nrf_gpio_cfg(SPI_SCK_PIN,  NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
    nrf_gpio_cfg(SPI_MISO_PIN, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_CONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
    &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Are there any hints as to where I can look?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/thread/242771?ContentTypeID=1</link><pubDate>Tue, 31 Mar 2020 16:37:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d941bfb-aca8-4f35-b8fc-1dd586b3dabf</guid><dc:creator>ryerye120</dc:creator><description>&lt;p&gt;I&amp;#39;m currently handing the driver a 64 byte array, but if might be doing some char shenanigans.&amp;nbsp;That&amp;#39;s a good point.&amp;nbsp;I&amp;#39;ll take a look at that.&lt;/p&gt;
&lt;p&gt;Haha! That&amp;#39;s the end goal! If you have&amp;nbsp;code for a SPI/BLE that can stream 1 Mbps that you&amp;#39;d be willing to share I certainly wouldn&amp;#39;t complain!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/thread/242561?ContentTypeID=1</link><pubDate>Tue, 31 Mar 2020 00:09:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb597b8f-0514-4f4d-b3c1-67292be50e2b</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Not sure, from using the USB interface for serial transmission I saw that although USB, BLE and nRF52 peripheral DMA transfers are all packet-based, most of the Nordic library drivers appear to be character based. So that can mean that the 64-byte USB packet actually gets sent as 1-byte USB transfers when the data is dribbled through the driver 1 byte at a time. When that happens, throughput is severely limited. I don&amp;#39;t know if that is an issue for you or not, but we had some problems with throughput albeit in the other direction. The host receiving end may also affect the transfer of course, although correctly buffering data for the drivers shouldn&amp;#39;t actually corrupt data.&lt;/p&gt;
&lt;p&gt;Need a USB expert here .. meanwhile just use SPI to BLE :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/thread/242552?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 20:16:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5240eab-8fe0-40de-84dc-f77497162bc9</guid><dc:creator>ryerye120</dc:creator><description>&lt;p&gt;Amazing! I&amp;#39;ll try this out right now. Thank you.&lt;/p&gt;
&lt;p&gt;Edit: So I bumped up the SPI_CLK to 8MHz and confirmed that via an oscope &amp;amp; single SPI transactions. Unfortunately, when I try&amp;nbsp;sending SPI transactions every 500 ms, I get the same issue as before.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That being said! I started printing what is received by the slave and am seeing no issues (through UART logging). On the master side, I&amp;#39;m outputting everything via USB to&amp;nbsp;COM port on my PC. Is it possible that the data is getting corrupted&amp;nbsp;through the USB transmission? Are there any considerations for frequently triggering USB transfers. The USB should be able to hit 1 Mb/s easily in theory, but I&amp;#39;m just using the example code. Are there any configs I should change?&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/thread/242542?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 18:46:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ad476cd-8e5a-44de-b425-fef4cc81d38e</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;They are not driver options, just commands to override the default settings of Standard Drive output port pins for &amp;#39;0&amp;#39; (low-level) and &amp;#39;1&amp;#39; (high-level):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Set to High-Drive on the SPI output pins (assuming nRF52832 is the Master)
 nrf_gpio_cfg(SPI0_CS_PIN,   NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
 nrf_gpio_cfg(SPI0_MOSI_PIN, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
 nrf_gpio_cfg(SPI0_SCK_PIN,  NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This must be done after the SPI init, just once. Edit: Yes, you can modify the driver code as you suggest, less safe as that is hidden; even less safe as the other bits in the snippet you post are now not handled correctly; CNF has many bit fields.&lt;/p&gt;
&lt;p&gt;Here is an example showing all the CNF fields for a typical SPI0 (sorry, source code not available):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// P0.19  SPI0-SCK CNF: 0x00000303 [Sense: Off] [Drive: High 0&amp;amp;1] [Pull: None] [Input: Disconnect] [Dir: Output] (now 0) (SPI0 SCK)
// P0.20 SPI0-MOSI CNF: 0x00000303 [Sense: Off] [Drive: High 0&amp;amp;1] [Pull: None] [Input: Disconnect] [Dir: Output] (now 1) (SPI0 MOSI)
// P0.22 SPI0-nCS0 CNF: 0x00000303 [Sense: Off] [Drive: High 0&amp;amp;1] [Pull: None] [Input: Disconnect] [Dir: Output] (now 1) (SPI0 CSN)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/thread/242541?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 18:31:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44aefaa0-fcab-4ec1-9ac4-f6962e4df4d7</guid><dc:creator>ryerye120</dc:creator><description>&lt;p&gt;&lt;span&gt;Where can I look for these drive options? Are they all in nrf_drv_spi.h or in some gpio file?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Update: I&amp;nbsp;see that I can use&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_GPIO-&amp;gt;PIN_CNF[pin_number] = (GPIO_PIN_CNF_DRIVE_H0H1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;so if I&amp;#39;m using p0.29 (29) for MOSI, I could just&amp;nbsp;use:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_GPIO-&amp;gt;PIN_CNF[29] = (GPIO_PIN_CNF_DRIVE_H0H1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos);&lt;/pre&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I don&amp;#39;t know what CNF stands for. I will continue to google! This seems like a long shot, but I&amp;#39;ll take anything. Seriously, thank you. I&amp;#39;m a little new to this so I appreciate the help.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/thread/242529?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 17:43:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1dc46146-a1d9-46d2-9c26-8968fadfd2dd</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;If using the library code it won&amp;#39;t help adding the lines I don&amp;#39;t think, but no harm in trying; regarding the SPI throughput provided a transfer has completed before starting the next transfer there is no limitation other than the slightly verbose library code which traverses multiple functions. I would advise using the maximum clock rate the SPI device you are connecting to can support, at least 8MHz. At the higher clock speeds you have to increase the SCK, MOSI and CS drive levels to H0H1&amp;nbsp;&lt;em&gt;after&lt;/em&gt; setting the SPI init.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/thread/242526?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 17:20:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f60f8454-65db-49e1-947c-a4d00253213b</guid><dc:creator>ryerye120</dc:creator><description>&lt;p&gt;Firstly, thank you!!&lt;/p&gt;
&lt;p&gt;This is&amp;nbsp;very interesting. I&amp;#39;m currently using the Nordic provided spi&amp;nbsp;library but I&amp;#39;ll try adding the following lines to my spi handler to see if it helps:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;  SPI-&amp;gt;EVENTS_END = 0;
  mSpiPacketTransferComplete = true;
  mSpiInterruptCounter++;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Are there any special considerations for&amp;nbsp;how frequently I can use the SPI? I&amp;#39;m currently just using SPI0 (with easyDMA enabled), which from my understanding should be able to run fast enough, but maybe I misunderstood the sdk.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI handler getting triggered when spi is not running?</title><link>https://devzone.nordicsemi.com/thread/242257?ContentTypeID=1</link><pubDate>Sun, 29 Mar 2020 20:47:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d768e91-377a-413d-8375-4523bc51255f</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;If you are using Nordic library drivers the following should not apply as the issue is (should be) handled in the drivers; if using low-level driver note the following where a handler will be invoked twice instead of once. How do I know this? Because the counter is incremented twice instead of once for every SPI transaction if the workaround is not applied.&lt;/p&gt;
&lt;p&gt;Option 1:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Example using SPI0
static volatile uint32_t mSpiInterruptCounter = 0UL;
static NRF_SPIM_Type* pSPIM = NRF_SPIM0;
static const IRQn_Type mSPIM_IRQn = SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn;
/**
 * @brief SPI interrupt handler.
 * @param event
 */
void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void)
{
  blahblah(); // Processing (if any)
  // Clearing -&amp;gt;EVENTS_END MUST be first or add void read else get double interrupt ..
  pSPIM-&amp;gt;EVENTS_END = 0;
  mSpiPacketTransferComplete = true;
  mSpiInterruptCounter++;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Option 2:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Example using SPI0
static volatile uint32_t mSpiInterruptCounter = 0UL;
static NRF_SPIM_Type* pSPIM = NRF_SPIM0;
static const IRQn_Type mSPIM_IRQn = SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn;
/**
 * @brief SPI interrupt handler.
 * @param event
 */
void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void)
{
  blahblah(); // Processing (if any)
  mAccPacketTransferComplete = true;
  mSpiInterruptCounter++;
  pSPIM-&amp;gt;EVENTS_END = 0;
  // Data Synchronization Barrier: completes when all explicit memory accesses before this instruction complete
  __DSB();
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Nordic library code mostly reads back the register to enforce the instruction completing, but that can be unsafe depending on compiler and optimisation levels.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>