<?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>nRF52840 USB HID with simultaneous SPIM transfer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/44908/nrf52840-usb-hid-with-simultaneous-spim-transfer</link><description>Hello, 
 I use SDK15.2, SES4.12 and custom board with nRF52840. 
 I have a strip of ws2812b LED&amp;#39;s connected to my device. I&amp;#39;ve made a simple RGB animation, each frame of which is transferred via SPIM. It works fine. 
 Now I need to add some USB HID functionality</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 21 Mar 2019 11:20:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/44908/nrf52840-usb-hid-with-simultaneous-spim-transfer" /><item><title>RE: nRF52840 USB HID with simultaneous SPIM transfer</title><link>https://devzone.nordicsemi.com/thread/177552?ContentTypeID=1</link><pubDate>Thu, 21 Mar 2019 11:20:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:648609b0-af50-4404-9db6-e3e7f055796f</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Good to hear you figured it out, I will close the case then &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 USB HID with simultaneous SPIM transfer</title><link>https://devzone.nordicsemi.com/thread/176954?ContentTypeID=1</link><pubDate>Tue, 19 Mar 2019 11:10:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6816b13-b18b-4ebb-8f0c-6e2ec7a83308</guid><dc:creator>ilia</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The problem is solved now. It was not related to USB, SPI, or the board itself. I just&amp;nbsp;unintentionally made&amp;nbsp;one mistake in placing variables in memory.&amp;nbsp;&lt;span style="font-family:inherit;"&gt;Basically I created a variable inside a function and stored its address in a global variable, and used this address in further calls.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 USB HID with simultaneous SPIM transfer</title><link>https://devzone.nordicsemi.com/thread/176678?ContentTypeID=1</link><pubDate>Mon, 18 Mar 2019 12:02:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93bc19e2-db41-4ddf-8876-4daca1be978b</guid><dc:creator>ilia</dc:creator><description>&lt;p&gt;How can I make USB and SPIM working together? These features work perfectly if I use them separately, but if I turn on both USB and SPIM my application crashes. Maybe there is some sort of interruption conflict?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 USB HID with simultaneous SPIM transfer</title><link>https://devzone.nordicsemi.com/thread/176513?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2019 17:28:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2109eb78-a521-4ea6-b50f-95b5d6f3b3e9</guid><dc:creator>ilia</dc:creator><description>&lt;p&gt;It works, but only without call to&amp;nbsp;__WFE();, and without USB functionality.&lt;/p&gt;
&lt;p&gt;If I have&amp;nbsp;app_usbd_event_queue_process() call in my main cycle, application breaks in the same way it was before any modifications.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 USB HID with simultaneous SPIM transfer</title><link>https://devzone.nordicsemi.com/thread/176509?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2019 17:06:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d66855f5-7e19-4584-bc80-da22a7d2c4a1</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;For this I would just count wakeups rather than complicating it with another interrupt for the timer. Something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Trigger every 1,000 wakeups if 1mSec system tick, 100 if 10mSec system tick
static uint32 LoopCount = 0;

		if ((SPI_Status) &amp;amp;&amp;amp; ((++LoopCount % 1000) == 0))
		{
			SPI_Status = 0;
			NRF_LOG_INFO(&amp;quot;Transfer completed.&amp;quot;);
			// Edit: remove this linenrf_delay_ms(10); 
			RGB_Refresh();  
		}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 USB HID with simultaneous SPIM transfer</title><link>https://devzone.nordicsemi.com/thread/176507?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2019 16:58:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cffd52f6-b534-4fc2-bc92-00769598f0bc</guid><dc:creator>ilia</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I agree, calling RGB_Refresh in interrupt is not a good idea. I placed it there in attempt to find working solution.&lt;/p&gt;
&lt;p&gt;I have modified my main:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int main(void)
{  
    nrf_gpio_cfg_output( LOGO );
    
	Logo_Initialize(LOGO);

	HID_Initialize();

    while (true)
    {
		while (app_usbd_event_queue_process())
        {
            /* Nothing to do */
        }
      
		if (SPI_Status)
		{
			SPI_Status = 0;
			NRF_LOG_INFO(&amp;quot;Transfer completed.&amp;quot;);
			nrf_delay_ms(10); 
			RGB_Refresh();  
		}
        /* Sleep CPU only if there was no interrupt since last loop processing */
        __WFE();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The behavior is the same as in my previous version, and the problem is still present.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I use&amp;nbsp;nrf_delay_ms(10); just to slow down animation, perhaps it is not a good way to do it. I&amp;#39;ll try to change it to timer api.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 USB HID with simultaneous SPIM transfer</title><link>https://devzone.nordicsemi.com/thread/176500?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2019 16:20:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b22cd8ba-2aaa-4b42-a59e-2550c60bbfd9</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I would suggest that you have an issue with putting stuff in the interrupt which does not belong in an interrupt, particularly when that stuff generates the same interrupt before the current interrupt completes. Perhaps change this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void spim_event_handler(nrfx_spim_evt_t const * p_event, void * p_context)
{
    NRF_LOG_INFO(&amp;quot;Transfer completed.&amp;quot;);
	
	nrf_delay_ms(10);
	RGB_Refresh();  
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;to something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Flag to trigger next display refresh outside of any interrupt
volatile uint16_t SPI_Signal = 0;

void spim_event_handler(nrfx_spim_evt_t const * p_event, void * p_context)
{
   SPI_Signal++;
}

   // in main loop after wakeup due to SPI interrupt above
   if (SPI_Signal)
   {
    SPI_Signal = 0;
    NRF_LOG_INFO(&amp;quot;Transfer completed.&amp;quot;);
	nrf_delay_ms(10); // &amp;lt;== what&amp;#39;s this for? better to use a timer
	RGB_Refresh();  
   }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;SPI_Signal should only be 0 or 1, but it doesn&amp;#39;t hurt to allow more for debugging&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>