<?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>Power save - UART disable</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/85054/power-save---uart-disable</link><description>nrf52833, custom application based BLE Central Uart Project. 
 s140_nrf52_7.2.0 
 
 Our average Power use in the application is 1.5mAmps. What is the proper way to manage the power 
 to the UART entering power save(idle) mode? And to restart the UART</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 Mar 2022 12:40:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/85054/power-save---uart-disable" /><item><title>RE: Power save - UART disable</title><link>https://devzone.nordicsemi.com/thread/355812?ContentTypeID=1</link><pubDate>Wed, 02 Mar 2022 12:40:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2414c824-79f3-4cec-b642-1b5caef70119</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi Dan,&lt;/p&gt;
&lt;p&gt;Is the&amp;nbsp;idle_state_handle() called in the main loop as in our examples? If so, then this is problematic as &lt;strong&gt;any&lt;/strong&gt; interrupt would cause the program to wake-up and re-init the UART + endless calls to cble_uart_deinit from the main loop.&lt;/p&gt;
&lt;p&gt;If you&amp;#39;re using the Softdevice then interrupts happen quite often in the program. This will cause multiple init and de-init routines to be scheduled and I guess the MCU isn&amp;#39;t able to keep up.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Instead, try only initializing and de-initialize the UART peripheral before and after you&amp;#39;re sending/receiving data.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;regards&lt;br /&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Power save - UART disable</title><link>https://devzone.nordicsemi.com/thread/355407?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 02:44:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82b06cd2-29bf-48c1-837f-7b35d111733c</guid><dc:creator>DanPhelan</dc:creator><description>&lt;p&gt;Hi Jared,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am still having a hard time getting the UART to restart after&amp;nbsp;closing for sleep mode.&amp;nbsp; The UART works fine on initial power up nd only fails when it is closed during Idle periods.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;1.&amp;nbsp; To close the uart,&amp;nbsp;&amp;nbsp;idle_state_handle(void), calls the cble_uart_deinit() before power management is run.&lt;/p&gt;
&lt;p&gt;cble_uart_deinit(void)&lt;/p&gt;
&lt;p&gt;If I dont call this, it works.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Function for handling the idle state (main loop).
 *
 * @details Handles any pending log operations, then sleeps until the next event occurs.
 */
static void idle_state_handle(void)
{
    if (NRF_LOG_PROCESS() == false)
    {
        cble_uart_deinit();
      
        // watchdog &amp;amp; failsafe state management
        nrf_pwr_mgmt_run();
    
        cble_uart_init();
        //NRF_LOG_INFO(&amp;quot;RE-init UART&amp;quot;);
    }
}
/*******************************************************************************
*  Function Name  : uint32_t cble_uart_close(void)
*  Description    : de-init and power down the uart 
*  Author         : Dan P
*  Date           : 02.23.2022
*  Input          : None
*  Return         : None
*******************************************************************************/
uint32_t cble_uart_close(void)
{
    nrf_drv_uart_tx_abort(&amp;amp;cble_uart_inst);//cble_uart_inst);app_uart_inst
    nrf_drv_uart_rx_abort(&amp;amp;cble_uart_inst);//cble_uart_inst);app_uart_inst
    nrf_drv_uart_uninit(&amp;amp;cble_uart_inst);//cble_uart_inst);app_uart_inst
    s_initialized = false;
    return NRF_SUCCESS;
}

