Skip to main content
NafiurRahman
Associate III
March 3, 2022
Question

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

  • March 3, 2022
  • 9 replies
  • 4922 views

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?

This topic has been closed for replies.

9 replies

Sebastien DENOUAL
ST Employee
March 4, 2022

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 III
March 4, 2022

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 III
March 4, 2022

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

Sebastien DENOUAL
ST Employee
March 7, 2022

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.

NafiurRahman
Associate III
March 7, 2022

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
March 7, 2022

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 III
March 7, 2022

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 III
March 7, 2022

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
March 8, 2022

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.

NafiurRahman
Associate III
March 8, 2022

Hi @Sebastien DENOUAL​,

The problem is now solved. I was using the Nucleo Expansion Board with a black pill module with necessary connections (In the image attached). I ordered a nucleo board and hooked up the expansion board with it. And it worked like a charm. Seems like in order to use it with the black pill module, I need to do something extra for a reliable connection. Do you happen to know what extra connections I need to consider?0693W00000KboPZQAZ.jpg

Sebastien DENOUAL
ST Employee
March 8, 2022

Hi @NafiurRahman​ ,

Good news ! Thanks for the update.

Reference documentation to use is the one for X-CUBE-BLE2 package ( which apply to X-NUCLEO-BNRG2A1) . I attached it to this post. This doc describe how to configure both SW and Nucleo HW.

Please take care that the screen copy you attached on your last post is a different board (IDB04A1) which must be used together with X-CUBE-BLE1 package. Slightly different from the one we are discussing here

Regards,

Sebastien.