<?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>HCSR04 with nRF52 (PCA10040)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/28137/hcsr04-with-nrf52-pca10040</link><description>Hi developer, sorry to interrupt and ask. How to use an ultrasonic sensor with nRF52? Since I search a code for nRF52 are not exist and see ultrasonic sensor can connect with nRF51. Hope that is some solution to use ultrasonic with nRF52.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 11 Dec 2017 16:56:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/28137/hcsr04-with-nrf52-pca10040" /><item><title>RE: HCSR04 with nRF52 (PCA10040)</title><link>https://devzone.nordicsemi.com/thread/111086?ContentTypeID=1</link><pubDate>Mon, 11 Dec 2017 16:56:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9545aa41-9f79-484c-abe8-cac02b35ddc7</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Have you been through the &lt;a href="https://devzone.nordicsemi.com/tutorials/36/"&gt;nRF52 Getting Started&lt;/a&gt; tutorial on devzone?&lt;/p&gt;
&lt;p&gt;You should definitely start there if you don&amp;#39;t have previous Nordic experience. Once you have been able to complete that you can start extending the examples with more code, to read your sensor.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HCSR04 with nRF52 (PCA10040)</title><link>https://devzone.nordicsemi.com/thread/111087?ContentTypeID=1</link><pubDate>Sun, 10 Dec 2017 17:02:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b33135c-9f76-4dd1-b8a8-08039fb6418a</guid><dc:creator>Khairi</dc:creator><description>&lt;p&gt;Can not working.&lt;/p&gt;
&lt;p&gt;I tried using this code on GitHub by use &amp;quot;&lt;a href="https://github.com/electronut/nRF51-hcsr04-test"&gt;this link&lt;/a&gt;&amp;quot; but they are some error and warning. Since I&amp;#39;m beginner about nrf52 and nrf51 and connected with some device and sensor make me cannot understanding about code. Hope some can teach me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HCSR04 with nRF52 (PCA10040)</title><link>https://devzone.nordicsemi.com/thread/111085?ContentTypeID=1</link><pubDate>Thu, 30 Nov 2017 12:10:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d07f5d1f-b7e2-4a60-9377-33e8c756837b</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;If I am not mistaken, to use this sensor you have to generate a short pulse from the nRF5x, and measure the time it takes until you receive a pulse in return from the sensor?&lt;/p&gt;
&lt;p&gt;To do that you can use the TIMER, PPI and GPIOTE peripherals in the nRF52, which allow you to generate the pulse and measure the delay without having to run a lot of code in the CPU.&lt;/p&gt;
&lt;p&gt;The code for this could look something like this (not tested!):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define SENSOR_PIN_OUT      2
#define SENSOR_PIN_IN       3
#define PPI_CH_A            0
#define PPI_CH_B            1
#define PPI_CH_C            2
#define GPIOTE_CH_A         0
#define GPIOTE_CH_B         1
#define PULSE_LENGTH_MS     10
#define TIMEOUT_LENGTH_MS   500

void sensor_init(void)
{
    // Timer configuration
    NRF_TIMER0-&amp;gt;PRESCALER   = 4; // (16M / (2^4)) = 1MHz timer frequency
    NRF_TIMER0-&amp;gt;CC[0]       = 1;
    NRF_TIMER0-&amp;gt;CC[1]       = PULSE_LENGTH_MS * 1000 + 1;
    NRF_TIMER0-&amp;gt;CC[2]       = 0;
    NRF_TIMER0-&amp;gt;CC[3]       = TIMEOUT_LENGTH_MS * 1000;
    NRF_TIMER0-&amp;gt;SHORTS      = TIMER_SHORTS_COMPARE3_STOP_Msk | TIMER_SHORTS_COMPARE3_CLEAR_Msk;
    NRF_TIMER0-&amp;gt;INTENSET    = TIMER_INTENSET_COMPARE3_Msk;
    
    // GPIOTE configuration
    NRF_GPIOTE-&amp;gt;CONFIG[GPIOTE_CH_A] = GPIOTE_CONFIG_MODE_Task   &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                                      SENSOR_PIN_OUT            &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos |
                                      GPIOTE_CONFIG_OUTINIT_Low &amp;lt;&amp;lt; GPIOTE_CONFIG_OUTINIT_Pos;
    NRF_GPIOTE-&amp;gt;CONFIG[GPIOTE_CH_B] = GPIOTE_CONFIG_MODE_Event  &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                                      SENSOR_PIN_IN             &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos |
                                      GPIOTE_CONFIG_POLARITY_LoToHi &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos;
    
    // PPI configuration    
    NRF_PPI-&amp;gt;CH[PPI_CH_A].EEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[GPIOTE_CH_B];
    NRF_PPI-&amp;gt;CH[PPI_CH_A].TEP = (uint32_t)&amp;amp;NRF_TIMER0-&amp;gt;TASKS_CAPTURE[2];
    NRF_PPI-&amp;gt;CHENSET = (1 &amp;lt;&amp;lt; PPI_CH_A);
    NRF_PPI-&amp;gt;CH[PPI_CH_B].EEP = (uint32_t)&amp;amp;NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0];
    NRF_PPI-&amp;gt;CH[PPI_CH_B].TEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_SET[GPIOTE_CH_A];
    NRF_PPI-&amp;gt;CHENSET = (1 &amp;lt;&amp;lt; PPI_CH_B);    
    NRF_PPI-&amp;gt;CH[PPI_CH_C].EEP = (uint32_t)&amp;amp;NRF_TIMER0-&amp;gt;EVENTS_COMPARE[1];
    NRF_PPI-&amp;gt;CH[PPI_CH_C].TEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_CLR[GPIOTE_CH_A];
    NRF_PPI-&amp;gt;CHENSET = (1 &amp;lt;&amp;lt; PPI_CH_C);

    // Interrupt configuration
    NVIC_SetPriority(TIMER0_IRQn, 7);
    NVIC_EnableIRQ(TIMER0_IRQn);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then to start a reading you would simply have to start the timer:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_TIMER0-&amp;gt;TASKS_START = 1;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Best regards&lt;br /&gt;
Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HCSR04 with nRF52 (PCA10040)</title><link>https://devzone.nordicsemi.com/thread/111084?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 19:55:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:871baa8c-795f-409f-855a-e89f6afa55c9</guid><dc:creator>endnode</dc:creator><description>&lt;p&gt;And also if you have example working with nRF51 then you can start from there because it will typically use some SPI/I2C/UART driver from SDK which works on nRF52 as well.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HCSR04 with nRF52 (PCA10040)</title><link>https://devzone.nordicsemi.com/thread/111083?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 18:35:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6dd48a1-b280-468c-85e7-fc9a398763e0</guid><dc:creator>Kyle Krueger</dc:creator><description>&lt;p&gt;Hi Khairi,&lt;/p&gt;
&lt;p&gt;You might have some better luck if you post some specs of the sensor you are talking about. At least a part number, and maybe a link to the data sheet.&lt;/p&gt;
&lt;p&gt;Also, what you expect to do with it.&lt;/p&gt;
&lt;p&gt;You might find some libraries for it on mBed or some other platforms, but don&amp;#39;t expect everything to be plug in and play.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>