<?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>How to execute a routine after successful connection to peripherial?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10076/how-to-execute-a-routine-after-successful-connection-to-peripherial</link><description>Hello,
I am using ble_app_multilink_central example as a foundation of my app involving central - peripherial connection (S120 - S110). My app works nicely but i have problem accomplishing one thing - i need to synchronize some data between central and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 04 Nov 2015 22:39:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10076/how-to-execute-a-routine-after-successful-connection-to-peripherial" /><item><title>RE: How to execute a routine after successful connection to peripherial?</title><link>https://devzone.nordicsemi.com/thread/37357?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2015 22:39:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:791cad21-d692-4585-8061-846a35d17b4e</guid><dc:creator>woytekm</dc:creator><description>&lt;p&gt;Hi Nathan, thanks. I followed your suggestion, moved sync routine to main(), made it to trigger on a flag set in db_discovery_event_handler and it seems to work as i wanted. Thanks again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute a routine after successful connection to peripherial?</title><link>https://devzone.nordicsemi.com/thread/37356?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2015 16:55:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41dfc435-7ca0-4ec9-bf9e-097689aeb306</guid><dc:creator>Nathan</dc:creator><description>&lt;p&gt;Woytekm,&lt;/p&gt;
&lt;p&gt;You cannot call the sd_ble_gattc_write function from an interrupt context above NRF_APP_PRIORITY_LOW (or APP_IRQ_PRIORITY_LOW, as defined in util_platform instead of nrf_soc). The event callbacks from the BLE stack are running at either softdevice priority low or softdevice priority high depending on the callback, which are both above NRF_APP_PRIORITY_LOW. Therefore the stack reports it&amp;#39;s too busy at the current time to handle pushing new data on the output buffer. I forget exactly where this is documented, so if someone could provide a link as a comment to this answer I&amp;#39;d appreciate it.&lt;/p&gt;
&lt;p&gt;Probably your best option is to create a volatile flag that you set at the end of db_discovery_event_handler to trigger the synchronization process from the main context, and implement a state machine of some kind to hold off any other kind of data transfer until the sync process is complete. You&amp;#39;ll have several milliseconds to get each command/read on the output buffer before the next connection interval from main (exact time depending on connection interval and length of time taken to execute any BLE event callbacks), so as long as your central device isn&amp;#39;t doing much else at the time the system should work fine using this solution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>