nRF_SDK_17.1.0 s140 pca10056 BLE_UART

Hello all,

I am trying to develop an application where the user will input some specific commands i.e hex value of 0x01 via a mobile application and then via bluetooth this command will be passed to the computer using UART.

I have compiled the ble app uart on my nrf52840 but i am struggling to modify the code for my application.

Could someone help me with this ? 

Thanks

Kleanthis

Parents
  • Thank you now when i send the command 0x01 via nrf connect from my phone i can see on termite that the device is activated. Now regarding the second part of my previous question. I would like when the user inputs that command (0x01 via BLE) to transfer it via UART to my computer. I have studied the app_uart function but i could not find any information on how i can transfer that command to UART.

    Could it be possible to help me with that ? I am guessing i shall introduce the m_device_state inside that function and when is set to 1 then it will transfer the data through the data_array ? 

    /**@brief   Function for handling app_uart events.
     *
     * @details This function will receive a single character from the app_uart module and append it to
     *          a string. The string will be be sent over BLE when the last character received was a
     *          'new line' '\n' (hex 0x0A) or if the string has reached the maximum data length.
     */
    /**@snippet [Handling the data received over UART] */
    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;
    
        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;
        }
    }

  • kleanthise said:
    Could it be possible to help me with that ? I am guessing i shall introduce the m_device_state inside that function and when is set to 1 then it will transfer the data through the data_array ? 

    Yes, but you are looking in the wrong function it seems - the uart_event_handle is used to handle the UART events, which primarily is used to handle the messages received / incoming over UART by forwarding them over the BLE link. You can see that in the uart_event_handle function it only really handles data in the APP_UART_DATA_READY event, which is generated whenever data is received over UART.

    You should instead add this in the nus_evt_handler, in the handling of the BLE_NUS_EVT_RX_DATA event (which is generated whenever data is received over BLE).
    You are on the right path - the approach you describe is correct for the functionality you are after - but you will need to add the app_uart_put function at the right place to implement it.

    Best regards,
    Karl

Reply
  • kleanthise said:
    Could it be possible to help me with that ? I am guessing i shall introduce the m_device_state inside that function and when is set to 1 then it will transfer the data through the data_array ? 

    Yes, but you are looking in the wrong function it seems - the uart_event_handle is used to handle the UART events, which primarily is used to handle the messages received / incoming over UART by forwarding them over the BLE link. You can see that in the uart_event_handle function it only really handles data in the APP_UART_DATA_READY event, which is generated whenever data is received over UART.

    You should instead add this in the nus_evt_handler, in the handling of the BLE_NUS_EVT_RX_DATA event (which is generated whenever data is received over BLE).
    You are on the right path - the approach you describe is correct for the functionality you are after - but you will need to add the app_uart_put function at the right place to implement it.

    Best regards,
    Karl

Children
No Data
Related