This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

cc2540 GATT_Notification



官方有没有用GATT_Notification从机向主机发送数据的例程 主从机都是开发板。SimpleBLECentral这个例程用GATT_Notification向主机发送数据需要怎样修改,貌似要向0x2902寄存器写入0x01,怎么写入,还有那个通信许可的handle怎么获取。

  • hi asdfe,

    如果你看simpleBLECentral.c 这个文件, 里面有个函数:simpleBLECentralProcessGATTMsg()

    这个函数就是处理各种从peripheral过来的数据.

    但是在示例代码中并没有加入通知, 就是notification的接收, 所以你得自己添加代码.

    很简单, 类似  if ( ( pMsg->method == ATT_READ_RSP ) || ........),  你添加  else if ( ( pMsg->method == ATT_HANDLE_VALUE_NOTI ) ||......)

    0x2902你是指Client Characteristic Configuration, 不是寄存器吧?

    你说的这个handle都是紧跟在相应的characteristic value的handle后面一个.你找到相应的characteristic value的handle, 用这个characteristic value的UUID去查找这个characteristic value的attribute handle, 找到后加1, 就是你要的handle了

    good luck!

  • static void simpleBLECentralProcessGATTMsg( gattMsgEvent_t *pMsg )
    {
    if ( simpleBLEState != BLE_STATE_CONNECTED )
    {
    // In case a GATT message came after a connection has dropped,
    // ignore the message
    return;
    }

    if ( ( pMsg->method == ATT_READ_RSP ) ||
    ( ( pMsg->method == ATT_ERROR_RSP ) &&
    ( pMsg->msg.errorRsp.reqOpcode == ATT_READ_REQ ) ) )
    {
    if ( pMsg->method == ATT_ERROR_RSP )
    {
    uint8 status = pMsg->msg.errorRsp.errCode;

    LCD_WRITE_STRING_VALUE( "Read Error", status, 10, HAL_LCD_LINE_1 );
    }
    else
    {
    // After a successful read, display the read value
    uint8 valueRead = pMsg->msg.readRsp.value[0];

    LCD_WRITE_STRING_VALUE( "Read rsp:", valueRead, 10, HAL_LCD_LINE_1 );
    }

    simpleBLEProcedureInProgress = FALSE;
    }
    else if ( ( pMsg->method == ATT_WRITE_RSP ) ||
    ( ( pMsg->method == ATT_ERROR_RSP ) &&
    ( pMsg->msg.errorRsp.reqOpcode == ATT_WRITE_REQ ) ) )
    {

    if ( pMsg->method == ATT_ERROR_RSP == ATT_ERROR_RSP )
    {
    uint8 status = pMsg->msg.errorRsp.errCode;

    LCD_WRITE_STRING_VALUE( "Write Error", status, 10, HAL_LCD_LINE_1 );
    }
    else
    {
    // After a succesful write, display the value that was written and increment value
    LCD_WRITE_STRING_VALUE( "Write sent:", simpleBLECharVal++, 10, HAL_LCD_LINE_1 );
    }

    simpleBLEProcedureInProgress = FALSE;

    }
    else if ( simpleBLEDiscState != BLE_DISC_STATE_IDLE )
    {
    simpleBLEGATTDiscoveryEvent( pMsg );
    }

    }

    黄色加亮部分就是你所说的那个功能函数吧

  • GATT_Notification( 0, &nData, FALSE )有三个参数,第一个是不是一般都为0,第二个ndata。handle数字是不是根据

     // Characteristic Value 1
          {
            { ATT_BT_UUID_SIZE, simpleProfilechar1UUID },
            GATT_PERMIT_READ | GATT_PERMIT_WRITE,
            0,
            &simpleProfileChar1
          },这个函数来的  这里的handle=0所以设定为1.我这样做能够实现发送了。我用20ms的定时器定时发送一包数据,数据包会丢失。

    我想问下怎样实现一次连接发送三个数据包?是不是用多个特征值同时发送?这样的话我主机端的接收地址能设置多个么?

    我需要1s发送2k的数据。我用的主机也是开发板,如果换成手机是不是会快一点,因为我加快发送速度的时候感觉是主机丢包。

  • Yan,你好!

    请问从peripheral发到主设备的notification,主设备是把这个notification的值存到哪里了呢?我们知道数据的传输有五个通道,主设备接收的notification是存在那个通道?