/*******************************************************************************
*  Function Name  : void cble_uart_deinit(void)
*  Description    : de-init and power down the uart 
*  Author         : Dan P
*  Date           : 02.23.2022
*  Input          : None
*  Return         : None
*******************************************************************************/
void cble_uart_init(void)
{
    ret_code_t err_code;
    if (!s_initialized){

    app_uart_comm_params_t const comm_params =
    {
        .rx_pin_no    = RX_PIN_NUMBER,
        .tx_pin_no    = TX_PIN_NUMBER,
        .rts_pin_no   = RTS_PIN_NUMBER,  // assign as a gpio for use in low power control, assign to un-used pins.
        .cts_pin_no   = CTS_PIN_NUMBER,  // assign as a gpio for use in low power control, assign to un-used pins.
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
        .baud_rate    = UART_BAUDRATE_BAUDRATE_Baud115200
    };
//#if 0
//    APP_UART_FIFO_INIT(&amp;amp;comm_params,
//                       UART_RX_BUF_SIZE,
//                       UART_TX_BUF_SIZE,
//                       uart_event_handler,
//                       APP_IRQ_PRIORITY_LOWEST,
//                       err_code);
//
//    APP_ERROR_CHECK(err_code);
//#endif 
                                                                                                                     \
    buffers.rx_buf      = rx_buf;                                                              \
    buffers.rx_buf_size = sizeof (rx_buf);                                                     \
    buffers.tx_buf      = tx_buf;                                                              \
    buffers.tx_buf_size = sizeof (tx_buf);                                                     \
    err_code = app_uart_init(&amp;amp;comm_params, &amp;amp;buffers, uart_event_handle, APP_IRQ_PRIORITY_LOWEST);                  \
    APP_ERROR_CHECK(err_code);
    
//    NRF_UARTE0-&amp;gt;TASKS_STARTRX=1;
//    NRF_UARTE0-&amp;gt;TASKS_STARTTX=1;
//    NRF_UARTE0-&amp;gt;ENABLE=1;
    nrf_uarte_enable(NRF_UARTE1);
    NRF_UARTE1-&amp;gt;TASKS_STARTRX=1;
    NRF_UARTE1-&amp;gt;TASKS_STARTTX=1;
    NRF_UARTE1-&amp;gt;ENABLE=1;
    nrf_uarte_enable(NRF_UARTE1);
     nrf_drv_uart_rx_enable(&amp;amp;cble_uart_inst);
    s_initialized = true;


    }
}

