<?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>Issue reading SD card from within a Gatt connection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/58666/issue-reading-sd-card-from-within-a-gatt-connection</link><description>Hi, 
 I am using a NRF58240-dk pca10056 S140. 
 I have an external SD card device connected which, I am writing live sensor data to then advertising that data over a ble advertisement packet. I also have the code functionality to have a GATT connection</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 18 Mar 2020 11:28:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/58666/issue-reading-sd-card-from-within-a-gatt-connection" /><item><title>RE: Issue reading SD card from within a Gatt connection</title><link>https://devzone.nordicsemi.com/thread/240407?ContentTypeID=1</link><pubDate>Wed, 18 Mar 2020 11:28:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9687c146-8acc-4e82-b808-2293952376ae</guid><dc:creator>Thomas</dc:creator><description>&lt;p&gt;Thanks for the response. I am now trying to implement your solution but, I am having an issue with passing over the boolean command from the gatt connection. My code looks like below.&lt;/p&gt;
&lt;p&gt;From me passing in a Gatt command from my mobile application I change a boolean main_test to 1. I tried with an int and bool and both failed to print out to the RTT terminal. What could I be doing wrong? I decalre the variable in another file I am using as an extern int main_test; and define it in the c file as int main_test = 0;&lt;/p&gt;
&lt;p&gt;My code is below:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void Process_data(void)
{
    if(GATT_CONNECTED == false)
    {
        //Non gatt connected functions here
    }
    else if (GATT_CONNECTED == true)// GATT_CONNECTED = true
    {
        NRF_LOG_INFO(&amp;quot;Test1 passed&amp;quot;);//Testing variable.
        if(main_test == 1)
        {
            NRF_LOG_INFO(&amp;quot;Test2 passed&amp;quot;);//Testing variable.
            main_test = 0;//False
        }
        if(main_read_sd_card == true)//Not used at the moment by the idea of how I will read the CSV
        {
            NRF_LOG_INFO(&amp;quot;Go to reading CSV file in main code&amp;quot;);
            main_read_sd_card = false;
            SEND_CSV();//Run the function to send the CSV file
        }
        sd_app_evt_wait();//Processing for SD CARD
        idle_state_handle();
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue reading SD card from within a Gatt connection</title><link>https://devzone.nordicsemi.com/thread/238480?ContentTypeID=1</link><pubDate>Fri, 06 Mar 2020 10:13:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f22d2ae7-4a8f-4516-8868-f0db8dcf241e</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Yes, program execution returns to the main loop once event processing is complete. So you could add some global state flags that are updated in your event handlers and polled in your main loop. &lt;/p&gt;
&lt;p&gt;static bool m_rcvd_data_request;&lt;/p&gt;
&lt;p&gt;main()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;for(;;)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (m_rcvd_data_request) // Always checked after application interrupts&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_rcvd_data_request = false;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //TODO: add calls to load data from SD and send over BLE&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if( &amp;lt;flag&amp;gt;)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; idle_state_handle(); // sleep while waiting for new events&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue reading SD card from within a Gatt connection</title><link>https://devzone.nordicsemi.com/thread/238475?ContentTypeID=1</link><pubDate>Fri, 06 Mar 2020 10:01:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8aee1259-5856-4966-ba87-cb87f8bc0395</guid><dc:creator>Thomas</dc:creator><description>&lt;p&gt;Ok but does the main loop run whilst a connection is made? If so I can just test for a connection(I am using a Boolean at the moment and just running idle state handle in it). If so I could poll a value to see if a command for reading the SD card has been called.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue reading SD card from within a Gatt connection</title><link>https://devzone.nordicsemi.com/thread/238454?ContentTypeID=1</link><pubDate>Fri, 06 Mar 2020 09:24:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:895e4705-125e-4aa1-b1ca-b5bcc808f481</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Thomas, glad to hear that it worked. Would it make sense to just perform the read and write from your main loop instead of doing it inside the Softdevice interrupt? I think that&amp;#39;s probably the easiest solution to this. Another option is to implement the app scheduler library so Softdevice events are not reported in the interrupt context. There is a tutorial for it here: &lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/scheduler-tutorial"&gt;https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/scheduler-tutorial&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue reading SD card from within a Gatt connection</title><link>https://devzone.nordicsemi.com/thread/238335?ContentTypeID=1</link><pubDate>Thu, 05 Mar 2020 14:40:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ccaaec1-21f5-4823-98f0-04ff422f6cd6</guid><dc:creator>Thomas</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;That fix worked thanks very much!&lt;/p&gt;
&lt;p&gt;However, how else would you recommend me handling this?&lt;/p&gt;
&lt;p&gt;Basically I have the need to read a CSV file stored on my SD card and then I need to transfer it over my bluetooth Gatt connection to my phone.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Thomas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue reading SD card from within a Gatt connection</title><link>https://devzone.nordicsemi.com/thread/238280?ContentTypeID=1</link><pubDate>Thu, 05 Mar 2020 12:32:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d42f92b-1eaf-49cf-84a2-ed97c6719e9f</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The&amp;nbsp;block_dev_handler() callback must get invoked to clear the &amp;quot;m_drives[n].busy&amp;quot; flag&amp;nbsp;that&amp;nbsp;keeps the&amp;nbsp;program spinning inside the wait loop.&amp;nbsp;The problem is that&amp;nbsp;the callback won&amp;#39;t get invoked if the wait loop is already run in an interrupt context with the same interrupt priority (ie if SPI IRQ pri == Softdevice). At least I think this is the problem. Please increase the interrupt priority for the SPI to&amp;nbsp;SPI_DEFAULT_CONFIG_IRQ_PRIORITY==5 in sdk_config.h and see if you get the same result. Both SPI and Softdevice use priority &amp;#39;6&amp;#39; by default. That said, I think the best solution is to not do these operations from an interrupt context&amp;nbsp;to keep your interrupt service routines short.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>