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

Concurrent Central/Peripheral UART

Hi,

I'am actually trying to develop a BLE based remote, with NRF52832, S132.

This remote must be configured by a smartphone (the remote act as peripheral) and be able to control one equipement (and act as Central).

As i only need to use uart on each side, i've started mixing demo programs ble_app_uart_c.c (central) and ble_app_uart.c (peripheral) without success.

As peripheral: The board advertise correctly, i can connect to it on my smartphone with the app nRF UART v2.0 but the NUS_data_handler seems not receive any message.

As central: When the board try to connect with another board flashed with ble_app_uart.c, the conn_handle indicate 65532 and the role is BLE_GAP_ROLE_INVALID instead of BLE_GAP_ROLE_CENTRAL.

RAM configuration: start: 0x20003DB0, size: 0xC250

My program: ble_app_uart_c.zip

Thanks a lot for your advice to correct these errors !!!

  • Hi Jorgen,

    Sorry for late reply, I flashed the correct softdevice only but still it is not working.

  •  */
    static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
    {	
    	  uint16_t conn_handle_nb;
    	  uint16_t role;
    	  
    	  ble_conn_state_on_ble_evt(p_ble_evt);
    	
    	  conn_handle_nb = p_ble_evt->evt.gap_evt.conn_handle;
        role        = ble_conn_state_role(conn_handle_nb);
    	
    	  SEGGER_RTT_printf(0,"EVT conn handle num %u!!\r\n", conn_handle_nb);
    	
    	 if(role != BLE_GAP_ROLE_INVALID)
    		{
    			    if (role == BLE_GAP_ROLE_PERIPH) //MAX
    					{
    							SEGGER_RTT_printf(0,"PERIPH\r\n");
    							on_ble_peripheral_evt(p_ble_evt);
    							ble_advertising_on_ble_evt(p_ble_evt);
    							ble_conn_params_on_ble_evt(p_ble_evt);
    						//dispatch to peripheral application
    						ble_nus_on_ble_evt(&m_nus, p_ble_evt);
    					}
    					
    				else	if (role == BLE_GAP_ROLE_CENTRAL)
    					{
    							SEGGER_RTT_printf(0,"CENTRAL\r\n");
    							on_ble_central_evt(p_ble_evt);
    							bsp_btn_ble_on_ble_evt(p_ble_evt);
    							ble_db_discovery_on_ble_evt(&m_ble_db_discovery, p_ble_evt);
    							ble_nus_c_on_ble_evt(&m_ble_nus_c,p_ble_evt);
    					
    					// If the peer disconnected, we update the connection handles last.
            if (p_ble_evt->header.evt_id == BLE_GAP_EVT_DISCONNECTED)
            {
                on_ble_central_evt(p_ble_evt);
            }
    		  }
    					
    					
    		else 
    		{
    					SEGGER_RTT_printf(0,"INVALID\r\n");
    		}
    
    }
    		
    }
    		
    

    Is this the change you suggested to Maxim?

  • Try debugging the application. Most likely some error code is putting the application into the error handler.

  • Hi Jorgen,

    Now it is advertising and scanning.

    But in peripheral it is able to connect to the central but not able to receive or send the data.

    In central it is able to scan but when it is connected  to the peripheral LED 2(which is used to mention that it is connected)  is not glowing and instead the advertising LED 3 is turned off and i am not able to receive or send the data.

    static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
    {
        uint16_t conn_handle;
        uint16_t role;
    
        ble_conn_state_on_ble_evt(p_ble_evt);
        pm_on_ble_evt(p_ble_evt);
    
        // The connection handle should really be retrievable for any event type.
        conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        role        = ble_conn_state_role(conn_handle);
    
        // Based on the role this device plays in the connection, dispatch to the right applications.
        if (role == BLE_GAP_ROLE_PERIPH)
        {
            // Manages peripheral LEDs.
    			  printf("peripheral\r\n");
            on_ble_peripheral_evt(p_ble_evt);
    
            ble_advertising_on_ble_evt(p_ble_evt);
            ble_conn_params_on_ble_evt(p_ble_evt);
    
            // Dispatch to peripheral applications.
            ble_nus_on_ble_evt (&m_nus, p_ble_evt);
           
        }
        else if ((role == BLE_GAP_ROLE_CENTRAL) || (p_ble_evt->header.evt_id == BLE_GAP_EVT_ADV_REPORT))
        {
    		      printf("in central\r\n");    
             /** on_ble_central_evt will update the connection handles, so we want to execute it
             * after dispatching to the central applications upon disconnection. */
            if (p_ble_evt->header.evt_id != BLE_GAP_EVT_DISCONNECTED)
            {
                on_ble_central_evt(p_ble_evt);
            }
    		  	//on_ble_central_evt(p_ble_evt);
    				//bsp_btn_ble_on_ble_evt(p_ble_evt);
    				ble_db_discovery_on_ble_evt(&m_ble_db_discovery, p_ble_evt);
            ble_nus_c_on_ble_evt(&m_ble_nus_c, p_ble_evt);
          
            // If the peer disconnected, we update the connection handles last.
            if (p_ble_evt->header.evt_id == BLE_GAP_EVT_DISCONNECTED)
            {
                on_ble_central_evt(p_ble_evt);
    				
            }
    		
    				
        }
    }

    should i need to make any changes in the dispatcher function mentioned above?

  • Please post your issue in a new question, you are moving outside the topic of this question.

Related