<?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 when advertising not working</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/30111/spi-when-advertising-not-working</link><description>Hi 
 I am using SPI to talk to an LIS2DH with an NRF51822. I have merged the SPI Master example with the ble_app_rscs example and as soon as the ble advertising begins, my SPI interrupts no longer work and I end up in the hard fault. I have changed the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 06 Feb 2018 06:02:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/30111/spi-when-advertising-not-working" /><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119854?ContentTypeID=1</link><pubDate>Tue, 06 Feb 2018 06:02:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d76e6d9-4a6c-410d-ba07-6c4c55cd2b84</guid><dc:creator>danimalia</dc:creator><description>&lt;p&gt;In the interest of closing this thread out - I managed to get this to work by setting a global flag in my timeout_handler which is where I need to call the SPI data. in my main loop I check the flag and call the spi function if it is set.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119641?ContentTypeID=1</link><pubDate>Sun, 04 Feb 2018 17:33:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74964d3c-8cdf-41d8-a167-337a39f394a4</guid><dc:creator>danimalia</dc:creator><description>&lt;p&gt;I&amp;#39;m not - just the spi_master example which I ported to the rscs example.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have since followed &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/4683/error-after-transmit-complete-event-in-spi-softdevice-enabled/16608#16608"&gt;this&amp;nbsp;&lt;/a&gt;&amp;nbsp;thread exactly but&amp;nbsp;&lt;span class="n"&gt;spi_master_event_handler() never gets called once I have begun advertising. hence I get stuck waiting for&amp;nbsp;m_transfer_completed to become true when I call&amp;nbsp;get_acc_data(), which I am doing in&amp;nbsp;sensorsim_measure()&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119638?ContentTypeID=1</link><pubDate>Sun, 04 Feb 2018 12:45:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:90682da1-0b0a-4d98-a5c3-18e58c863bbe</guid><dc:creator>gkovelman_tap</dc:creator><description>&lt;p&gt;I haven&amp;#39;t worked with SDK8.0.0 and aren&amp;#39;t familiar with the API but are you using SPI with EasyDMA? It works well with SoftDevice in the background.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119626?ContentTypeID=1</link><pubDate>Sat, 03 Feb 2018 15:58:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c8a23cb-2e51-4ff2-938a-2e3d078f6d97</guid><dc:creator>danimalia</dc:creator><description>&lt;p&gt;I&amp;#39;m sorry, but I don&amp;#39;t understand exactly how to convert the existing spi code to what you posted above. can you provide a bit more detail, or pointers to where I can find more examples?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;going through the forums it seems that a lot of people had the same problem when trying to get spi master to work with softdevice present, but I can&amp;#39;t find a definitive solution.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thank you.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119623?ContentTypeID=1</link><pubDate>Sat, 03 Feb 2018 14:16:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:563da5a0-3d58-4ad1-9c10-0f88b22aabb4</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;I already shoed you the code previously. &amp;nbsp;You can also find a lot of examples in the SDK.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119618?ContentTypeID=1</link><pubDate>Sat, 03 Feb 2018 04:06:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c46edf8-207d-4794-9160-ab3db8208963</guid><dc:creator>danimalia</dc:creator><description>&lt;p&gt;OK, I understand thank you.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Can you how me where to place and how to call the app_scheduler for this situation please? the current interrupt is in spi_master.c:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void SPI0_TWI0_IRQHandler(void)
{
    if ((NRF_SPI0-&amp;gt;EVENTS_READY == 1) &amp;amp;&amp;amp; (NRF_SPI0-&amp;gt;INTENSET &amp;amp; SPI_INTENSET_READY_Msk))
    {
        NRF_SPI0-&amp;gt;EVENTS_READY = 0;

        volatile spi_master_instance_t * p_spi_instance = spi_master_get_instance(SPI_MASTER_0);

        spi_master_send_recv_irq(p_spi_instance);
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119616?ContentTypeID=1</link><pubDate>Sat, 03 Feb 2018 02:42:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f16b3b7-938f-4c88-95fe-f3a91039c516</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;When softdevice is running, &amp;nbsp;you cannot debug. &amp;nbsp;You can breakpoint only. &amp;nbsp;Then it will crash if you try to step. &amp;nbsp;You need to restart every time you break. &amp;nbsp;With softdevice, you cannot hold the processor too long so the SPI init and data reading has to be done quickly. &amp;nbsp;Calling SD function within interrupt also not permitted. &amp;nbsp;Hence require to use App Scheduler. &amp;nbsp;When you hold the process too long, SD will crash. &amp;nbsp;This mean you SPI init and read data are taking too long to complete.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119610?ContentTypeID=1</link><pubDate>Sat, 03 Feb 2018 00:45:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4fa59698-74b9-4677-8b1c-a5b5439d498e</guid><dc:creator>danimalia</dc:creator><description>&lt;p&gt;let me re-phrase that:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;the processor doesn&amp;#39;t hang - I can still see me ble advertising packets and connect to it etc. as soon as I call&amp;nbsp;spi_master_init or&amp;nbsp;spi_send_recv after I have called advertising_init, nothing happens. I have scoped the SPI lines and nothing happens on them.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If I put breakpoints on&amp;nbsp;s&lt;span&gt;pi_master_init or&amp;nbsp;&lt;/span&gt;&lt;span&gt;spi_send_recv, I end up in the hardfault if I try step over those functions.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;seriously confused here&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119608?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2018 22:47:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f802e11f-9d62-49a2-b252-f3a6f7ebf4fe</guid><dc:creator>danimalia</dc:creator><description>&lt;p&gt;in the hardfault:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/2117.Capture.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;the call stack is also not helping me determine how it got there...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119607?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2018 22:30:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86addb10-e240-4bef-8e6e-292566f9a598</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;Where does it hang exactly ? Are there any errors returned by the SDK ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119606?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2018 22:26:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:659f30b0-ef42-4496-b85e-ee39f59b895f</guid><dc:creator>danimalia</dc:creator><description>&lt;p&gt;That&amp;rsquo;s what I thought, I changed it to only call spi_config once and then removed all the delays in get_acc_data and it still hangs&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119604?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2018 22:22:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3002c44-e0a4-4825-9991-aef2bedab8dd</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;It doesn&amp;#39;t work after advertisement_start() is normal. &amp;nbsp;The spi_config is taking to much time. &amp;nbsp;Softdevice does like it. &amp;nbsp;There are also to many delays in your get_acc_data. &amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119602?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2018 22:12:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0dba52ff-a19c-415e-9bde-3d1b085596a9</guid><dc:creator>danimalia</dc:creator><description>&lt;p&gt;actually I&amp;#39;m not sure if I&amp;#39;m setting this up right at all. here is my code:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;spi_config() works fine when called the first two&amp;nbsp;time in the main loop. once advertising_start() has been called it no longer works - to test I am simply trying to call the accelerometer data as part of the cadence measurement send:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int main(void)
{
    uint32_t err_code;how to 
	
    // Initialize.
    app_trace_init();
		leds_init();
    ble_stack_init();
    device_manager_init();
    timers_init();
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);
    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
                        APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
                        NULL);
    APP_ERROR_CHECK(err_code);
    gap_params_init();
    advertising_init();
    services_init();
    sensor_simulator_init();
    conn_params_init();
		spi_master_init(SPI_MASTER_0, spi_master_0_event_handler, false);
		spi_config(); 
    // Start execution.
    application_timers_start();	
    advertising_start();
    // Enter main loop.
    for (;; )
    {
        power_manage(); 
    }
}


