连接断开后返回的错误码代表上面意识,从那个手册可以看到,Disconnected...Reason:8
#define BLE_HCI_STATUS_CODE_SUCCESS 0x00
#define BLE_HCI_STATUS_CODE_UNKNOWN_BTLE_COMMAND 0x01
#define BLE_HCI_STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER 0x02
#define BLE_HCI_AUTHENTICATION_FAILURE 0x05
#define BLE_HCI_STATUS_CODE_PIN_OR_KEY_MISSING 0x06
#define BLE_HCI_MEMORY_CAPACITY_EXCEEDED 0x07
#define BLE_HCI_CONNECTION_TIMEOUT 0x08
#define BLE_HCI_STATUS_CODE_COMMAND_DISALLOWED 0x0C
#define BLE_HCI_STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS 0x12
#define BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION 0x13
#define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES 0x14
#define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF 0x15
#define BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION 0x16
#define BLE_HCI_UNSUPPORTED_REMOTE_FEATURE 0x1A
#define BLE_HCI_STATUS_CODE_INVALID_LMP_PARAMETERS 0x1E
#define BLE_HCI_STATUS_CODE_UNSPECIFIED_ERROR 0x1F
#define BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT 0x22
#define BLE_HCI_STATUS_CODE_LMP_ERROR_TRANSACTION_COLLISION 0x23
#define BLE_HCI_STATUS_CODE_LMP_PDU_NOT_ALLOWED 0x24
#define BLE_HCI_INSTANT_PASSED 0x28
#define BLE_HCI_PAIRING_WITH_UNIT_KEY_UNSUPPORTED 0x29
#define BLE_HCI_DIFFERENT_TRANSACTION_COLLISION 0x2A
#define BLE_HCI_PARAMETER_OUT_OF_MANDATORY_RANGE 0x30
#define BLE_HCI_CONTROLLER_BUSY 0x3A
#define BLE_HCI_CONN_INTERVAL_UNACCEPTABLE 0x3B
#define BLE_HCI_DIRECTED_ADVERTISER_TIMEOUT 0x3C
#define BLE_HCI_CONN_TERMINATED_DUE_TO_MIC_FAILURE 0x3D
#define BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED 0x3E
主机用的是CH573,使用的是Central例程,蓝牙设备是N21的NB模组,我修改例程中的MAC地址和UUID后可以跟N21模组连接上,并通过UUID=0XFFF0获取到主服务,
Waiting for advertising..
[22-04-24 16:33:25.634]MTU: f6
[22-04-24 16:33:25.711]
[22-04-24 16:33:26.397]exchange mtu:23
[22-04-24 16:33:26.397]MTU: 17
[22-04-24 16:33:26.554]Found Profile Service handle : 1d ~ 27
[22-04-24 16:33:26.704]
[22-04-24 16:33:28.532]Param Update...
再通过UUID=0XFFF2获取handle时,获取不到,如果我不获取handle,直接将handle设置为0x24,就可以和N21模组正常收发数据。这是什么原因?
以下是更改后的UUID
#define SIMPLEPROFILE_SERV_UUID 0xFFF0
// Key Pressed UUID
#define SIMPLEPROFILE_CHAR1_UUID 0xFFF1
#define SIMPLEPROFILE_CHAR2_UUID 0xFFF2
#define SIMPLEPROFILE_CHAR3_UUID 0xFFF3
#define SIMPLEPROFILE_CHAR4_UUID 0xFFF4
#define SIMPLEPROFILE_CHAR5_UUID 0xFFF5
if(pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
pMsg->msg.findByTypeValueRsp.numInfo > 0)
{
centralSvcStartHdl = ATT_ATTR_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
centralSvcEndHdl = ATT_GRP_END_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
// Display Profile Service handle range
PRINT("Found Profile Service handle : %x ~ %x \n", centralSvcStartHdl, centralSvcEndHdl);
}
// If procedure complete
if((pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP && //ATT按类型查找值响应
pMsg->hdr.status == bleProcedureComplete) || //程序完成了
(pMsg->method == ATT_ERROR_RSP))
{
if(centralSvcStartHdl != 0)
{
// Discover characteristic
centralDiscState = BLE_DISC_STATE_CHAR;
req.startHandle = centralSvcStartHdl;
req.endHandle = centralSvcEndHdl;
req.type.len = ATT_BT_UUID_SIZE;
req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR2_UUID);
req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR2_UUID);
GATT_ReadUsingCharUUID(centralConnHandle, &req, centralTaskId);
// centralCharHdl = 0x24;
// centralProcedureInProgress = FALSE;
//
// // Start do read or write
// tmos_start_task(centralTaskId, START_READ_OR_WRITE_EVT, DEFAULT_READ_OR_WRITE_DELAY);
//
// // Display Characteristic 1 handle
// PRINT("Found Characteristic 1 handle : %x \n", centralCharHdl);
// centralDiscState = BLE_DISC_STATE_IDLE;
}
}
}
else if(centralDiscState == BLE_DISC_STATE_CHAR)
{
// Characteristic found, store handle
if(pMsg->method == ATT_READ_BY_TYPE_RSP &&
pMsg->msg.readByTypeRsp.numPairs > 0)
{
centralCharHdl = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[0],
pMsg->msg.readByTypeRsp.pDataList[1]);
centralProcedureInProgress = FALSE;
// Start do read or write
tmos_start_task(centralTaskId, START_READ_OR_WRITE_EVT, DEFAULT_READ_OR_WRITE_DELAY);
// Display Characteristic 1 handle
PRINT("Found Characteristic 1 handle : %x \n", centralCharHdl);
}
centralDiscState = BLE_DISC_STATE_IDLE;
}
将GATT_ReadUsingCharUUID(centralConnHandle, &req, centralTaskId);屏蔽,直接用注释掉的代码,就可以和从设备正常通信了。
为什么没有技术人员回复啊?
CH579 CH573 CH582 Central 例子应用说明二 (读写通知的控制说明) - debugdabiaoge - 博客园 (cnblogs.com)
获取通道handle的方法可以参考这个说明
从你的打印信息看,在获取handle的过程中有mtu的交互,可以这样试试看,在交互mtu之后再去开始发现服务获取handle。
建立工程是我选的单片机是CH573F,现在我想更改为CH571单片机,怎么更改?
如果是将573芯片切换为571芯片,需要注意这里相应的功能使用即可:
使用的工程都是官方CH573EVT