SF32LB58 adds a Bluetooth master device based on the watch routine

  1. For the SF32LB58 platform, currently based on the watch example code, I would like to add a new program for a Bluetooth master device to actively connect to a slave device and communicate normally.

The current issue is that, using the attached code, the newly added program can successfully connect to the slave device, but it cannot receive data from the slave device. Please help check where the problem might be.

simple_ble_master.c (9.0 KB)

I couldn’t tell much just by looking at the attached code. Could you please upload the entire project, and also provide the operation procedure, expected behavior, and actual behavior?

The project is too large to send. Currently, data is being sent via serial port, and then the function simple_ble_start(void) below is triggered.

Originally, the example code was designed for the device to act as a slave (peripheral) connected by a phone. The current idea is to add a new task so that the device can simultaneously act as both a slave (peripheral) and a master (central). As a master, it should be able to connect to other slave devices and communicate with them. The current issue is: after starting, the connection succeeds, but communication fails. The slave continuously sends data, but the master does not receive or print it.

Log data after connection:

[119842] drv.lcdp: DSI error code 80
[119845] nv3051f1: ESDCehck PowerMode 0x9c
[144549] drv.lcdp: DSI error code 80
[144553] nv3051f1: ESDCehck PowerMode 0x9c
[U5] 585a0103000001010f00000008A585
[157249] simple_ble: Start scanning for devices with name: KEEY FOUR
[157258] BLE_GAP: evt 161, ret 0
[157319] BLE_GAP: evt 164, ret 0
[157322] simple_ble: Scan started
[157326] ble_connect: Scan start status 0
[157330] ble_talk.rev: Scan start status 0
ble_tool_event_handler, id:50
[157617] simple_ble: Found device: KEEY FOUR
[157622] simple_ble: Target matched!
[157625] simple_ble: Target found, stopping scan…
ble_tool_event_handler, id:73
ble_tool_event_handler, id:73
[157637] simple_ble: Scan stopped, reason: 0
[157642] ble_connect: Scan stopped 0
[157645] ble_talk.rev: Scan stopped 0
ble_tool_event_handler, id:51
[157651] BLE_GAP: evt 165, ret 0
[157655] ble_talk.rev: Scan stop
ble_tool_event_handler, id:52
[157661] BLE_GAP: evt 162, ret 0
[157665] BLE_GAP: evt 167, ret 0
[157689] BLE_GAP: evt 164, ret 0
ble_tool_event_handler, id:53
[157973] ble_cm: BLE_GAP_CONNECTED_IND
[157977] ble_cm: connection_manager_event_process 0x40
ble_tool_event_handler, id:176
[157985] ble_cm: connection_manager_connection_state_change 0x20 to 0x23
[157992] sibles: tb cb:100ce411,id:3
[157996] sibles: tb cb:100d0689,id:4
[157999] sibles: tb cb:100e3c6d,id:1
[158003] sibles: tb cb:1035ba3d,id:6
[158006] DFU_P: Peripheral should be slave!!!
[158011] DFU_P: Peer device(10-20-ba-91-1c-7a) connected
[158016] simple_ble: *** MASTER: Connected to device! conn_idx=0
[158022] simple_ble: Starting service discovery…
[158027] ble_ancs: BLE_GAP_CONNECTED_IND conn_idx:0
[158032] ble_connect: Peer device(role:0) (10-20-ba-91-1c-7a) connected as deivce 0
[158039] bt_connect: [app_bt_connect_req] mask:159 type:2 addr:00000000
[158046] bt_connect: db addr:00:00:00:00:00:00
[158050] bt_connect: [bt_connect_update_last_idx] conn idx:0 connected
[158057] bt_connect: [app_bt_connect_req] bt addr invalid
[158063] APP.UI: send_msg_to_gui_thread_e: msg 623fe088 msg_len 4 data_len 1 ret_addr 1010fe8b err 0
[158072] bt_connect: [app_bt_connect_req] mask:159 type:2 addr:00000000
[158078] bt_connect: db addr:00:00:00:00:00:00
[158083] bt_connect: [bt_connect_update_last_idx] conn idx:0 connected
[158089] bt_connect: [app_bt_connect_req] bt addr invalid
[158095] APP.UI: send_msg_to_gui_thread_e: msg 623feb28 msg_len 4 data_len 1 ret_addr 1010fe8b err 0
[158104] ble_connect: BLE_GAP_CONNECTED_IND idx:0 con_interval:48
[158110] APP.UI: Peripheral should be slave!!!
[158115] APP.UI: Peer device(10-20-ba-91-1c-7a) connected
ble_tool_event_handler, id:55
[158123] sibles: connected 0
[158126] ble_cm: SIBLES_REMOTE_CONNECTED_IND
[158130] simple_ble: RECV: event=0x0064, len=1
DATA: 00
ble_tool_event_handler, id:100
[158138] simple_ble: RECV: event=0x005C, len=2
DATA: 04 00
ble_tool_event_handler, id:92
[158149] APP.UI: app_lv_task_exec: msg 623fe088 len 4
[158154] APP.UI: app_lv_task_exec: msg 623feb28 len 4
[159068] sibles: GATTC_CMP_EVT 1, 0
[159073] ble_cm: SIBLES_MTU_EXCHANGE_IND 0, 500
[159080] ble_cm: update_data_length
[159083] DFU_P: Exchanged MTU size: 500
[159088] simple_ble: RECV: event=0x0067, len=4
DATA: 00 75 F4 01
[159095] ble_connect: Exchanged device 0 MTU size: 500
ble_tool_event_handler, id:103
[159105] simple_ble: RECV: event=0x004B, len=10
DATA: 00 93 1B 00 48 01 FB 00 48 08
ble_tool_event_handler, id:75
[160048] sibles: GATTC_CMP_EVT 1, 0
[160052] ble_cm: SIBLES_MTU_EXCHANGE_IND 0, 500
[160056] ble_cm: update_data_length
[160060] DFU_P: Exchanged MTU size: 500
[160064] simple_ble: RECV: event=0x0067, len=4
DATA: 00 48 F4 01
[160070] ble_connect: Exchanged device 0 MTU size: 500
ble_tool_event_handler, id:103
[161032] sibles: svc search end 10
[161036] simple_ble: RECV: event=0x0090, len=2
DATA: 00 02
[161042] ble_ancs: BLE_ANCS_ENABLE_RSP conn_idx:0 result:2 encrypt:0
ble_tool_event_handler, id:144
ble_tool_event_handler, id:97
[164158] BLE_GAP: GAPC event status, op: 20, ret 0
[164163] simple_ble: RECV: event=0x004A, len=2
DATA: 00 00
ble_tool_event_handler, id:74
[164478] ble_cm: BLE_GAP_UPDATE_CONN_PARAM_IND 32, 0
[164483] ble_cm: connection_manager_event_process 0x49
[164488] simple_ble: RECV: event=0x00BA, len=8
DATA: 00 65 20 00 00 00 90 01
ble_tool_event_handler, id:186
[164498] simple_ble: RECV: event=0x003E, len=8
DATA: 00 00 20 00 00 00 90 01
[164506] ble_connect: BLE_GAP_UPDATE_CONN_PARAM_IND
[164511] ble_connect: conn_idx:0, con_interval:32, con_latency:0
[164517] ble_connect: latency:2, interval_min:80, interval_max:100
[164523] NO_TAG: ota_get_res_status:0
ble updata para
ble_tool_event_handler, id:62
[165134] simple_ble: RECV: event=0x004B, len=10
DATA: 00 0E FB 00 48 08 FB 00 48 08
ble_tool_event_handler, id:75
[169394] drv.lcdp: DSI error code 80
[169398] nv3051f1: ESDCehck PowerMode 0x9c
[183381] APP.FWK.PM: fsm:Cur[GUI_STATE_ACTIVE],Action[GUI_PM_ACTION_SLEEP]
[183390] APP.FWK.PM: change_gui_state:[GUI_STATE_ACTIVE]->[GUI_STATE_INACTIVE_PENDING]
[183400] APP.UI: app_gui_pm_process: event 1 sleep_type 0x0007 idle 4
[183408] APP.UI: app_gui_sleep_suspend_app
[183412] APP.FWK: send msg[GUI_APP_MSG_SUSPEND_SCHEDULER] [0x0] to gui_app_mbx tick:22208.
[183422] APP.FWK: gui_app_exec_now Start
[183427] APP.FWK: send msg[GUI_APP_MSG_ABORT_TRANS_ANIM] [0x0] to gui_app_mbx tick:22210.
[183437] APP.SCHE: ----------------app_schedule_task---------------start
[183445] APP.SCHE: >>Execute msg[GUI_APP_MSG_SUSPEND_SCHEDULER] tick:22208
[183453] APP.SCHE: Pause all app and suspend scheduler
[183459] APP.SCHE: page[Main][root] tgt_state [RESUMED] → [PAUSED]
[183467] APP.SCHE: page[Main][root] do ONPAUSE, 623fee88
[183481] APP.UI: menu_pause: cur List last List
[183486] APP.SCHE: app_schedule_task done.
[183492] APP.FWK: gui_app_exec_now Cnt 0
[183496] APP.FWK: gui_app_exec_now Done.
[183501] IPC_SRV: ipc_send_msg_to_server: LCPU_APP client_handle 11 623fef08 client_ready 1
[183597] APP.UI: app_gui_pm_process: event 2 sleep_type 0x0007 idle 1
[183604] drv.epic: drv_gpu closed.
[183607] drv.lcd: Power off
[183610] drv.lcd: display off
[183613] nv3051f1: SetBrightness,br:0,pulse:0
[191616] drv.lcd: [ON] → [OFF]
[191619] drv.lcd: HW close
[199616] drv.lcd: HW close done.
[199619] drv.lcd: Power off done
[199623] TOUCH: Power off
[199625] TOUCH: Power off done.
[199904] APP.FLASHDB: app_flashdb_write: nvm_ble fn /nvm/app/nvm_ble 33 (ms)
[199911] APP.FWK.PM: change_gui_state:[GUI_STATE_INACTIVE_PENDING]->[GUI_STATE_INACTIVE]
[199919] APP.FWK.PM: gui_suspend
  1. The callback of sibles_register_remote_svc cannot be null, as notifications or indications from the remote device are delivered through this callback (SIBLES_REMOTE_EVENT_IND).
  2. You must first enable notification or indication in the Client Characteristic Configuration Descriptor (CCCD) in order to receive notifications or indications sent from the remote device.
  3. For both points above, you can refer to the main.c and bf0_sibles_ancs.c files in the central_and_peripheral project, which include code examples for discovering and registering server-side services.

Alright, I’ve debugged it. Thank you.