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);
}

  • If you build the application in "debug" configuration (or add the DEBUG/DEBUG_NRF symbols to the projects preprocessor symbols), the log should output the error code and the location where the error occurred on the long, instead of just "Fatal error".

    My guess is that the application pass the error source from the communication error to the error handler, and the GPIO you set as RX pin is in the wrong state when you enable the UART RX, generating a FRAMING/BREAK error:

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

    If you have this APP_ERROR_CHECK in your application, please try to comment this out and see if it resolves the fatal error.

  • Hello,

    Jorgen thanks for your reply,

    As you said i have commented the APP_ERROR_HANDLER and now no error  i can able to receive the data from the MAX232 to MCU over  HW_UART and BLE is connected now i need to send the data over BLE but this works via Virtual UART right. here i observed something like when i send a command data from the MOBILE APP to MCU  to control the motor and its working fine but at the same time if i connect the TX,RX pins of HW_UART physically data send from the sensor board to MCU via MAX232 but there is unwanted noise from the motor while receiving the data from the MAX232 to MCU i mean in the sense motor stops for nano sec and after receiving the data it continuous for motor running this is happening fraction of sec so i can able to here that sound.

    so how can i reduce this and why its happening while receiving the data  from the MAX232 to MCU.??

    Please let me know your feedback .

    thank you.

  • How is the motor powered and controlled? Do you have a scope image of the control signal when you hear the noise?

    If you can post your schematics and layout files, our HW team may be able to review it and see if there is any issues.

Related