<?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>Is it possible to get an event/interrupt on CS falling edge using the SPI slave?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/95173/is-it-possible-to-get-an-event-interrupt-on-cs-falling-edge-using-the-spi-slave</link><description>Hi, 
 I&amp;#39;m developing on this setup: 
 
 nRF52833 DK, emulating an nRF52820. 
 Soft Device 113 version 7.2.0 
 SDK 17.1.0, with updated MDK (see link ) 
 IAR EW ARM 9.30 
 
 I need to get an event on the CS falling edge, with the nRF configured as a SPI</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 13 Jan 2023 18:05:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/95173/is-it-possible-to-get-an-event-interrupt-on-cs-falling-edge-using-the-spi-slave" /><item><title>RE: Is it possible to get an event/interrupt on CS falling edge using the SPI slave?</title><link>https://devzone.nordicsemi.com/thread/404867?ContentTypeID=1</link><pubDate>Fri, 13 Jan 2023 18:05:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e71f966a-bcbc-4965-8620-d8982f909e9a</guid><dc:creator>Federico</dc:creator><description>&lt;p&gt;Ok, great, that&amp;#39;s what I was missing. Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to get an event/interrupt on CS falling edge using the SPI slave?</title><link>https://devzone.nordicsemi.com/thread/404762?ContentTypeID=1</link><pubDate>Fri, 13 Jan 2023 10:16:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c225c05-5bc4-4e67-8330-e3933f4dda75</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;&lt;span&gt;Why does the master assert the CS pin before the SPIS has signalized&amp;nbsp;that it&amp;#39;s ready and the SPIS is initialized?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
[quote user="Federico"]Does the SPI peripheral work if it&amp;#39;s initialized with CS low? Or do I need to raise CS and lower it again to give it a new falling edge? If that&amp;#39;s the case, it looks like a quick pulse on CS could be used to initilize the SPI peripheral and the transfer should start after the nRF indicates it&amp;#39;s ready (with the other GPIO), lowering CS again.&amp;nbsp;[/quote]
&lt;p&gt;You would need to raise the CS pin so that it can detect the falling edge, if not then the SPIS peripheral will never try to acquire the semaphore resulting in the transaction being ignored as explained &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52833/spis.html?cp=4_1_0_5_23_2#concept_abk_lbf_wr"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;regards&lt;br /&gt;Jared&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to get an event/interrupt on CS falling edge using the SPI slave?</title><link>https://devzone.nordicsemi.com/thread/404196?ContentTypeID=1</link><pubDate>Tue, 10 Jan 2023 20:55:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd3f64b9-675e-4917-b851-b1d8ee767f9c</guid><dc:creator>Federico</dc:creator><description>&lt;p&gt;Hi Jared,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;We have tried this, but it doesn&amp;#39;t seem to work. I&amp;nbsp;think it&amp;#39;s because once the SPI peripheral is configured on the slave (nRF) the CS line is already low, so there&amp;#39;s no CS falling edge to tell the SPI peripheral that the transfer is incoming.&lt;/p&gt;
&lt;p&gt;Does the SPI peripheral work if it&amp;#39;s initialized with CS low? Or do I need to raise CS and lower it again to give it a new falling edge? If that&amp;#39;s the case, it looks like a quick pulse on CS could be used to initilize the SPI peripheral and the transfer should start after the nRF indicates it&amp;#39;s ready (with the other GPIO), lowering CS again.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to get an event/interrupt on CS falling edge using the SPI slave?</title><link>https://devzone.nordicsemi.com/thread/403877?ContentTypeID=1</link><pubDate>Mon, 09 Jan 2023 14:15:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:885501dc-3c3e-4581-ba50-e06b15166168</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been thinking about this and after some thought I think you can scratch my previous comment as it would require you to connect the two pins externally and would thus over-complicate this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is what I suggest:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use the CS signal and send a wakeup signal x ms before a transfer using the GPIOTE IN event on slave&lt;/li&gt;
&lt;li&gt;Wakeup on slave and de initialize GPIOTE and configure SPIS peripheral and use another GPIO to signalize ready to master and wait for SPI transfer in&amp;nbsp;IDLE sleep.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Initialize SPI on Master and start transfer.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;After Master has finished transfer, de initialize SPIS peripheral and initialize GPIOTE and go back to system off sleep.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The difference here is that you&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Send a wakeup signal with the CS pin from master before you&amp;nbsp;initialize&amp;nbsp;the SPI and SPIS on the master and slave respectively.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Only initialize the SPIS peripheral once you know a transfer is coming.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Yes, there will be some added latency due to waiting for SPI and SPIS peripheral to initialize on master and slave respectively, but I think this is the best approach as the master will still have full control of the CS line.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to get an event/interrupt on CS falling edge using the SPI slave?</title><link>https://devzone.nordicsemi.com/thread/403180?ContentTypeID=1</link><pubDate>Wed, 04 Jan 2023 12:33:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:294ec882-b5fa-4b20-89d9-4ac00deb517b</guid><dc:creator>Federico</dc:creator><description>&lt;p&gt;Hi Jared,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The way I&amp;#39;m&amp;nbsp;configuring the SPI is&amp;nbsp;with the spis_init function, as follows. This function runs once when fw boots.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void enable_spi_pin_handler( nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action )
{
	nrf_spis_enable( spis.p_reg );
	nrf_drv_spis_buffers_set( &amp;amp;spis, tx_buf, tx_length, rx_buf, SPIS_BUF_LEN );
}


