<?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>Writing BLE Scan data to SD Card</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/33560/writing-ble-scan-data-to-sd-card</link><description>Hi, 
 Right now I have a program on nRF52-DK (SDK 11) that scans for BLE adv packets, and transfers data from some specific addresses to PC through UART. Around every 10ms there is 30 bytes of new data to be transferred. In the current program, the UART</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 30 Apr 2018 21:36:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/33560/writing-ble-scan-data-to-sd-card" /><item><title>RE: Writing BLE Scan data to SD Card</title><link>https://devzone.nordicsemi.com/thread/130354?ContentTypeID=1</link><pubDate>Mon, 30 Apr 2018 21:36:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:265994fd-982c-44bf-8198-8c67e39de21a</guid><dc:creator>FA</dc:creator><description>&lt;p&gt;Ok, so either my question was very easy or everyone was waiting to see what happens after implementation!&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&amp;nbsp;Here is a summary of what I have right now. Hope it can be useful for others + let me know your comments.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1-&lt;/strong&gt; I ported my program w/ UART from SDK 11 to SDK 12.3 using the template of ble_uart_app example, and everything worked fine.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2-&lt;/strong&gt; I tested the FATFS example from SDK 12.3 with &lt;a href="https://www.sparkfun.com/products/12941"&gt;this&lt;/a&gt; SD card interface/nRF52-DK and it worked. One issue that I noticed was that when the GND pin of the SDC was connected to the GND pin available on the header where VDD pin is, &lt;span style="text-decoration:underline;"&gt;SDC mounting failed&lt;/span&gt; every now and then. Connecting the GND to above P0.25 solved the issue and mounting never failed again.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3-&lt;/strong&gt; I added the FATFS functions and files to my own program. Complied without error, but &lt;span style="text-decoration:underline;"&gt;program was restarted&lt;/span&gt; whenever BLE scanning was called. It turned out the issue was using the NRF_LOG settings. I still have the UART in my code, and it seems NRF_LOG has an issue when used with UART. I noticed some posts that they can work together if we change some settings, but as the LOG was not important, I unchecked the NRF_LOG from sdk.config.h and the restart issue was solved. Let me know if you know an easy and straight forward way of using the NRF_LOG without facing this issue.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4-&amp;nbsp;&lt;/strong&gt;I started testing with a few seconds between receiving BLE packets and using only one buffer to write. I decreased the packet intervals down to 500ms and still the data was written to SDC without any issue. I haven&amp;#39;t precisely compared the packet loss with and without write to SDC, but looking at the counter in the packets, the error rates seems to be close to each other. This means so far the SDC interface is not blocking the BLE. Buffer size was changed between hundred bytes to 10 Kbyte. File was open before starting the scan, f_sync used after f_open and f_write, write performed in main.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5-&amp;nbsp;&lt;/strong&gt;For msec intervals, the 2 buffer approach was implemented. Same results, and to verify the code, I toggled 3 pins as follows:&lt;/p&gt;
&lt;p&gt;Pin 1: Toggle to 1 and then 0 at the start/end BLE handler when an address match is detected.&lt;/p&gt;
&lt;p&gt;Pin 2: Toggle to 1 and 0 at the start/end of the flag check that writes to SDC when any buffer is full.&lt;/p&gt;
&lt;p&gt;Pin 4: SDC Clk used, 8 MHz here.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;-&lt;em&gt; Writes to SDC needs different times (2nd trace) in each write, although buffer size is the same&amp;nbsp;&lt;/em&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/4162.pastedimage1525123207804v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;- &lt;em&gt;Still receiving BLE packets (1st trace) while the buffer is being written to SDC&amp;nbsp;&lt;/em&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/5483.pastedimage1525123578045v4.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;- &lt;em&gt;No SDC Clock (3rd trace) while running the code in the BLE handler (1st trace)&lt;/em&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/2844.pastedimage1525123396308v3.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;- &lt;em&gt;SDC&amp;nbsp;clocked&amp;nbsp;(3rd trace) even while running&amp;nbsp;the code in the BLE handler&amp;nbsp;(1st trace)&lt;/em&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/4571.pastedimage1525123357711v2.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>