void spi_config(void)
{
		    // Setup bsp module.
   // bsp_configuration();
	 

		uint8_t tx_data[2] = {0x00, 0x00};  							// Transmit register
		uint8_t rx_data[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};  // Receive register


			tx_data[0] = ( WHO_AM_I | 0x80 ); //Add the RW bit to the address.
			m_transfer_completed   = false; 
			nrf_delay_ms(1);
			spi_master_init(SPI_MASTER_0, spi_master_0_event_handler, false);
			spi_send_recv(SPI_MASTER_0, tx_data, rx_data, 2); 

			nrf_delay_ms(10); 
	//write ctr_reg1
			tx_data[0] = CTR_REG1; 
			tx_data[1] = 0xFF;		//low power mode 
      m_transfer_completed   = false;
      nrf_delay_ms(1);
			spi_master_init(SPI_MASTER_0, spi_master_0_event_handler, false);
      spi_send_recv(SPI_MASTER_0, tx_data, rx_data, 2); 
			nrf_delay_ms(10);
		
		//read it back
			tx_data[0] = (CTR_REG1 | 0x80); 
			tx_data[1] = 0x00;		
      m_transfer_completed   = false;
      nrf_delay_ms(1);
			spi_master_init(SPI_MASTER_0, spi_master_0_event_handler, false);
      spi_send_recv(SPI_MASTER_0, tx_data, rx_data, 2);  
			nrf_delay_ms(10);
		
		//write ctr_reg4
			tx_data[0] = CTR_REG4; 
			tx_data[1] = 0x08;		//low power mode
      m_transfer_completed   = false;
      nrf_delay_ms(1);
			spi_master_init(SPI_MASTER_0, spi_master_0_event_handler, false); 
      spi_send_recv(SPI_MASTER_0, tx_data, rx_data, 2); 
			nrf_delay_ms(10);
			
			//read it back
			tx_data[0] = (CTR_REG4 | 0x80); 
			tx_data[1] = 0x00;		//low power mode
      m_transfer_completed   = false;
      nrf_delay_ms(1);
			spi_master_init(SPI_MASTER_0, spi_master_0_event_handler, false);
      spi_send_recv(SPI_MASTER_0, tx_data, rx_data, 2); 

			nrf_delay_ms(10);
		
		#ifdef SPI_TEST
		while (true)
    {
			tx_data[0] = (OUT_X_H_addr | 0xC0 );		//read bit set (bit 0) &amp;amp; increment registers (bit 1)  
			tx_data[1] = 0x00;
      m_transfer_completed   = false;
      nrf_delay_ms(1);
			spi_master_init(SPI_MASTER_0, spi_master_0_event_handler, false);
      spi_send_recv(SPI_MASTER_0, tx_data, rx_data, 7); 
			nrf_delay_ms(500);
    }
		#endif //SPI_TEST
	
}

