<?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>nRF51422 SPI disable/enable with softdevice</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/18381/nrf51422-spi-disable-enable-with-softdevice</link><description>I have an issue with waking up SPI communication after sleep. 
 Befor I go to sleep I&amp;#39;m disabling SPI communication: 
 NRF_SPI0-&amp;gt;ENABLE = 0;
NRF_SPI1-&amp;gt;ENABLE = 0;
 
 Handler function triggered by timer (which is responsible for wake-up) enabling</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 09 Apr 2018 14:37:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/18381/nrf51422-spi-disable-enable-with-softdevice" /><item><title>RE: nRF51422 SPI disable/enable with softdevice</title><link>https://devzone.nordicsemi.com/thread/127473?ContentTypeID=1</link><pubDate>Mon, 09 Apr 2018 14:37:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc20bf41-310c-48ef-a938-2d4e76eedc6f</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;This issue have been fixed in SDK 15.0.0 with the new nrfx driver module.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 SPI disable/enable with softdevice</title><link>https://devzone.nordicsemi.com/thread/123274?ContentTypeID=1</link><pubDate>Wed, 07 Mar 2018 14:38:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0c94193-22d6-400a-a68e-a1b1bd4f8c5e</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Thank you for reporting this. I have forwarded the issue to the developers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 SPI disable/enable with softdevice</title><link>https://devzone.nordicsemi.com/thread/123148?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 23:15:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e1d0397-4369-417c-9e9b-39ea5f1060f9</guid><dc:creator>riataman</dc:creator><description>&lt;p&gt;I was running into this, about 60uA consumtion after calling nrf_drv_spi_init then nrf_drv_spi_uninit.&lt;/p&gt;
