CH579M作為主機怎樣查找從機,求助!

一.從機為另一款芯片藍牙模塊,Uuid分別為

Server_Uuid:

D973F2E0-B19E-11E2-9E96-080020F29A66

Tx_Uuid:

D973F2E1-B19E-11E2-9E96-9E08000C9A66

Rx_Uuid:

D973F2E2-B19E-11E2-9E96-0800200C9A66

使用Central例程,修改以下

uint8_t?server_uuid[16]=?{0xD9,0x73,0xF2,0xE0,0xB1,0x9E,0x11,0xE2,0x9E,0x96,0x08,0x00,0x20,0xF2,0x9A,0x66};
static?void?centralStartDiscovery(?void?)
{
//??uint8?uuid[ATT_BT_UUID_SIZE]?=?{?LO_UINT16(SIMPLEPROFILE_SERV_UUID),
//???????????????????????????????????HI_UINT16(SIMPLEPROFILE_SERV_UUID)?};
??
??//?Initialize?cached?handles
??centralSvcStartHdl?=?centralSvcEndHdl?=?centralCharHdl?=?0;
??centralDiscState?=?BLE_DISC_STATE_SVC;
??
??//?Discovery?simple?BLE?service
??GATT_DiscPrimaryServiceByUUID(?centralConnHandle,
?????????????????????????????????server_uuid,
?????????????????????????????????ATT_UUID_SIZE,
?????????????????????????????????centralTaskId?);
}

上述代碼執(zhí)行無法查詢到服務(wù)Handle,需要怎樣修改

二.如果在不知道對方Uuid的情況下,在通過Mac連接到從機設(shè)備后怎樣獲取uuid

待連接的藍牙芯片的UUID是128bit,CH58xcentral默認是16bit的,因此需要做修改:

image.png

可以留下郵箱,提供代碼參考。


您好,您留個郵箱,給您發(fā)發(fā)現(xiàn)所有服務(wù)的參考代碼。


問題已經(jīng)找到了,謝謝!還有個問題就是CH579M SWD調(diào)試必須先用WCHISP軟件設(shè)置使能"兩線仿真"么?因為我手頭的板子是沒有USB口的,沒法使用WCHISP軟件,如果我需要仿真該怎么辦?


代碼調(diào)試期間,啟用兩線仿真需要在上位機進原廠boot后操作。您板子上有接出UART1和PB22嗎嗎,使用UART1接口也可以進boot,PB22接GND同時串口4根線一起接上,再點擊啟用兩線仿真,也可以成功(串口識別BOOT不會有提示)。啟用SWD會提示有代碼泄漏風險,代碼調(diào)試完畢批量生產(chǎn)后不建議啟用。


我這邊還遇到一個問題,CH579M為主機可以和CH579M的藍牙模塊(從機)進行通訊,讀寫都正常.但是和BLUENRG1芯片的藍牙模塊沒法通訊,服務(wù)特性搜索如下image.png,當寫入數(shù)據(jù)時提示W(wǎng)rite Error :3,手機搜索BLUENRG1模塊如下image.png,手機可以正常和BLUENRG1模塊通訊。請問我這邊出錯 的原因是什么,謝謝!


搜索代碼如下:

static?void?centralGATTDiscoveryEvent(?gattMsgEvent_t?*pMsg?)
{
	uint8_t?result;
//??attReadByTypeReq_t?req;
	uint8_t?i;
//	uint8_t?*p_uuid;
//	uint8_t?uuid_length;
??PRINT("centralGATTDiscoveryEvent\r\n");
??if?(?centralDiscState?==?BLE_DISC_STATE_SVC?)
??{		
????//?Service?found,?store?handles
????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??&&?pMsg->hdr.status?==?bleProcedureComplete?)?||?(?pMsg->method?==?ATT_ERROR_RSP?)?)
????{
??????if?(?centralSvcStartHdl?!=?0?)
??????{
				centralDiscState?=?BLE_DISC_STATE_CHAR;
				result?=?GATT_DiscAllChars(centralConnHandle,centralSvcStartHdl,centralSvcEndHdl,centralTaskId);
				PRINT("GATT_DiscAllChars:%02x\r\n",result);
				iFindChar?=?0;
??????}
????}
	}
??else?if?(?centralDiscState?==?BLE_DISC_STATE_CHAR?)
??{
		//?Characteristic?found,?store?handle
		if(pMsg->method?==?ATT_READ_BY_TYPE_RSP?&&?pMsg->msg.readByTypeRsp.numPairs?>?0)
		{
			for(i?=?0;?i?<?pMsg->msg.readByTypeRsp.numPairs?;?i++)?
			{
				//characteristic?properties
				uint8_t?char_properties?=?pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len?*?i?+?2];
				uint16_t?char_value_handle?=?BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len?*?i+3],?\
																		?pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len?*?i?+?4]);
				//characteristic?uuid?length
				uint8_t?char_uuid_length?=?pMsg->msg.readByGrpTypeRsp.len?-?5;
				//uuid
				uint8_t?*char_uuid?=?&(pMsg->msg.readByGrpTypeRsp.pDataList[pMsg->msg.readByGrpTypeRsp.len?*?i?+?5]);

				PRINT("char_properties??:%02x,%s\r\n",char_properties,(char_properties&(GATT_PROP_WRITE|GATT_PROP_WRITE_NO_RSP))?"wite?handle":"");
				PRINT("char_value_handle:%04x\r\n",char_value_handle);
				PRINT("char_uuid_length?:%02d\r\n",char_uuid_length);
				PRINT("char_uuid????????:");
				hex_dump(char_uuid,char_uuid_length);
				if(char_properties&GATT_PROP_NOTIFY)?
				{
					centralCCCDHdl?=?char_value_handle+1;
					PRINT("notify?handle:%04x\r\n",centralCCCDHdl);
					iFindChar?|=?(1<<0);
			??}
				else?if(char_properties&(GATT_PROP_WRITE|GATT_PROP_WRITE_NO_RSP))?
				{
					centralCharHdl?=?char_value_handle;
					PRINT("wtite?handle:%04x\r\n",char_value_handle);
					iFindChar?|=?(1<<1);		
				}				
//????????????????if(char_properties&GATT_PROP_INDICATE)?{
//????????????????????centralCCCDHdl?=?char_value_handle+1;
//????????????????????PRINT("notify?handle2:%04x\r\n",char_value_handle);
//????????????????????tmos_start_task(centralTaskId,?START_WRITE_CCCD_EVT,?800);
//???????????????}
			}
		}??
		if((iFindChar?&0x03)?==?0x03)
??		centralDiscState?=?BLE_DISC_STATE_CCCD;	
	}
??else?if?(?centralDiscState?==?BLE_DISC_STATE_CCCD?)
	{
		if?(?pMsg->method?==?ATT_READ_BY_TYPE_RSP)?
		{
			PRINT("Found?client?characteristic?configuration?handle?:?%x?\n",centralCCCDHdl);
			central_enbale_notify(centralConnHandle,centralCCCDHdl);
			tmos_start_task(centralTaskId,?START_READ_OR_WRITE_EVT,?1600);
			centralProcedureInProgress?=?FALSE;
			centralDoWrite?=true;						
			centralDiscState?=?BLE_DISC_STATE_IDLE;
		}
	}		
}



在建立連接成功之后,可以直接根據(jù)handle值進行通信:

image.png

image.png


這個例程可以發(fā)我郵箱么,謝謝!個人信息保護,已隱藏


已發(fā)送至郵箱,請查收。

這里的類型如果是write no response,則做如下修改:

1.png


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频