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

nrf UART app receive value sent from uart app

Hi, I am using the nrf uart app to communicate with a smart phone and the NRF52. I am trying to detect whenever it is sent a value between 0 and 60 from the phone, and save it to an int. I know that I get a callback from the function nus_data_handler whenever something is received on the nrf, but I dont really know how to convert that data to type int.

(I am using the smart phone app NRF UART)

-Erblin

Parents
  • 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') || (index >= (BLE_NUS_MAX_DATA_LEN)))
            {
    						
                err_code = ble_nus_string_send(&m_nus, data_array, index);
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
               ......
    

    I see that this function runs through the array of characters, till it gets a new line \n or is at maximum data length. How am i able to check if this array of characters contains a number between 0 and 60, and then save it to a type int?

Reply
  • 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') || (index >= (BLE_NUS_MAX_DATA_LEN)))
            {
    						
                err_code = ble_nus_string_send(&m_nus, data_array, index);
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
               ......
    

    I see that this function runs through the array of characters, till it gets a new line \n or is at maximum data length. How am i able to check if this array of characters contains a number between 0 and 60, and then save it to a type int?

Children
No Data
Related