uint8_t get_acc_data(void)
{
			uint8_t tx_data[2] = {0x00, 0x00}; 																// Transmit register
			uint8_t rx_data[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};  // Receive register
	
//			tx_data[0] = (OUT_X_H_addr | 0xC0 );															//read bit set (bit 0) &amp;amp; increment registers (bit 1)  
//			tx_data[1] = 0x00;
//      m_transfer_completed   = false;
//      nrf_delay_ms(1);
//			spi_master_init(SPI_MASTER_0, spi_master_0_event_handler, false);
//      spi_send_recv(SPI_MASTER_0, tx_data, rx_data, 7); 
//			nrf_delay_ms(10);

			tx_data[0] = ( WHO_AM_I | 0x80 ); //Add the RW bit to the address.
			m_transfer_completed   = false;
			//nrf_delay_ms(1);
			spi_master_init(SPI_MASTER_0, spi_master_0_event_handler, false);
			spi_send_recv(SPI_MASTER_0, tx_data, rx_data, 2); 

			//nrf_delay_ms(10); 
			return rx_data[1];
}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;then in ble_rscs.c:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint32_t ble_rscs_measurement_send(ble_rscs_t * p_rscs, ble_rscs_meas_t * p_measurement)
{
    uint32_t err_code;
		uint8_t tx_data[2] = {0x00, 0x00}; 							// Transmit register
		uint8_t rx_data[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};  // Receive register
		
		
    // Send value if connected and notifying
    if (p_rscs-&amp;gt;conn_handle != BLE_CONN_HANDLE_INVALID)
    {
        uint8_t                encoded_rsc_meas[MAX_RSCM_LEN];
        uint16_t               len;
        uint16_t               hvx_len;
        ble_gatts_hvx_params_t hvx_params;

				
			
        len     = rsc_measurement_encode(p_rscs, p_measurement, encoded_rsc_meas);
        hvx_len = len;

        memset(&amp;amp;hvx_params, 0, sizeof(hvx_params));

        hvx_params.handle = p_rscs-&amp;gt;meas_handles.value_handle;
        hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
        hvx_params.offset = 0;
        hvx_params.p_len  = &amp;amp;hvx_len;
			
				encoded_rsc_meas[0] = get_acc_data();
        hvx_params.p_data = encoded_rsc_meas;

			
        err_code = sd_ble_gatts_hvx(p_rscs-&amp;gt;conn_handle, &amp;amp;hvx_params);
        if ((err_code == NRF_SUCCESS) &amp;amp;&amp;amp; (hvx_len != len))
        {
            err_code = NRF_ERROR_DATA_SIZE;
        }
    }
    else
    {
        err_code = NRF_ERROR_INVALID_STATE;
    }

    return err_code;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119601?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2018 22:01:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b25073e6-9edf-4ca9-a55e-c50b7cfd91d2</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;It should be the same.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119595?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2018 21:23:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fb681fd-a72d-4123-bcc7-54c4ff4d6d2c</guid><dc:creator>danimalia</dc:creator><description>&lt;p&gt;thanks. what would be the equivalent app_scheduler to use in SDK 8?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI when advertising not working</title><link>https://devzone.nordicsemi.com/thread/119464?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2018 04:02:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:10c3b5ce-b0fe-4e0a-baa9-1227a0b15757</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;Try to use app_scheduler to differ interrupt processing.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void SchedIrqHandler(void * p_event_data, uint16_t event_size)

{

...

}



void IRQ_Handler()

{

    uint32 evt = 1;

    app_sched_event_put(&amp;amp;evt, sizeof(uint32_t), SchedIrqHandler);

}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>