static void init_enable_spi_interrupt( void )
{
	ret_code_t err_code;

	err_code = nrf_drv_gpiote_init();
	APP_ERROR_CHECK( err_code );

	nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO( false );
	in_config.pull = NRF_GPIO_PIN_PULLDOWN;

	err_code = nrf_drv_gpiote_in_init( SPI_CS_PIN, &amp;amp;in_config, enable_spi_pin_handler );
	APP_ERROR_CHECK( err_code );

	nrf_drv_gpiote_in_event_enable( SPI_CS_PIN, true );
}

void spis_init( void )
{
	ret_code_t err_code;

	nrf_drv_spis_config_t spis_config	= NRF_DRV_SPIS_DEFAULT_CONFIG;
	spis_config.sck_pin					= SPI_SCK_PIN;
	spis_config.miso_pin				= SPI_MISO_PIN;
	spis_config.mosi_pin				= SPI_MOSI_PIN;
	spis_config.csn_pin					= SPI_CS_PIN;
	spis_config.irq_priority			= APP_IRQ_PRIORITY_LOWEST;

	err_code = nrf_drv_spis_init( &amp;amp;spis, &amp;amp;spis_config, spis_event_handler );
	APP_ERROR_CHECK( err_code );

	nrf_spis_disable( spis.p_reg );
	init_enable_spi_interrupt();

	spi_incoming_parser_reset( &amp;amp;spi_incoming_parser );
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The way this is intended to work is for SPI to be off all the time, until the master pulls the CS line low. At that point, the nRF gets the CS event, enables the SPI peripheral and calls&amp;nbsp;nrf_drv_spis_buffers_set. On the&amp;nbsp;NRF_DRV_SPIS_BUFFERS_SET_DONE event, the nRF raises another GPIO to tell the master it&amp;#39;s ready (not included in this piece of code). After that, the master clocks all bits into the nRF and pulls CS high. This causes the&amp;nbsp;NRF_DRV_SPIS_XFER_DONE event to be generated, the nRF processes the packet and disables the SPI again.&lt;/p&gt;
&lt;p&gt;Note that the GPIO event is configured after initializing the SPI, so presumably the GPIO will override the SPI behavior. And this sort of happens, because on certain occasions I don&amp;#39;t get the&amp;nbsp;&amp;nbsp;NRF_DRV_SPIS_XFER_DONE event when CS line goes high again. If I switch the lines and call&amp;nbsp;init_enable_spi_interrupt before&amp;nbsp;nrf_drv_spis_init, then I never get the CS falling edge interrupt and SPI is never enabled. So they seem to be overriding each other.&lt;/p&gt;
&lt;p&gt;I&amp;#39;d assume this is the expected behavior right? Is there a way to work around this?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;I haven tried it myself but you can toggle a GPIO from sw that is connected to the CS pin trough GPIOTE + PPI.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Would this require an external hardware connection or is it all internal? I&amp;#39;m not familiar with PPI yet, could you elaborate please?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to get an event/interrupt on CS falling edge using the SPI slave?</title><link>https://devzone.nordicsemi.com/thread/402321?ContentTypeID=1</link><pubDate>Tue, 27 Dec 2022 17:20:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:846046db-15ef-446e-9959-f550c4bd8c05</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi there,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user=""]. I read somewhere (I can&amp;#39;t seem to find it now) that the SPIS module uses the GPIOTE to monitor the CS falling edge and start the transaction[/quote]
&lt;p&gt;&lt;a href="https://github.com/NordicSemiconductor/nrfx/blob/23fb4437c08a9edfdf6d34f002322f693a15e8fe/drivers/src/nrfx_spis.c#L97"&gt;You&amp;#39;re correct&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;But I can&amp;#39;t see exactly how this would mess up with the SPIS driver. Can you share how you&amp;#39;re configuring the GPIOTE interrupt?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user=""]It&amp;#39;d be great if there was a way to get an event for the CS falling edge without messing with the SPI peripheral. Or a way to send a &amp;quot;fake&amp;quot; event to the SPI, so that my GPIOTE interrupt handles the falling edge and forwards it to the other module. Is this possible? Can I generate a fake CS falling edge from software?[/quote]
&lt;p&gt;I haven tried it myself but you can toggle a GPIO from sw that is connected to the CS pin trough GPIOTE + PPI.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>