This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NRF52840 in sleep how to wakeup

How to wakeup while in sleep state via uart

Parents
  • Hi

    I am using STM32H7 and i connect nrf52840 via uart connection and i tried to sleep ON  & OFF using trigger button in stm32 

    * I sent data in stm32 via UART  1-> to start & 2-> stop

    Is this is write way i am working with i cannot able to understand

    uart_event_handle(app_uart_evt_t * p_event) // in this fun i used this logic 
    {
         if(data_array[0] == '1')
        {
             ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
         }
         else if(data_array[0] == '2')
         {
             sd_ble_gap_adv_stop(m_advertising.adv_handle);
         }
    .....
    }
  • I don't see where you are updating the 'data_array'. That should normally be done inside the uart_event_handle() if you are using the app uart libary. 

    Like this: 

    uart_event_handle(app_uart_evt_t * p_event) // in this fun i used this logic 
    {
        if (p_event->evt_type == APP_UART_DATA_READY)
        {
            UNUSED_VARIABLE(app_uart_get(&data_array[0]));
            
            if(data_array[0] == '1')
            {
                ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
            }
            else if(data_array[0] == '2')
            {
                sd_ble_gap_adv_stop(m_advertising.adv_handle);
            }
        }

Reply
  • I don't see where you are updating the 'data_array'. That should normally be done inside the uart_event_handle() if you are using the app uart libary. 

    Like this: 

    uart_event_handle(app_uart_evt_t * p_event) // in this fun i used this logic 
    {
        if (p_event->evt_type == APP_UART_DATA_READY)
        {
            UNUSED_VARIABLE(app_uart_get(&data_array[0]));
            
            if(data_array[0] == '1')
            {
                ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
            }
            else if(data_array[0] == '2')
            {
                sd_ble_gap_adv_stop(m_advertising.adv_handle);
            }
        }

Children
  • Hi Vidar Berg

    I tried lots of time but i am not able to ON and OFF 

    Receive data via UART data_array[].It get's OFF but not getting ON i don't have Idea

    void uart_event_handle(app_uart_evt_t * p_event)
    {
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t err_code;
    /****************************************************************/
    if(data_array[0] == '1')
    {
         // ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
         ble_advertising_restart_without_whitelist(&m_advertising);

    }
    else if(data_array[0] == '2')
    {
         sleep_mode_enter();
    }
    /****************************************************************/
    switch (p_event->evt_type)
    {
    case APP_UART_DATA_READY:
    UNUSED_VARIABLE(app_uart_get(&data_array[index]));
    index++;
    if ((data_array[index - 1] == '\n') ||
    (data_array[index - 1] == '\r') ||
    (index >= m_ble_nus_max_data_len))
    {
    if (index > 1)
    {
    NRF_LOG_DEBUG("Ready to send data over BLE NUS");
    NRF_LOG_HEXDUMP_DEBUG(data_array, index);

    do
    {
    uint16_t length = (uint16_t)index;
    err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
    if ((err_code != NRF_ERROR_INVALID_STATE) &&
    (err_code != NRF_ERROR_RESOURCES) &&
    (err_code != NRF_ERROR_NOT_FOUND))
    {
    APP_ERROR_CHECK(err_code);
    }
    while (err_code == NRF_ERROR_RESOURCES);
    }

    index = 0;
    }
    break;

    case APP_UART_COMMUNICATION_ERROR:
    APP_ERROR_HANDLER(p_event->data.error_communication);
    break;

    case APP_UART_FIFO_ERROR:
    APP_ERROR_HANDLER(p_event->data.error_code);
    break;

    default:
    break;
    }
    }
Related