cancel
Showing results for 
Search instead for 
Did you mean: 

X-Nucleo-BNRG2A1 BLE Central disconnects right after connection.

NafiurRahman
Associate II

I am trying to use X-Nucleo-BNRG2A1 as a BLE Central Device. My BLE peripheral is based on STM32WB15CC (Which is working fine). On the central code, I am using the central example from CubeIDE. I can scan and see my peripheral. I managed to connect to it. However, as soon as it connects, it disconnects giving me "GATT Procedure completed with error 0x41 0x0806". Here, 0x41 = error code (referring to Failed). And 0x0806 is the connection handle.

I tried to modify the example by adding a primary service discovery inside the connection complete event callback. It fails to discover service. The debug message I get is "aci_gatt_disc_all_primary_services() failed: 0x46". No idea what 0x46 refers to.

FYI, the connection code (in the central) is: aci_gap_create_connection(SCAN_P, SCAN_L,

                 saved_devices.dev_info[dev_index].addr_type,

                 saved_devices.dev_info[dev_index].bdaddr,

                 PUBLIC_ADDR, 6, 80, 1, 60, 2000 , 2000);)

and the advertising code in the peripheral is: aci_gap_set_discoverable(

    ADV_TYPE,

    CFG_FAST_CONN_ADV_INTERVAL_MIN,

    CFG_FAST_CONN_ADV_INTERVAL_MAX,

    CFG_BLE_ADDRESS_TYPE,

    ADV_FILTER,

    0,

    0,

    0,

    0,

    6,

    80);

I tried changing the min max intervals. No luck either. Btw, I can connect to the peripheral using any BLE app and it works fine. Any idea what I'm doing wrong in the central code?

11 REPLIES 11
Sebastien DENOUAL
ST Employee

Hi @NafiurRahman​ ,

0x41 : Failed.

0x46 : Not allowed - expected error at this stage as connection is not established.

Focusing on connection issue :

Parameters you are using for aci_gap_create_connection looks correct.

FYI, value I used for a test (OK)

> aci_gap_create_connection(0x4000, 0x4000, PUBLIC_ADDR, bdaddr, PUBLIC_ADDR, 40, 40, 0, 60, 2000 , 2000); 

  • Was the init phase OK ? (gatt_init, gap_init,..)
    • Did you well performed GAP_INIT with role = GAP_CENTRAL_ROLE ?
  • You talk about disconnection ? Should I understand you received callbak connection_complete followed by a disconnection (callback disconnection_complete)
    • If yes : what is disconnection reason code ?

Regards,

Sebastien

NafiurRahman
Associate II

Hi @Sebastien DENOUAL​ ,

I figured out the problem of service discovery. Apparently, I was calling it from inside the connection complete event. I removed it and put it outside the event. And right now now error during service discovery. It returns BLE_STATUS_SUCCESS. But although discover the services, the program continues and disconnects immediately. After service discovery, the code doesn't go to aci_att_read_by_group_type_resp_event.

I've used the same parameters in aci_gap_create_connection as you've mentioned. Unfortunately same result. It disconnects.

To answer your question, all the phases were OK. aci_gap_init was called with GAP_CENTRAL_ROLE.

For disconnection, I just checked the reason code. It is 0x08 - Connection Timeout.

NafiurRahman
Associate II

I forgot to mention, it goes to connection callback first and then to the disconnection callback.

Sebastien DENOUAL
ST Employee

Ok - Thanks for feedback.

> 0x08 is a timeout (supervision timeout)

At first, you can try to increase timeout value while calling aci_gap_create_connection() - Value you set looks alaready correct - Should at least twice connection interval +1 (this is the case here)

May be timeout issue is link to a request which is not acknowledged such as connection parameters update request, ....

Is there any other pending action in your code (ie like update parameters)?

Regards,

Sebastien.

Hi @Sebastien DENOUAL​,

I am calling aci_gatt_disc_all_primary_services. Although the library says that I'll get a response from aci_att_read_by_group_type_resp_event, but I don't get any response back from the peripheral.

I'd like to add that I've removed the service discovery call from my code, and it disconnects too after the supervision timeout. But I guess that is supposed to happen right? When there is no communication between them after connection?

Sebastien DENOUAL
ST Employee

Hi @NafiurRahman​ ,

No, this should not happen.

Once connected - even is you don't exchange any data - Connection remains active. You should not get any disconnection.

Do you have any possibility to capture some logs ? Is there some specific action on peripheral side after connection ? Connection Parma update request or any other action might come from Slave.

Using same code, are you able to connect to another Slave ?

Regards,

Sebastien.

Regards,

Sebastien.

NafiurRahman
Associate II

Hi @Sebastien DENOUAL​,

I'll try to capture some logs. As my peripheral is an STM32WB series MCU, I'll try to use CubeMonitorRF to see the RF commands. I've never used CubeMonitorRF before so I'll try to gather as much information I can.

On the other hand, on the X-Nucleo-BNRG2A1 (the central), using the same code, I tried to connect to a different peripheral. Same issue occurs. It connects and disconnects immediately. This is pointing out that the central is the one with the problem (not sure though). FYI, I'm using the default BLE central example of X-Nucleo-BNRG2A1 software pack without any change.

NafiurRahman
Associate II

Hello @Sebastien DENOUAL​,

Small update. Just to test, I have ran the SensorBLE example on the X-Nucleo-BNRG2A1. The board is acting as a peripheral here. When I try to connect to it from my phone, it does the same thing. Connects and disconnects. The reason is also the same. Timeout. I've used multiple apps to connect to it. (ST BLE Sensor, ST VLE Toolbox).

What do you think is going on?

Sebastien DENOUAL
ST Employee

Hi @NafiurRahman​,

I did similar test on my side :

I used central code example from X-CUBE-BLE2 package, I've been able to scan and connect to a slave device - I did not get any disconnection nor timeout.

Now, from your latest update, (Peripheral config also leading to disconnection), I suspect a more general issue.

Do you confirm "SW code example from X-CUBE-BLE2" is used as it is for this peripheral test ? For sure, this code is working.

What is your exact HW setup ? (schematics/picture might help)

Thanks,

Sebastien.