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

How to use BLE UART and normal UART

Hello,

In my project i am using nrf52840 with custom board, here i am using BLE UART to send the data from the mobile to device and sending data from another sensor board device to controller board over RS232 UART communication but i can able to send the data from the mobile to device over BLE UART but i couldn't receive the data sensor board to controller board this is the hurdle i am facing i have used the app_uart_get function also but it didn't work for me, In uart event handler also i have checked there is no any data received from the sensor board. 

1. First thing how can i configure the TX,RX pins for example if i have used TX,RX pins as 6,8 then BLE UART is working fine but if i have changed it to custom board pins(RS232) 3,4 then its not work so please let me know how to configure the pins.??

2. is it possible to use two UARTs.??

thank you. 

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;
    NRF_LOG_INFO("I AM IN UART_EVENT_HANDLER");
    NRF_LOG_FLUSH();
    NRF_LOG_INFO("data_array:%d",data_array);
    NRF_LOG_FLUSH();
    switch (p_event->evt_type)
    {
        case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&data_array[index]));
            NRF_LOG_INFO("s:%d",data_array);
            NRF_LOG_FLUSH();
            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);
            NRF_LOG_INFO("Communication error");
             NRF_LOG_FLUSH();
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_code);
            NRF_LOG_INFO("FIFO error");
             NRF_LOG_FLUSH();
            break;

        default:
            NRF_LOG_INFO(" defualt break");
            break;
    }

   
    data_init(data_array);
 //   memset(data_array,0,20);
}

Parents
  • Hi,

    1. First thing how can i configure the TX,RX pins for example if i have used TX,RX pins as 6,8 then BLE UART is working fine but if i have changed it to custom board pins(RS232) 3,4 then its not work so please let me know how to configure the pins.??

    The pins are set in the app_uart_comm_params_t struct, passed to APP_UART_FIFO_INIT() macro during initialization. What is not working? Have you checked if any data is input/ouput on the pins using a logic analyzer?

    2. is it possible to use two UARTs.??

    nRF52840 have two UARTE instances, but only one can be used with app_uart library. To utilize both UARTE instances, you need to use the UART driver or libUARTE for one or both instances. See for instance this example.

    Best regards,
    Jørgen

  • Hello Jorgen,

    first of all thanks for your reply, 

    The pins are set in the app_uart_comm_params_t struct, passed to APP_UART_FIFO_INIT() macro during initialization. What is not working? Have you checked if any data is input/ouput on the pins using a logic analyzer?

    As i said before i need to work on two UARTs like i need to send data from the mobile APP to device as well as another sensor board to device since i am using one UART may when i try to send data from the sensor board to MCU board BLE is disconnected but i got your point that i need to use UART and UARTE as well.

    nRF52840 have two UARTE instances, but only one can be used with app_uart library. To utilize both UARTE instances, you need to use the UART driver or libUARTE for one or both instances. See for instance this example.

    Best regards,

    Yeah, i have gone through the UART driver and i got that we can  use one is legacy UART and another Easy DMA UART so to configure it they have mentioned in the guide but i need to use it in the non blocking mode because i need to send the commands as well as data from the mobile APP and sensor board to MCU continuously but for implementation point of view how can quick start like after configuration creating UART handler is a big task  i don't have idea on this so if you have any reference or idea on this please help me to resolve.

    thank you. 

Reply
  • Hello Jorgen,

    first of all thanks for your reply, 

    The pins are set in the app_uart_comm_params_t struct, passed to APP_UART_FIFO_INIT() macro during initialization. What is not working? Have you checked if any data is input/ouput on the pins using a logic analyzer?

    As i said before i need to work on two UARTs like i need to send data from the mobile APP to device as well as another sensor board to device since i am using one UART may when i try to send data from the sensor board to MCU board BLE is disconnected but i got your point that i need to use UART and UARTE as well.

    nRF52840 have two UARTE instances, but only one can be used with app_uart library. To utilize both UARTE instances, you need to use the UART driver or libUARTE for one or both instances. See for instance this example.

    Best regards,

    Yeah, i have gone through the UART driver and i got that we can  use one is legacy UART and another Easy DMA UART so to configure it they have mentioned in the guide but i need to use it in the non blocking mode because i need to send the commands as well as data from the mobile APP and sensor board to MCU continuously but for implementation point of view how can quick start like after configuration creating UART handler is a big task  i don't have idea on this so if you have any reference or idea on this please help me to resolve.

    thank you. 

Children
No Data
Related