&lt;p&gt;I figured out it was NRF_SPI_DRV_MISO_PULLUP_CFG set to NRF_GPIO_PIN_PULLUP in sdk_config.h. Was seting up a pull up on nrf_drv_spi_init , but nrf_drv_spi_uninit wasn&amp;#39;t undoing that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 SPI disable/enable with softdevice</title><link>https://devzone.nordicsemi.com/thread/70956?ContentTypeID=1</link><pubDate>Mon, 19 Dec 2016 17:34:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc4554a5-0356-496e-aa70-e36d8cc544d5</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;It may be that the SPI interface is not successfully disabled before you go to sleep. Can you try to wait for the bit to be set, before going to sleep:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while(NRF_SPI0-&amp;gt;ENABLE != 0)
{
    nrf_drv_spi_uninit(&amp;amp;spi);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or check if it is set before enabling the SPI interface on wakeup:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if(NRF_SPI0-&amp;gt;ENABLED == 0)
{
   nrf_drv_spi_init(&amp;amp;spi, &amp;amp;spi_config, spi_event_handler)
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 SPI disable/enable with softdevice</title><link>https://devzone.nordicsemi.com/thread/70955?ContentTypeID=1</link><pubDate>Thu, 15 Dec 2016 20:59:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88be948f-212c-4569-800e-9050962a294a</guid><dc:creator>Marcin</dc:creator><description>&lt;p&gt;Hello Jorgen,&lt;/p&gt;
&lt;p&gt;My code is quite long and divided into a couple of files, but below are parts related to SPI and sleep.
I suppose that it will be challenging to go through.
I skipped some parts like variables definition and not related code...
Briefly:
I have 2 modules (ADC and gyro) connected to nRF51422, both work fine till the moment when go to sleep - go_sleep() function.
Then I want to wake up gyro module and read current values.
I&amp;#39;m not able to do it because  communication causing reset (return code 17).
Timer1_handler function is responsible for waking up.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;        int main(void)
        {
        	ret_code_t err_code;
        		softdevice_setup();
            ant_channel_tx_broadcast_setup();
        		**spi_setup_adc();
        		spi_setup_gyro();**
            gpio_init();
        	
        		create_timers();
        		start_timer1(CHECK_TIME_WHEN_SLEEP);
        
        		// reset
        	  	ads1247_reset();
        		nrf_delay_ms(2); // 0.6 ms after reset
         		ads1247_set_reg_MUX1(2, 2, 0); // ON, but OFF when sleep
        		nrf_delay_ms(1);
        		// ADS1247 set register SYS0
        		// Gain: 1,2,4,8,16,32,64,128 SPS:5,10,20,40,80,160,320,640,1000,2000
        		ads1247_set_reg_SYS0(128, 160);
        		nrf_delay_ms(10);
        		// Self offset calibration
        		ads1247_selfocal();
        		nrf_delay_ms(10);
    
        		l3g4200d_set_register(CTRL_REG4, 0xE0);
        		nrf_delay_ms(10);
        		l3g4200d_set_register(CTRL_REG1, 0x7C);
        		
        		pwr_start_flag = true;
        		nrf_delay_ms(1);
          
        		for (;;)
        		{
        			// Calibration request
        			if (pwr_calib_request)
        				pwr_calib();
        
        			**if (cad0_counter&amp;gt;20) go_sleep();**
        			
        			// Put CPU in sleep if possible.			
        			err_code = sd_app_evt_wait();
              APP_ERROR_CHECK(err_code);
        			nrf_delay_ms(10);
        	
        		}
    
        void spi_setup_gyro()
        {
        	  nrf_drv_spi_config_t const config_gyro =
            {
                .sck_pin  		= SPIM1_SCK_PIN_GYRO,
                .mosi_pin 		= SPIM1_MOSI_PIN_GYRO,
                .miso_pin 		= SPIM1_MISO_PIN_GYRO,
                .ss_pin   		= SPIM1_SS_PIN_GYRO,
                .irq_priority = APP_IRQ_PRIORITY_LOW,
        				.orc          = 0xFF,
                .frequency    = NRF_DRV_SPI_FREQ_1M,
                .mode         = NRF_DRV_SPI_MODE_3,
                .bit_order    = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST,
            };
            ret_code_t err_code = nrf_drv_spi_init(&amp;amp;m_spi_master_gyro, &amp;amp;config_gyro, spi_master_event_handler_gyro);
        		APP_ERROR_CHECK(err_code);
        	}

void spi_unsetup_gyro()
{
    nrf_drv_spi_uninit(&amp;amp;m_spi_master_gyro);
}
    
    
        void l3g4200d_read_register(uint8_t reg, uint8_t len)
        {
        		m_tx_data_gyro[0] = 192 + reg;
        		spi_send_recv_gyro(m_tx_data_gyro, m_rx_data_gyro, SPI_BUF_LEN1, len+1);
        		int i;  
    // Temporary for error analyzing		
        		for (i = 0; i &amp;lt; len; i++)
            {
        				SEGGER_RTT_WriteString(0, &amp;quot;\nGyro register &amp;quot;);
        				sprintf(RTT_terminal_str, &amp;quot;%i&amp;quot;, reg+i);
        				SEGGER_RTT_WriteString(0, RTT_terminal_str);
        				SEGGER_RTT_WriteString(0, &amp;quot; : &amp;quot;);
        				sprintf(RTT_terminal_str, &amp;quot;%i&amp;quot;, m_rx_data_gyro[i+1]);
        				SEGGER_RTT_WriteString(0, RTT_terminal_str);
                }
            }
    
    
    static void spi_send_recv_gyro(uint8_t * const p_tx_data,
                              uint8_t * const p_rx_data,
                              const uint16_t  len_tx,
    													const uint16_t  len_rx)
    {	
        uint32_t err_code = nrf_drv_spi_transfer(&amp;amp;m_spi_master_gyro,
            p_tx_data, len_tx, p_rx_data, len_rx);
    		APP_ERROR_CHECK(err_code);
    }


void go_sleep()
{
ret_code_t err_code;	
		// Sleep
			cad0_counter = 0;
			// ------ Close ANT channel
				err_code = sd_ant_channel_close(BPWR_CHANNEL_NUMBER);
				APP_ERROR_CHECK(err_code);
				nrf_delay_ms(1);
			// ------ Stop counting
				pwr_start_flag = false;
			// ------ Power down ADC
				nrf_drv_gpiote_out_clear(START_PIN_ADC); //Power down
				nrf_delay_ms(1);
				//NRF_SPI0-&amp;gt;ENABLE = 0;
				spi_unsetup_adc();
			// ------ Power down Gyro			
				l3g4200d_set_register(CTRL_REG1, 0x70); //Power down
				nrf_delay_ms(1);
				//NRF_SPI1-&amp;gt;ENABLE = 0;
				spi_unsetup_gyro();
				nrf_drv_gpiote_out_set(SPIM1_MOSI_PIN_GYRO); // Pull up MOSI to save power ~300uA
			// ------ Set sleep flag
				sleep_flag = true;
}


static void timer1_handler(void * p_context)
{
int32_t l_gyro_val = 0;
	
	nrf_drv_gpiote_out_toggle(LED_PIN);
		if(sleep_flag)
		{
			//Wake up gyro for a while and check
				//NRF_SPI1-&amp;gt;ENABLE = 1;
				spi_setup_gyro();
				nrf_delay_ms(1);
				l3g4200d_read_register(CTRL_REG1, 1);  // Reading data causing the issue (reset) !!!
				//l3g4200d_set_register(CTRL_REG1, 0x7C); //Power up
				nrf_delay_ms(1);
				//NRF_SPI1-&amp;gt;ENABLE = 0;
				spi_unsetup_gyro();
		}
		else
		{
			// do nothing
		}
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 SPI disable/enable with softdevice</title><link>https://devzone.nordicsemi.com/thread/70953?ContentTypeID=1</link><pubDate>Thu, 15 Dec 2016 09:29:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d39173db-b349-4fe7-b9fe-25f70563e124</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Can you upload your code, to show how SPI is init, transfer, going to sleep, etc.?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 SPI disable/enable with softdevice</title><link>https://devzone.nordicsemi.com/thread/70954?ContentTypeID=1</link><pubDate>Wed, 14 Dec 2016 21:12:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04fdb3f1-5f0e-4de7-9b79-fec7555c6668</guid><dc:creator>Marcin</dc:creator><description>&lt;p&gt;Hello Jorgen,&lt;/p&gt;
&lt;p&gt;I replaced:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_SPI0-&amp;gt;ENABLE... 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;with&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrf_drv_spi_init
nrf_drv_spi_uninit
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;accordingly&lt;/p&gt;
&lt;p&gt;Same result.&lt;/p&gt;
&lt;p&gt;Marcin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 SPI disable/enable with softdevice</title><link>https://devzone.nordicsemi.com/thread/70952?ContentTypeID=1</link><pubDate>Wed, 14 Dec 2016 10:07:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a6463d4-103b-4cd7-b5df-ba5b451a4473</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Can you try to disable and enable the SPI interface using &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.2.0/group__nrf__drv__spi.html#ga26c8de34c1a218eba9e1d7522ae8727c"&gt;&lt;code&gt;nrf_drv_spi_uninit()&lt;/code&gt;&lt;/a&gt; and &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.2.0/group__nrf__drv__spi.html#ga6a5a24a4ccf990f95bc94bd99ea48e6f"&gt;&lt;code&gt;nrf_drv_spi_init()&lt;/code&gt;&lt;/a&gt;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>