<?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 wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/16126/how-to-wake-up-from-idle-mode-using-ppi</link><description>Hi 
 I want to know how to use ppi to wake up CPU from IDLE mode. 
 I&amp;#39;ve tried to use timer timeout event for triggering Port Event and wake up CPU, but can&amp;#39;t assign NRF_GPIOTE-&amp;gt;EVENTS_PORT to ppi channel. nrf_drv_ppi_channel_assign returns NRF_ERROR_INVALID_STATE</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 06 Sep 2016 11:41:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/16126/how-to-wake-up-from-idle-mode-using-ppi" /><item><title>RE: how to wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/thread/61495?ContentTypeID=1</link><pubDate>Tue, 06 Sep 2016 11:41:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4535c2a2-3751-49b9-8e11-041ecfb3e774</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;For debugging &lt;code&gt;printf&lt;/code&gt; should be OK (in a loop or not), but you should &lt;em&gt;not&lt;/em&gt; use it for production, as you will have higher current consumption etc. Also, in general debugging with &lt;code&gt;printf&lt;/code&gt;&amp;#39;s can be a bad idea, as it will be easy to misunderstand the order of events. Have you for example verified that there is no error check that causes a reset, which would make it seem like the looping is constant, when what might really be happening is that &lt;code&gt;main()&lt;/code&gt; is constantly started again after each reset? How have you verified that the CPU does not go to sleep?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/thread/61505?ContentTypeID=1</link><pubDate>Mon, 05 Sep 2016 06:32:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1557c499-cb41-4b2c-93c7-788c48ed5827</guid><dc:creator>Haruki Kawakami</dc:creator><description>&lt;p&gt;could you answer above question?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/thread/61504?ContentTypeID=1</link><pubDate>Fri, 02 Sep 2016 02:29:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:778a685a-5df2-4b77-874e-5ef0be1d153e</guid><dc:creator>Haruki Kawakami</dc:creator><description>&lt;p&gt;hi
I tried commenting out printf in while loop, then CPU sleep again and printf in timer_event_handler runs every 2ms and BSP_LED_0_MASK(LED1) blinks.
printf in while loop is bad coding?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/thread/61503?ContentTypeID=1</link><pubDate>Fri, 02 Sep 2016 01:47:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:104687e5-f443-46f1-8268-5cacc4f6d6b8</guid><dc:creator>Haruki Kawakami</dc:creator><description>&lt;p&gt;Hi, of course  I defined them like below.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const nrf_drv_timer_t timer1 = NRF_DRV_TIMER_INSTANCE(1);

nrf_ppi_channel_t ppi_channel1;

void uart_error_handle(app_uart_evt_t * p_event)
{
    if (p_event-&amp;gt;evt_type == APP_UART_COMMUNICATION_ERROR)
    {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_communication);
    }
    else if (p_event-&amp;gt;evt_type == APP_UART_FIFO_ERROR)
    {
          APP_ERROR_HANDLER(p_event-&amp;gt;data.error_code);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/thread/61502?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2016 12:18:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:50474b25-c666-4816-a7ea-af8e708ec410</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Can you post the rest of your code as well? For example &lt;code&gt;ppi_channel1&lt;/code&gt; is not defined anywhere, and neither is &lt;code&gt;timer1&lt;/code&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/thread/61501?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2016 11:20:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fc09e9c-a91f-407c-bf67-4126e9149cf6</guid><dc:creator>Haruki Kawakami</dc:creator><description>&lt;p&gt;Hi I paste my codes.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void timer_event_handler(nrf_timer_event_t event_type, void * p_context){
    printf(&amp;quot;kumi %d\n\r&amp;quot;, nrf_gpio_pin_read(LED_1));
}

static void ppi_init(void)
{
    uint32_t err_code = NRF_SUCCESS;

    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel1);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_assign(ppi_channel1,
                                          nrf_drv_timer_event_address_get(&amp;amp;timer1, NRF_TIMER_EVENT_COMPARE0),
                                          NRF_GPIOTE-&amp;gt;EVENTS_PORT);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_enable(ppi_channel1);
    APP_ERROR_CHECK(err_code);
}