/*******************************************************************************
*  Function Name  : void cble_uart_deinit(void)
*  Description    : de-init and power down the uart 
*  Author         : Dan P
*  Date           : 02.23.2022
*  Input          : None
*  Return         : None
*******************************************************************************/
void cble_uart_deinit(void)
{
    if (s_initialized)
    {
  //  NRF_UARTE0-&amp;gt;TASKS_STOPRX=1;
  //    NRF_UARTE0-&amp;gt;TASKS_STOPTX=1;
  //   NRF_UARTE0-&amp;gt;ENABLE=0;
     
    NRF_UARTE1-&amp;gt;TASKS_STOPRX=1;
    NRF_UARTE1-&amp;gt;TASKS_STOPTX=1;
    NRF_UARTE1-&amp;gt;ENABLE=0;
      
      cble_uart_flush();
      app_uart_flush();
      cble_uart_close();
      
 //UARTE0
//       *(volatile uint32_t *)0x40002FFC = 0;
//       *(volatile uint32_t *)0x40002FFC;
//       *(volatile uint32_t *)0x40002FFC = 1;

//UARTE1
    *(volatile uint32_t *)0x40028FFC = 0; // Power down UARTE1
    *(volatile uint32_t *)0x40028FFC;     //
    *(volatile uint32_t *)0x40028FFC = 1; // Power on UARTE1 so it is ready for next time

        s_initialized = false;
    }

}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Power save - UART disable</title><link>https://devzone.nordicsemi.com/thread/355036?ContentTypeID=1</link><pubDate>Fri, 25 Feb 2022 13:12:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c8641de-d804-4236-ae9e-493561b4cdc6</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi Dan,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Are you passing the correct uart event handler to the init function? In the #ifdef block you pass&amp;nbsp;&lt;span&gt;uart_event_handleR while to the init function you pass&amp;nbsp;uart_event_handlE&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;You should wait for the peripheral to produce the TXSTOPPED event before proceeding after triggering the event.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;&lt;span&gt;Does&amp;nbsp;cble_uart_close call&amp;nbsp;&lt;/span&gt;&lt;/span&gt;app_uart_close()?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Power save - UART disable</title><link>https://devzone.nordicsemi.com/thread/354711?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 04:10:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32ebe5e7-0e55-4d73-82de-6dd01955347c</guid><dc:creator>DanPhelan</dc:creator><description>&lt;p&gt;Hi Jared,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thanks for the input.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am still having trouble getting the UART to re-initialize.&amp;nbsp; It does not restart?&amp;nbsp; Below is the code I am using to disable and restart the uart.&lt;/p&gt;
&lt;p&gt;After a restart, the PUT_Tx quickly fills and crashes.&amp;nbsp; It looks like the UART is not delivering any data and emptying the Tx fifo?&lt;/p&gt;
&lt;p&gt;/*******************************************************************************&lt;br /&gt;* Function Name : void cble_uart_deinit(void)&lt;br /&gt;* Description : de-init and power down the uart &lt;br /&gt;* Author : Dan P&lt;br /&gt;* Date : 02.23.2022&lt;br /&gt;* Input : None&lt;br /&gt;* Return : None&lt;br /&gt;*******************************************************************************/&lt;br /&gt;void cble_uart_init(void)&lt;br /&gt;{&lt;br /&gt; ret_code_t err_code;&lt;br /&gt; if (!s_initialized){&lt;/p&gt;
&lt;p&gt;app_uart_comm_params_t const comm_params =&lt;br /&gt; {&lt;br /&gt; .rx_pin_no = RX_PIN_NUMBER,&lt;br /&gt; .tx_pin_no = TX_PIN_NUMBER,&lt;br /&gt; .rts_pin_no = RTS_PIN_NUMBER, // assign as a gpio for use in low power control, assign to un-used pins.&lt;br /&gt; .cts_pin_no = CTS_PIN_NUMBER, // assign as a gpio for use in low power control, assign to un-used pins.&lt;br /&gt; .flow_control = APP_UART_FLOW_CONTROL_DISABLED,&lt;br /&gt; .use_parity = false,&lt;br /&gt; .baud_rate = UART_BAUDRATE_BAUDRATE_Baud115200&lt;br /&gt; };&lt;br /&gt;#if 0&lt;br /&gt; APP_UART_FIFO_INIT(&amp;amp;comm_params,&lt;br /&gt; UART_RX_BUF_SIZE,&lt;br /&gt; UART_TX_BUF_SIZE,&lt;br /&gt; uart_event_handler,&lt;br /&gt; APP_IRQ_PRIORITY_LOWEST,&lt;br /&gt; err_code);&lt;/p&gt;
&lt;p&gt;APP_ERROR_CHECK(err_code);&lt;br /&gt;#endif &lt;br /&gt; \&lt;br /&gt; buffers.rx_buf = rx_buf; \&lt;br /&gt; buffers.rx_buf_size = sizeof (rx_buf); \&lt;br /&gt; buffers.tx_buf = tx_buf; \&lt;br /&gt; buffers.tx_buf_size = sizeof (tx_buf); \&lt;br /&gt; err_code = app_uart_init(&amp;amp;comm_params, &amp;amp;buffers, uart_event_handle, APP_IRQ_PRIORITY_LOWEST); \&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt; &lt;br /&gt; s_initialized = true;&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;/*******************************************************************************&lt;br /&gt;* Function Name : void cble_uart_deinit(void)&lt;br /&gt;* Description : de-init and power down the uart &lt;br /&gt;* Author : Dan P&lt;br /&gt;* Date : 02.23.2022&lt;br /&gt;* Input : None&lt;br /&gt;* Return : None&lt;br /&gt;*******************************************************************************/&lt;br /&gt;void cble_uart_deinit(void)&lt;br /&gt;{&lt;br /&gt; if (s_initialized)&lt;br /&gt; {&lt;br /&gt; NRF_UARTE1-&amp;gt;TASKS_STOPRX=1;&lt;br /&gt; NRF_UARTE1-&amp;gt;TASKS_STOPTX=1;&lt;br /&gt; NRF_UARTE1-&amp;gt;ENABLE=0;&lt;br /&gt; &lt;br /&gt; cble_uart_flush();&lt;br /&gt; app_uart_flush();&lt;br /&gt; cble_uart_close();&lt;br /&gt; &lt;br /&gt; *(volatile uint32_t *)0x40028FFC = 0; // Power down UARTE1&lt;br /&gt; *(volatile uint32_t *)0x40028FFC; //&lt;br /&gt; *(volatile uint32_t *)0x40028FFC = 1; // Power on UARTE1 so it is ready for next time&lt;/p&gt;
&lt;p&gt;s_initialized = false;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Dan&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Power save - UART disable</title><link>https://devzone.nordicsemi.com/thread/354631?ContentTypeID=1</link><pubDate>Wed, 23 Feb 2022 14:48:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8b27e26-eff3-48e0-a4c5-d918598d490b</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;If you&amp;#39;re doing it that way then I would move the un initializing and re- initializing of the peripheral right outside of where nrf_pwr_mgtmt_run() is called, something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrf_drv_uart_t tmp = NRF_DRV_UART_INSTANCE(0);
nrf_drv_uart_uninit(&amp;amp;tmp);

nrf_pwr_mgmt_run();

uart_init();&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You might have to call the STOP task before un-initializing the module.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>