連接斷開(kāi)后返回的錯(cuò)誤碼代表上面意識(shí),從那個(gè)手冊(cè)可以看到,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
主機(jī)用的是CH573,使用的是Central例程,藍(lán)牙設(shè)備是N21的NB模組,我修改例程中的MAC地址和UUID后可以跟N21模組連接上,并通過(guò)UUID=0XFFF0獲取到主服務(wù),
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...
再通過(guò)UUID=0XFFF2獲取handle時(shí),獲取不到,如果我不獲取handle,直接將handle設(shè)置為0x24,就可以和N21模組正常收發(fā)數(shù)據(jù)。這是什么原因?
以下是更改后的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按類型查找值響應(yīng)
? ? ? ? ? ? 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);屏蔽,直接用注釋掉的代碼,就可以和從設(shè)備正常通信了。
為什么沒(méi)有技術(shù)人員回復(fù)???
CH579 CH573 CH582 Central 例子應(yīng)用說(shuō)明二 (讀寫通知的控制說(shuō)明) - debugdabiaoge - 博客園 (cnblogs.com)
獲取通道handle的方法可以參考這個(gè)說(shuō)明
從你的打印信息看,在獲取handle的過(guò)程中有mtu的交互,可以這樣試試看,在交互mtu之后再去開(kāi)始發(fā)現(xiàn)服務(wù)獲取handle。
建立工程是我選的單片機(jī)是CH573F,現(xiàn)在我想更改為CH571單片機(jī),怎么更改?
如果是將573芯片切換為571芯片,需要注意這里相應(yīng)的功能使用即可:
使用的工程都是官方CH573EVT