static void timer1_init(void)
{
    ret_code_t err_code = nrf_drv_timer_init(&amp;amp;timer1, NULL, timer_event_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_extended_compare(&amp;amp;timer1, NRF_TIMER_CC_CHANNEL0, 0x7FFFUL, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);
}

int main(void)
{
    uint32_t err_code;

    timer1_init(); // Timer to generate events on even number of seconds.

    nrf_drv_timer_compare_int_enable(&amp;amp;timer1, NRF_TIMER_CC_CHANNEL0);
    const app_uart_comm_params_t comm_params =
     {
         RX_PIN_NUMBER,
         TX_PIN_NUMBER,
         RTS_PIN_NUMBER,
         CTS_PIN_NUMBER,
         APP_UART_FLOW_CONTROL_ENABLED,
         false,
         UART_BAUDRATE_BAUDRATE_Baud115200
     };

    APP_UART_FIFO_INIT(&amp;amp;comm_params,
                    UART_RX_BUF_SIZE,
                    UART_TX_BUF_SIZE,
                    uart_error_handle,
                    APP_IRQ_PRIORITY_LOW,
                    err_code);

    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_enable(&amp;amp;timer1);

    while (true)
    {
        __WFI();
        printf(&amp;quot;Current count\n\r&amp;quot;);
        if(LED_IS_ON(BSP_LED_0_MASK)){
            LEDS_OFF(BSP_LED_0_MASK);
       } else {
           LEDS_ON(BSP_LED_0_MASK);
       }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/thread/61500?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2016 11:11:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c2a26f5-44c9-4b90-9796-20a93280ef14</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;When you use the driver you should not have to clear the interrupt explicitly (as you do with &lt;code&gt;nrf_timer_event_clear()&lt;/code&gt;, as it is done by the driver. You can see this in nrf_drv_timer.c, where the &lt;code&gt;irq_handler()&lt;/code&gt; calls &lt;code&gt;nrf_timer_event_clear()&lt;/code&gt; just before it calls the event handler you registered with the call to &lt;code&gt;nrf_drv_timer_init()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t understand why your CPU does not go back to sleep, though. Can you double-check?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/thread/61499?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2016 10:47:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74c4575e-0bae-41ad-a3f2-e00a0e6f4077</guid><dc:creator>Haruki Kawakami</dc:creator><description>&lt;p&gt;I made it to wake CPU using  nrf_drv_timer_compare_int_enable(), but I can&amp;#39;t make CPU sleep again.&lt;/p&gt;
&lt;p&gt;It seems that compare event is always true once happened.
then I&amp;#39;ve used nrf_timer_event_clear to make compare event false, but cannot resolve this problem.&lt;/p&gt;
&lt;p&gt;how can i make CPU sleep again?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; while (true)
{
    __WFI();
    printf(&amp;quot;Current count\n\r&amp;quot;);
    nrf_timer_event_clear(timer1.p_reg, nrf_timer_compare_event_get(NRF_TIMER_CC_CHANNEL0));
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/thread/61498?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2016 09:07:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0de37544-34d1-42bc-9840-47925561d297</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Yes, if you enable the interrupt for the relevant compare event in the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/timer.html?cp=2_2_0_23_4_1#register.INTENSET"&gt;INTENSET&lt;/a&gt; register (directly, or by using &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/group__lib__driver__timer.html?cp=6_0_0_6_7_20_1_12#ga5647281b3b8b0fe1949c161b2c1542ac"&gt;&lt;code&gt;nrf_drv_timer_compare_int_enable()&lt;/code&gt;&lt;/a&gt; as you already use the timer driver).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/thread/61497?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2016 09:01:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f48762d7-708b-4574-b38d-8331c299724c</guid><dc:creator>Haruki Kawakami</dc:creator><description>&lt;p&gt;do the compare event wake the CPU?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to wake up from IDLE mode using ppi?</title><link>https://devzone.nordicsemi.com/thread/61496?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2016 08:58:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75b7cf51-fa93-4513-b285-4dd8841bf11c</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;PPI is used to connect peripherals, for example TIMER0 and TIMER1 in your case. If you want to wake the CPU on a compare event (for example on TIMER1 which you use to stop TIMER0) you should enable the compare interrupt. Using the timer driver you can do this with &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/group__lib__driver__timer.html?cp=6_0_0_6_7_20_1_12#ga5647281b3b8b0fe1949c161b2c1542ac"&gt;&lt;code&gt;nrf_drv_timer_compare_int_enable()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>