<?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>Counting Time</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/34639/counting-time</link><description>I&amp;#39;m working with nrf52 dk to read the sensor dht22. i need to follow this steps to make sure the sensor is ready to send data. 
 
 Wait until DHT responds and pulls the line to LOW after around 40 micro-seconds or else exit as timeout error. 
 Next, check</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 24 May 2018 11:10:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/34639/counting-time" /><item><title>RE: Counting Time</title><link>https://devzone.nordicsemi.com/thread/133202?ContentTypeID=1</link><pubDate>Thu, 24 May 2018 11:10:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54ccd10e-2e63-4c71-abc9-09f2d67b60a7</guid><dc:creator>Freitas</dc:creator><description>&lt;p&gt;is this a good approach?&lt;/p&gt;
&lt;p&gt;however it gives 5 message errors:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Error: L6218E: Undefined symbol rtc1_init (referred from teste.o).&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Counting Time</title><link>https://devzone.nordicsemi.com/thread/133201?ContentTypeID=1</link><pubDate>Thu, 24 May 2018 11:08:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b69866d2-31a0-4235-b6f9-9f54975d33a1</guid><dc:creator>Freitas</dc:creator><description>&lt;p&gt;i check the app_timer instead.&lt;/p&gt;
&lt;p&gt;this is my code so far:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;#include &amp;lt;stdint.h&amp;gt;&lt;br /&gt;#include &amp;lt;string.h&amp;gt;&lt;br /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;#include &amp;quot;nrf_drv_gpiote.h&amp;quot; // NordicSemiconductor::nRF_Drivers:nrf_drv_gpiote&lt;br /&gt;#include &amp;quot;nrf_delay.h&amp;quot; // NordicSemiconductor::nRF_Drivers:nrf_delay&lt;br /&gt;#include &amp;quot;app_error.h&amp;quot; // NordicSemiconductor::nRF_Libraries:app_error&lt;br /&gt;#include &amp;quot;startup_config.h&amp;quot; // NordicSemiconductor::Device:StartupConfig&lt;br /&gt;#include &amp;quot;nrf.h&amp;quot; // Device header&lt;br /&gt;#include &amp;quot;system_nrf52.h&amp;quot; // NordicSemiconductor::Device:Startup&lt;br /&gt;#include &amp;quot;RTE_Components.h&amp;quot; // Component selection&lt;br /&gt;#include &amp;quot;nrf_drv_timer.h&amp;quot; // NordicSemiconductor::nRF_Drivers:nrf_drv_timer&lt;br /&gt;#include &amp;quot;nrf_timer.h&amp;quot; // NordicSemiconductor::nRF_Drivers:nrf_timer&lt;br /&gt;#include &amp;quot;app_simple_timer.h&amp;quot; // NordicSemiconductor::nRF_Libraries:app_simple_timer&lt;br /&gt;#include &amp;quot;nrf_drv_rtc.h&amp;quot; // NordicSemiconductor::nRF_Drivers:nrf_drv_rtc&lt;br /&gt;#include &amp;quot;nrf_rtc.h&amp;quot; // NordicSemiconductor::nRF_Drivers:nrf_rtc&lt;br /&gt;#include &amp;quot;app_timer.h&amp;quot;&lt;br /&gt;#include &amp;quot;app_util_platform.h&amp;quot;&lt;br /&gt;#include &amp;quot;nrf_soc.h&amp;quot;&lt;br /&gt;#include &amp;quot;sdk_macros.h&amp;quot;&lt;/p&gt;
&lt;p&gt;#define level_0 0&lt;br /&gt;#define level_1 1&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;//#define DHT22_PIN D1&lt;br /&gt;uint32_t DHT22_PIN = 12;&lt;br /&gt;uint32_t time = 0; // Set to 0 for no prescaling.&lt;br /&gt;//counter&lt;br /&gt;uint32_t ticks_now = 0;&lt;br /&gt;uint32_t ticks_old = 0;&lt;br /&gt;uint32_t ticks_final = 0;&lt;br /&gt;uint32_t time_us = 0;&lt;/p&gt;
&lt;p&gt;//configuring the given GPIO pin number as output&lt;br /&gt;void DHT22_OUTPUT(void)&lt;br /&gt;{&lt;br /&gt; nrf_gpio_cfg_output(DHT22_PIN); &lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;//Function for configuring sense level for the given GPIO.&lt;br /&gt;void DHT22_ToLow(void)&lt;br /&gt;{&lt;br /&gt; nrf_gpio_cfg_sense_set(DHT22_PIN,NRF_GPIO_PIN_SENSE_LOW);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;//Function for configuring the given GPIO pin number as input &lt;br /&gt;void DHT22_INPUT(void)&lt;br /&gt;{&lt;br /&gt; nrf_gpio_cfg_input(DHT22_PIN, NRF_GPIO_PIN_PULLUP);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;uint32_t app_timer_ms(uint32_t ticks)&lt;br /&gt;{&lt;br /&gt; &lt;br /&gt; float numerator = ((float)time + 1.0f) * 1000.0f;&lt;br /&gt; float denominator = (float)APP_TIMER_CLOCK_FREQ;&lt;br /&gt; float ms_per_tick = numerator / denominator;&lt;/p&gt;
&lt;p&gt;uint32_t ms = ms_per_tick * ticks;&lt;/p&gt;
&lt;p&gt;return ms;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;void DHT22_START(void)&lt;br /&gt;{&lt;br /&gt; DHT22_OUTPUT();&lt;br /&gt; DHT22_ToLow();&lt;br /&gt; nrf_delay_ms(18);&lt;br /&gt; DHT22_INPUT();&lt;br /&gt; &lt;br /&gt; //initialize counter&lt;br /&gt; rtc1_init(time);&lt;br /&gt; //start counter&lt;br /&gt; rtc1_start();&lt;br /&gt; //get 1st value&lt;br /&gt; ticks_old = rtc1_counter_get();&lt;br /&gt; &lt;br /&gt; //Function for reading the input level of a GPIO pin.&lt;br /&gt; while(nrf_gpio_pin_read(DHT22_PIN)!=level_0) //0 if the pin input level is low.&lt;/p&gt;
&lt;p&gt;//get 2nd value&lt;br /&gt; ticks_now = rtc1_counter_get();&lt;br /&gt; //stop counter&lt;br /&gt; rtc1_stop();&lt;br /&gt; //get diff&lt;br /&gt; ticks_final = ticks_diff_get(ticks_now,ticks_old);&lt;br /&gt; &lt;br /&gt; //ticks to micro seconds&lt;br /&gt; time_us = app_timer_ms(ticks_final) / 1000; &lt;br /&gt; &lt;br /&gt; if(time_us &amp;lt; (20 * 10^-6) || time_us &amp;gt; (40*10^-6)) &lt;br /&gt; { &lt;br /&gt; printf(&amp;quot;Failed to communicate with sensor&amp;quot;);&lt;br /&gt; exit(0);&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;int main(void)&lt;br /&gt;{&lt;br /&gt; &lt;br /&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Counting Time</title><link>https://devzone.nordicsemi.com/thread/133138?ContentTypeID=1</link><pubDate>Thu, 24 May 2018 07:29:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ec424d4-a3d7-49c8-8bc1-3b3de508b260</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;You may take a look at the&amp;nbsp;\nRF5_SDK_15.0.0_a53641a\examples\peripheral\timer in the nRF SDK. This should show how to setup a timer, and for instance setup compare events. For instance&amp;nbsp;nrf_drv_timer_us_to_ticks() will help you to setup a timer with a specific us timeout.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Counting Time</title><link>https://devzone.nordicsemi.com/thread/133075?ContentTypeID=1</link><pubDate>Wed, 23 May 2018 16:20:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b987513-35d4-4bf9-bd18-04745121d10e</guid><dc:creator>Freitas</dc:creator><description>&lt;p&gt;Hi, thank you for your answer.&lt;/p&gt;
&lt;p&gt;i was thinking of doing something like this to point 1:&lt;/p&gt;
&lt;p&gt;----------------------------------------------------------&lt;/p&gt;
&lt;p&gt;start timer count&lt;/p&gt;
&lt;p&gt;while( line high) // just waiting to turn low&lt;/p&gt;
&lt;p&gt;Time = &amp;#39;count time&amp;#39;&lt;/p&gt;
&lt;p&gt;if( time &amp;lt; 20 || time &amp;gt; 40){&lt;/p&gt;
&lt;p&gt;error&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;-------------------------------------------------------&lt;/p&gt;
&lt;p&gt;do you thing this is a good&amp;nbsp;approach? can i get the time and compare the time in micro seconds?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Counting Time</title><link>https://devzone.nordicsemi.com/thread/133039?ContentTypeID=1</link><pubDate>Wed, 23 May 2018 14:14:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4271970-4062-432b-ace0-9746d446d009</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hi, there may be different ways to solve this, but it seems you have some tight timing requirements here. In that case it make sense to run this code when there is no BLE activity, and you for instance can temporary disable other interrupts that may interfere. In such case you may just use nrf_delay_us() for most part?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>