<?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>BLE timeout when SAADC sample rate is high</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77555/ble-timeout-when-saadc-sample-rate-is-high</link><description>Hi, I&amp;#39;m sending SAADC data via BLE. If my SAADC_SAMPLE_RATE is high(e.g. 250ms), the code works perfectly fine. However, if I sample at a fast rate (e.g. 10ms), there will be a BLE ERROR 8 (0x8) GATT CONN TIMEOUT issue. 
 1) Does the error caused by BLE</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 24 Aug 2021 11:14:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77555/ble-timeout-when-saadc-sample-rate-is-high" /><item><title>RE: BLE timeout when SAADC sample rate is high</title><link>https://devzone.nordicsemi.com/thread/326341?ContentTypeID=1</link><pubDate>Tue, 24 Aug 2021 11:14:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9188346c-4302-4d10-a9d6-c5e938d7eeb0</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="StevenW807"]Thanks for your help, Karl.[/quote]
&lt;p&gt;No problem at all, I am happy to help!&lt;br /&gt;&lt;br /&gt;Thank you for providing the sniffer traces, this makes it a lot easier for me to see what is happening.&lt;br /&gt;It seems to me that your peripheral device abruptly stops responding in the unstable trace - this is very helpful for debugging purposes.&lt;br /&gt;This behavior makes me suspect that the device might be encountering an error that causes it to reset, could this be the case?&lt;br /&gt;Are you able to monitor what is happening on the peripheral side of the link when this behavior occurs?&lt;br /&gt;I see from your included main.c code that you are initializing the logger. Are you seeing the logger&amp;#39;s RTT output? You should be able to see this either in the&amp;nbsp;&lt;em&gt;SES Debug terminal&amp;nbsp;&lt;/em&gt;or in the standalone&amp;nbsp;&lt;em&gt;SEGGER RTT Viewer&amp;nbsp;&lt;/em&gt;desktop application.&lt;br /&gt;&lt;br /&gt;Based on the information we have so far I am suspecting that the increased sampling rate is causing a buffer to overflow, which in turn resets the device.&lt;br /&gt;The default error handling of the APP_ERROR_CHECK is to reset the device, so unless you have implemented specific error handling for it this is what will happen whenever a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK.&lt;br /&gt;&lt;br /&gt;Please make sure to have DEBUG defined in your preprocessor defines for the&amp;nbsp;&lt;em&gt;common&lt;/em&gt; build configuration like described in my initial reply, and check what the RTT log reads when this behavior occurs. Please let me know what the logger says.&lt;br /&gt;&lt;br /&gt;Looking forward to resolving this issue together!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE timeout when SAADC sample rate is high</title><link>https://devzone.nordicsemi.com/thread/326080?ContentTypeID=1</link><pubDate>Mon, 23 Aug 2021 06:09:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:abacaa04-331c-491c-a390-a1aa461cb348</guid><dc:creator>StevenW807</dc:creator><description>&lt;p&gt;Thanks for your help, Karl.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I used Nordic UART Service --&amp;gt; Tx Characteristic in nRF Connect App to receive BLE data. When SAADC interrupt time = 50ms, both BLE advertising and receiving data are&amp;nbsp;very stable. It will never disconnect.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;However, if I change to&amp;nbsp;&lt;span&gt;SAADC interrupt time = 20ms, BLE advertising and connection are very unstable. BLE advertising and connection are fine. But after selecting&amp;nbsp;receiving data, BLE will disconnect automatically after 1-20 seconds. The Error message is: &lt;strong&gt;Error 8 (0x8): GATT CONN TIMEOUT&lt;/strong&gt;.&amp;nbsp;&lt;/span&gt;&lt;span&gt;Because in 50ms SAADC interrupt case, BLE works fine. So I think that my code has no problem.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In my code, I used TWI, SAADC (PPI interruption), UART and BLE. I used the internal clock, clock calibration in SDK is configured. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I used the nRF52 DK as the BLE sniffer. Here are 2 sniffer log files:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Sniffer 1) stable BLE connection (50ms SAADC interrupt)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Sniffer 2)&amp;nbsp;unstable BLE connection (20ms SAADC interrupt)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you very much!&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/Unstable-BLE.pcapng"&gt;devzone.nordicsemi.com/.../Unstable-BLE.pcapng&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/Stable-BLE.pcapng"&gt;devzone.nordicsemi.com/.../Stable-BLE.pcapng&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE timeout when SAADC sample rate is high</title><link>https://devzone.nordicsemi.com/thread/325170?ContentTypeID=1</link><pubDate>Mon, 16 Aug 2021 15:06:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:433ce396-3acd-4230-8080-bd466b3ff26e</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;Thank you for your continued patience with this. I have been out of office for some time now, but now I am back.&lt;/p&gt;
[quote user="StevenW807"]Thank you so much for your detailed support, Karl!&amp;nbsp;[/quote]
&lt;p&gt;No problem at all, I am happy to help!&lt;br /&gt;Thank you for elaborating.&amp;nbsp;&lt;/p&gt;
[quote user="StevenW807"]BLE seems to be very unstable (BLE will disconnect after 2-20 seconds).[/quote]
&lt;p&gt;What do you mean what you say unstable? What reason do you get for the disconnect?&lt;br /&gt;Could you possibly provide a sniffer trace of the on-air BLE traffic when this happens? You could use &lt;a href="https://www.nordicsemi.com/Products/Development-tools/nrf-sniffer-for-bluetooth-le"&gt;the nRF Sniffer tool&lt;/a&gt;&amp;nbsp;to capture this trace.&lt;/p&gt;
[quote user="StevenW807"]&lt;p&gt;I have read another &lt;a href="https://blog.csdn.net/liwei16611/article/details/90412480"&gt;post &lt;/a&gt;on a Chinese website. The author says that the reason&amp;nbsp;is: Device hasn&amp;#39;t completed transmitting the current data, and the device tries to send another new data. The solution is to add a flag in BLE. The device only allows sending the next data until the previous data has been sent successfully.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Do you support his/her opinion? How to add this &amp;quot;BLE transmitting is completed flag&amp;quot;, please?&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;[/quote]
&lt;p&gt;This will not be the case when working with the SoftDevice. The SoftDevice handles all this for you, behind the scenes. What I could imagine might be happening is that the SoftDevice returns an error code (non-NRF_SUCCESS) to the application after a function call, and that the application then resets due to this error, thus disrupting the BLE connection and everything else. Could this be the case?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE timeout when SAADC sample rate is high</title><link>https://devzone.nordicsemi.com/thread/322034?ContentTypeID=1</link><pubDate>Tue, 27 Jul 2021 11:56:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bd012aa9-4085-40f5-8428-ab9b0de0c829</guid><dc:creator>StevenW807</dc:creator><description>&lt;p&gt;Thank you so much for your detailed support, Karl!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My SAADC uses timer1 and PPI to generate interruption every XXX ms. If 50ms, my BLE works perfectly fine. However, if I shorten the interruption time, for example 10ms, BLE seems to be very unstable (BLE will disconnect after 2-20 seconds). I only send a very small amount of data (about 10-15 bytes) every time.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have read another &lt;a href="https://blog.csdn.net/liwei16611/article/details/90412480"&gt;post &lt;/a&gt;on a Chinese website. The author says that the reason&amp;nbsp;is: Device hasn&amp;#39;t completed transmitting the current data, and the device tries to send another new data. The solution is to add a flag in BLE. The device only allows sending the next data until the previous data has been sent successfully.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Do you support his/her opinion? How to add this &amp;quot;BLE transmitting is completed flag&amp;quot;, please?&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Thanks, &lt;span&gt;Karl&lt;/span&gt;!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE timeout when SAADC sample rate is high</title><link>https://devzone.nordicsemi.com/thread/320481?ContentTypeID=1</link><pubDate>Fri, 16 Jul 2021 14:28:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82dfdf6f-08ef-40bf-8314-22ada2c4559c</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]1) Does&amp;nbsp;the error caused by BLE MTU, or SAADC dual Buffer, or something else?&amp;nbsp;[/quote]
&lt;p&gt;I am not sure what you are asking here, are you getting an error? If so, what error is generated?&lt;br /&gt;Please make sure to have DEBUG defined in your preprocessor defines, like shown in the included image, to have the logger output a detailed error message whenever a non-NRF_SUCCSS error code is passed to an APP_ERROR_CHECK.&lt;br /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/3426.enabling_5F00_debug_5F00_SES.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;EDIT: I see now that you say you are getting a GATT timeout error. This means that your connection times out - i.e the central or peripheral is not hearing from its peer in the time configured as the timeout. Are the devices still within range? Is both devices always powered on?&lt;/p&gt;
[quote user=""]2) If I set SAADC buffer = 4 and 4 channels, does that mean SAADC will save the past 4 data in the 4 channels (in total 16 data), and give return averaged data for 4 channels?[/quote]
&lt;p&gt;No, if you set SAADC buffer to 4, it will be big enough to contain 4 samples.&lt;br /&gt;If you are using the SAADC in scan mode, it will sample once from every enabled channel each time the SAMPLE task is triggered, which will then produce 4 samples, immediately filling up the buffer.&lt;br /&gt;If you would like the SAADC to average over a number of samples you will have to enable oversampling on the channels. Please be advised that oversampling must be configured together with burst mode, in order to work when the SAADC is in scan mode.&amp;nbsp;&lt;/p&gt;
[quote user=""]3) I use the timer to interrupt SAADC. For each interrupt, there will be only 1 SAADC reading. If SAADC_SAMPLE_RATE = 250ms and buffer = 4, does that mean SAADC returns the data at 1 second ago (250ms*4 = 1sec)?&amp;nbsp;[/quote]
&lt;p&gt;No, each time SAMPLE is triggered it will sample all enabled channels, which here is 4. 4 samples will therefore be generated every sampling.&lt;/p&gt;
[quote user=""]4) BLE min/max connection interval is 10ms to 20ms. If my SAADC timer interrupts every 250ms, what data will BLE send during most of the connection intervals? Just empty packages?[/quote]
&lt;p&gt;Yes. If there is no data to be sent when a connection event is upcoming both devices will send an empty packet to maintain the connection. In these cases you should either increase your connection interval, or make use of the&amp;nbsp;&lt;em&gt;slave latency&lt;/em&gt; feature in order to save power.&lt;/p&gt;
[quote user=""]5) If the&amp;nbsp;&lt;span&gt;BLE min/max connection interval is 10ms to 20ms, and&amp;nbsp;&lt;/span&gt;&lt;span&gt;my SAADC timer interrupts every 5ms, does that mean there will be 2-4 packets (Rx+Tx is 1 packet) for each connection interval?&amp;nbsp;&lt;/span&gt;[/quote]
&lt;p&gt;This depends on your&amp;nbsp;&lt;em&gt;connection event length&amp;nbsp;&lt;/em&gt;configuration. If there is more packets to send, the devices will keep on sending packets for the entire duration of the&amp;nbsp;&lt;em&gt;&lt;/em&gt;configured&amp;nbsp;&lt;em&gt;connection event length&lt;/em&gt;. You can use &lt;a href="https://devzone.nordicsemi.com/nordic/power/w/opp/2/online-power-profiler-for-ble"&gt;the Online Power profiler&lt;/a&gt; to see how different size TX payloads are transferred depending on the&amp;nbsp;configured&amp;nbsp;&lt;em&gt;connection event length&lt;/em&gt; and &lt;em&gt;connection interval&lt;/em&gt;.&lt;/p&gt;
[quote user=""]6) My custom board uses an internal RC oscillator (32.768kHz), Why does SAADC uses&amp;nbsp;NRF_TIMER_FREQ_31250Hz, but not 32.768kHz?&amp;nbsp;[/quote]
&lt;p&gt;The TIMER peripheral uses the HFCLK, not the LFCLK. The frequency therefore have to be a multiple of the HFCLK frequency, since the lower frequencies are implemented by prescaling the HFCLK tick rate. You can find &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Fgroup__nrf__timer__hal.html&amp;amp;anchor=ga28862835cd77a9c8481ed04c7b1918eb"&gt;the available prescaler values here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>