微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > CC2540master与Slave通信问题

CC2540master与Slave通信问题

时间:10-02 整理:3721RD 点击:

我主机用SimpleBLECentral工程,从机用BloodPressure工程,它们连接成功后我用从机Service_IMeasNotify发送数据给主机,在运行

bStatus_t Service_IMeasNotify( uint16 connHandle, attHandleValueNoti_t *pNoti, uint8 taskId )
{
uint16 value = GATTServApp_ReadCharCfg( connHandle, ServiceIMeasConfig );

// If notifications enabled
if ( value & GATT_CLIENT_CFG_NOTIFY )
{
// Set the handle
pNoti->handle = ServiceAttrTbl[SERVICE_IMEAS_VALUE_POS].handle;

// Send the Indication
return GATT_Notification( connHandle, pNoti, FALSE);

}
return bleIncorrectMode;

}这个中uint16 value = GATTServApp_ReadCharCfg( connHandle, ServiceIMeasConfig );读出value 为0;这是为什么,是还要怎样设置才可以从机端才可以用Notification发送数据给主机端?

notification刚开始都是关闭的,你需要通过主机发送如下命令enable.

To enable notifications, you must write a value of 0x0001 to the client characteristic configuration descriptor (CCCD). If you know the handle of the client characteristic descriptor, you can enable notifications by using the following code:

  attWriteReq_t writeReq;
  uint16 connHandle = connectionHandle;  // this will always be 0 if device only ever has one connection at a time

  writeReq.handle = handleOfCCCD; // if you know the value, you can put it in as a fixed value;
                                  // otherwise you will need to first discover the value
  writeReq.len = 2;
  writeReq.value[0] = LO_UINT16(GATT_CLIENT_CFG_NOTIFY);
  writeReq.value[1] = HI_UINT16(GATT_CLIENT_CFG_NOTIFY);
  writeReq.sig = 0;
  writeReq.cmd = 1;
 
  GATT_WriteNoRsp( connHandle, &writeReq, taskId );

Before doing this, you may also need to discover the handle of the CCCD. Some example of this process can be found in the TimeApp project which is included in the SDK. Specifically, look in the file "timeapp_discovery.c

请问怎样发现handleOfCCCD的值,看timeapp_discovery.c看不懂,能否详细说清楚点?

In order to enable notifications, the client device must write a value of 0x0001 to the client characteristic
configuration descriptor for the particular characteristic. The handle for the client characteristic
configuration descriptor immediately follows the characteristic value’s handle. Therefore, a value of
0x0001 must be written to the “handle + 1”.

建议你按照《CC2540/41 Mini Development Kit User’s Guide》Document Number: SWRU270C。先做一遍,搞清楚其中的概念,剩下的只是调什么接口函数的问题了。

is that each characteristic can have its own CCCD ?

in ANCS , how can i both subscribe to get callback from Notification Source and Data Source  ?
(https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Specification/Specification.html) 

e.g.

9FBF [notify characteristic ] - Notification Source
22EA[notify characteristic ] - Data Source

do it means i can get CCCD from both 9FBF , 22EA ?
 and i can start notify both with above procedure ?

with reference to "timeapp_discover.c"

is the callback of both notify  arrive at  TimeAppDiscAlertNtf ?

能把你的代码共享一下吗,好多人都卡到了这里

请问writeReq.cmd = 1;代表什么意思?

可以参考我个性签名档的博客地址,《CC2541之主机端获取notify数据》

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top