This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Problem: Enable Disable UART, ADC peripherals?

Hello to all,

I am using nRF52840 with SES SDK15.0 version. My device is goes into sleep mode after sending data to server. But when woke up device for first reading data successfully send and it will goes into sleep mode. After few minute it wakeup that time not able to ON proper ADC and UART functionality. Also i am struggling for debug because not showing any error it shows only unknown fuction at 0x000978 like this. 

Please help me how i can fix this issue, here is my bellow function for sleep mode:

void stop_adc()
{

    nrf_drv_timer_disable(&m_timer);
    nrf_drv_timer_uninit(&m_timer);
    nrf_drv_ppi_channel_disable(m_ppi_channel);
    nrf_drv_ppi_uninit();
//    NRF_SAADC->TASKS_STOP = 1;
    nrf_drv_saadc_uninit();
}

void sleep_mode_enter()
{
  uint32_t err_code;
  NRF_LOG_INFO("Sleep mode Enter");
  stop_adc();
  err_code = app_uart_close();
  APP_ERROR_CHECK(err_code);                          
//  NRF_LOG_INFO("UART close: %d", err_code);
//  stop_BLE();
}

void startMeasuring_reading()
{
   NRF_LOG_INFO("Measurement started");
   int dataCounter=0;
   int flag = 0;
   int flag2 = -10;
   int flag3 = 0;
   int NextChannelCounter=0;
   int notificationConter = 0;
   int connectionflag = 0;
   uint8_t channel_number = -1;
   bool START_SENDING = false;
   uart_init();
   saadc_sampling_event_init();
   saadc_sampling_event_enable();
}

Also one another thing is i am trying to HIGH and LOW GPIOP0.23 and P0.29 but not able to HIGH this pin why it so. Is it any configuration for access GPIO of nRF52840 DK.

nrf_gpio_cfg_output(23);

nrf_gpio_pin_set(23); // High pin

Is the above code is correct please suggest me proper way or provide program snippet for the above both issues.

Thanks in advanced...

  • 1)

    "Also i am struggling for debug because not showing any error it shows only unknown fuction at 0x000978 like this." 
    - like what?

    We need the definitions for:

    • stop_BLE();
    • uart_init();
    • saadc_sampling_event_init();
    • saadc_sampling_event_enable();

    2) 

    nrf_gpio_cfg_output(23);

    nrf_gpio_pin_set(23); 

    This should set p0.23 to logic high. 

    What is the state of the GPIO registers after you've executed the two functions above?

  • 1) stop_BLE(); means disconnect ble connection and stop advertising this call before enter sleep mode

    void stop_BLE()
    {
      uint32_t err_code;
      stop_adv = true;
        err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
        APP_ERROR_CHECK(err_code);
    }
    
    static void uart_init(void)
    {
        uint32_t                     err_code;
        app_uart_comm_params_t const comm_params =
        {
            .rx_pin_no    = RX_PIN_NUMBER,//RX_PIN_NUMBER,
            .tx_pin_no    = TX_PIN_NUMBER,//TX_PIN_NUMBER,
            .rts_pin_no   = RTS_PIN_NUMBER,
            .cts_pin_no   = CTS_PIN_NUMBER,
            .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
            .use_parity   = false,
    #if defined (UART_PRESENT)
            .baud_rate    = NRF_UART_BAUDRATE_115200
    #else
            .baud_rate    = NRF_UARTE_BAUDRATE_115200
    #endif
        };
    
        APP_UART_FIFO_INIT(&comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_event_handle,
                           APP_IRQ_PRIORITY_LOWEST,
                           err_code);
        APP_ERROR_CHECK(err_code);
    }
    
    void saadc_sampling_event_init(void)
    {
        ret_code_t err_code;
        err_code = nrf_drv_ppi_init();
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_timer_config_t timer_config = NRF_DRV_TIMER_DEFAULT_CONFIG;
        timer_config.frequency = NRF_TIMER_FREQ_31250Hz;
        err_code = nrf_drv_timer_init(&m_timer, &timer_config, timer_handler);
        APP_ERROR_CHECK(err_code);
    
        /* setup m_timer for compare event */
        uint32_t ticks = nrf_drv_timer_us_to_ticks(&m_timer,SAADC_SAMPLE_RATE);
        nrf_drv_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);
        nrf_drv_timer_enable(&m_timer);
    
        uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&m_timer, NRF_TIMER_CC_CHANNEL0);
        uint32_t saadc_sample_event_addr = nrf_drv_saadc_sample_task_get();
    
        /* setup ppi channel so that timer compare event is triggering sample task in SAADC */
        err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_ppi_channel_assign(m_ppi_channel, timer_compare_event_addr, saadc_sample_event_addr);
        APP_ERROR_CHECK(err_code);
    }
    
    void saadc_sampling_event_enable(void) {
    	ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
    	APP_ERROR_CHECK(err_code);
    }
    

    Basically what i want to do startMeasuring_reading(); is a fun which is call every periodic interval as per requirements. When first callback come WIFi module successfully send sensor reading but when call it again second time got error in SES IDE like unknown fuction at 0x000978. Will you please provide proper way for turn off saadc , uart in sleep mode means system ON mode. It will again turn ON once  startMeasuring_reading(); call. 

    Is any issue when i call sleep_mode_enter(); in uart_event_hnandler(); callback function because when i comment this not show unknown function but program not work proper.

    2) 

    What is the state of the GPIO registers after you've executed the two functions above?

    what you are manning how i check state of GPIO registers?

    Another thing is when i use GPIO15 pin so this pin is able to set logic high but problem for p0.23. i am using PCA10056 board file.

    Thanks for reply...

    1. You won't be able to put the MCU to sleep when the debugger is connected. 

      "When first callback come WIFi module successfully send sensor reading but when call it again second time got error in SES IDE like 
      unknown fuction at 0x000978." 
      -What callback are you referring to?
    2. In a debug session in SES: View -> Registers -> Register1 -> Groups -> Turn off CPU groups, and turn on the P0 group. 
  • 1. The callback is uart_event_handle(..) When i comment uart close function then it worked but problem with again uart_init();

    2. Here is bellow screen shot of GPIO state:

    I have tried like this

    #define WIFI_PIN NRF_GPIO_PIN_MAP(0,23)
    #define SENSOR_PIN NRF_GPIO_PIN_MAP(0,29) 

    SENSOR_PIN  is working but only problem with  WIFI_PIN  i not getting high tested with multi-meter.

    Why it problem with p0.23 pin in segger when i read this resister the IDE show 1 value but not getting on multi-meter. 

    Please help me asap.

    Thanks...

  • 1.  "Is any issue when i call sleep_mode_enter(); in uart_event_hnandler(); callback function because when i comment this not show unknown function but program not work proper." 
    - You should never go to sleep in a callback, wait for the uart event handler to return to main and enter sleep from there.

    2. p0.23 is used with the flash chip on the DK. You need to use another gpio. See fig 1 in Connector interface

Related