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 merge libuarte with app_ble_uart example for use two uart

Hello,

In my project i want two use two UART as off now i am using app_ble_uart example since by default 6,8 is tx and rx pins respectively. so overall application of my project is i need to receive the commands from the mobile application to device and from another external sensor board i need to receive the data  continuously to device from RS232 pin number of 3,4 TX ,RX respectively so now i can able to use one UART with 6,8 pins for sending commands from the mobile application to device but if i change the pin number to 3,4 in same uart_init it will disconnected from the mobile app so i have got information from the devzone like using libuarte example and i don't know to merge with the app_ble_uart example so please help me to resolve this problem or if any reference on this please share me.

thank you.

Parents
  • Hello,

    While you can use the libuarte library, it is quite complex and resource demanding. I suggest that you at least consider using the nrf_drv_uart driver (which app_uart in the ble_app_uart example uses).

    If you look in the ble_app_uart example, and you go follow the implementation on how the uart is already set up in this example, you will find:

    main.c uart_init() -> APP_UART_FIFO_INIT() -> app_uart_init() -> nrf_drv_uart_init()

    nrf_drv_uart_init() is the function call that takes an uart instance. By default, the app_uart_fifo.c uses APP_UART_DRIVER_INSTANCE (which is set to 0 in sdk_config.h), so if you want to set up another UART, you can use the UART instance 1, and call nrf_drv_uart_init() using that.

    Whether you add a new function that looks like app_uart_init() inside app_uart_fifo.c or if you use nrf_drv_uart_init() from your main.c file is up to you. 

    Best regards,

    Edvin

  • Hello Edvin,

    thanks for reply, i gone through the uart_init() present in the app_ble_uart  example and in app_uart_fifo.c  i have duplicate the app_uart_init() and how can i pass the APP_UART_DRIVER_INSTANCE 1 to this i am get confused that  how it will take the UARTE to the app_uart_init() . i hope you get my problem that i have explained from the top. in uart_init() i changed the TX,RX pins to P1.3,P1.4 so if i send the data(commands) from my customized APP to the device and its receiving properly and at the same time if i am trying to send the data from the MAX232 which is connected to the  same P1.3, P1.4 (TX,RX) of MCU so that's why its going to break condition in the uart_handler so for this can we use two UART's.

    if yes, please guide me that in app_uart_fifo.c how can add another app_uart_init() .??

    thank you.

  • Hello Edvin,

    thanks for your reply,

    I only thought you wanted to pass the data from BLE out on a physical UART as well, since the headline for this ticket says "two uarts". 

    Yes, i want to send the command data from the MOBILE APP to MCU over BLE and i want to send the data from the sensor board to MCU over MAX232 with HW_UART but

    1: the physical uart has been written to, and disable the ble_nus_data_send() from this callback in order to not forward this data directly over BLE.

    No, want to receive the data from the sensor board to MCU over MAX 232 with HW_UART here i need to send the data to BLE as well i couldn't disable the function ble_nus_data_send() here . the device should receive the data and send to MOBILE_APP over BLE.

    The callback where the nRF receives data over the BLE service, and disable that the nRF will send this data over the physical UART.

    Ah, like when device receives the data from sensor board it will send to nrf over BLE  and then again APP will send this data to HW_UART. this is what you ment.??

    thank you.

  • Hello,

    By default, whenever the physical UART receives any data (one byte), the function uart_event_handle() in main.c is triggered. What this does is that it checks whether:

    1: The buffer is full (BLE_NUS_MAX_DATA_LEN) bytes, or:

    2: the last received byte was either '\r' or '\n' (linefeed)

    If one of the two is true, then it will send that data over BLE using ble_nus_data_send(), and reset the buffer.

    You can keep this functionality if it suits your case. If it doesn't use \r or \n, perhaps it uses some other value to indicate that the message is done. 

    Then you have the nus_data_handler(), also in main.c, which will trigger every time the device receives a message over BLE, containing the data. This will by default take whatever payload data that is received, and send it to the physical UART's TX. I assume you don't want to send this data to the sensor directly, so in that case, you may want to comment out this part:

            for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
            {
                do
                {
                    err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
                    if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                    {
                        NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                        APP_ERROR_CHECK(err_code);
                    }
                } while (err_code == NRF_ERROR_BUSY);
            }

    But that depends on what you want to do. 

  • Hello Edvin,

    . I assume you don't want to send this data to the sensor directly, so in that case, you may want to comment out this part:

    Yes, i have  already done this and my  nus_data_handler()  look like this,

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {    uint8_t result[120]={};
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            uint32_t err_code;
           
            uint8_t *PRCS;
    
            NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
            NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
    
            for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
            {
             result[i]=p_evt->params.rx_data.p_data[i];
          
            //NRF_LOG_INFO("result:%s",result);
            //NRF_LOG_FLUSH();
            }
    
    
            for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
            {
               FINAL[i]=p_evt->params.rx_data.p_data[i];
            
            //NRF_LOG_INFO("FINAL:%s",FINAL);
            //NRF_LOG_FLUSH();
            
            }
            
           
            if((result[0]=='P') && (result[1]=='R') && (result[2]=='O'))
            {
                internal_process(result);
               
            }
    
             command_init(result);
            
            
          
    
    
        }
    
    }

    somehow it's ok but while receiving the data from the MAX232 i couldn't reduce the noise of motor like its stuck while receiving and it back to work within a nano sec.

    i don't know how to reduce it .

    thank you.

  • Remember that I don't know anything about any motor. Is the MAX232 the motor?

    sagarnayakm said:

    couldn't reduce the noise of motor like its stuck while receiving and it back to work within a nano sec.

    What does this mean? Is the motor sending data?

  • Hello,

    What does this mean? Is the motor sending data?

    No, actually over a BLE we are sending command to control the servo motor that's what i am trying to explain. It's ok  i will try to reduce the noise and i will update you.

     thank you.

Reply Children
No Data
Related