SYD8811使用开发板,代码使用的是透传例程:Source Code\SYD8811_ble_peripheral\1.SYD8811_BLE_UART_notifyen_open_power
FR801XH芯片丝印如下:
两块板子实物路如下:
FR801XH上位机软件<FreqChip_Download.exe>以及烧录步骤如下:
这里使用的工程为:FR801xH-SDK-master\examples\dev1.0\ble_multi_role\kei
简单按照如下步骤修改主机的代码:
1.在void app_gap_evt_cb(gap_event_t *p_event)函数中修改扫描结构中判断设备的逻辑:
case GAP_EVT_ADV_REPORT:
{
uint8_t scan_name[] = "SYD_UART";
// co_printf("data:%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\r\n",p_event->param.adv_rpt->data[0],p_event->param.adv_rpt->data[1],p_event->param.adv_rpt->data[19],\
// p_event->param.adv_rpt->data[20],p_event->param.adv_rpt->data[21],p_event->param.adv_rpt->data[22],p_event->param.adv_rpt->data[23],p_event->param.adv_rpt->data[24],\
// p_event->param.adv_rpt->data[25],p_event->param.adv_rpt->data[26]);
//if(memcmp(event->param.adv_rpt->src_addr.addr.addr,"\x0C\x0C\x0C\x0C\x0C\x0B",6)==0)
// if (p_event->param.adv_rpt->data[0] == 0x05
// && p_event->param.adv_rpt->data[1] == GAP_ADVTYPE_LOCAL_NAME_COMPLETE
// && memcmp(&(p_event->param.adv_rpt->data[2]), scan_name, 0x12) == 0)
if (p_event->param.adv_rpt->data[0] == 0x02
&& p_event->param.adv_rpt->data[1] == GAP_ADTVYPE_FLAGS
&& memcmp(&(p_event->param.adv_rpt->data[19]), scan_name, 0x08) == 0)
{
gap_stop_scan();
co_printf("evt_type:0x%02x,rssi:%d\r\n",p_event->param.adv_rpt->evt_type,p_event->param.adv_rpt->rssi);
co_printf("content:");
show_reg(p_event->param.adv_rpt->data,p_event->param.adv_rpt->length,1);
gap_start_conn(&(p_event->param.adv_rpt->src_addr.addr),
p_event->param.adv_rpt->src_addr.addr_type,
12, 12, 0, 300);
}
}
break;
2.在void app_gap_evt_cb(gap_event_t *p_event)函数中修改连接上设备好查找的服务:
case GAP_EVT_MASTER_CONNECT:
{
co_printf("master[%d],connect. link_num:%d\r\n",p_event->param.master_connect.conidx,gap_get_connect_num());
//master_link_conidx = (p_event->param.master_connect.conidx);
#if 0
if (gap_security_get_bond_status())
gap_security_enc_req(p_event->param.master_connect.conidx);
else
gap_security_pairing_req(p_event->param.master_connect.conidx);
#else
// extern uint8_t client_id;
// gatt_discovery_all_peer_svc(client_id,p_event->param.master_encrypt_conidx);
uint8_t group_uuid[]={0x01,0x00};
gatt_discovery_peer_svc(client_id,p_event->param.master_encrypt_conidx,2,group_uuid);
#endif
mr_central_start_scan();
}
break;
3.static uint16_t mr_central_msg_handler(gatt_msg_t *p_msg)函数中查找到服务后使能notify等操作:
case GAP_EVT_MASTER_CONNECT:
{
co_printf("master[%d],connect. link_num:%d\r\n",p_event->param.master_connect.conidx,gap_get_connect_num());
//master_link_conidx = (p_event->param.master_connect.conidx);
#if 0
if (gap_security_get_bond_status())
gap_security_enc_req(p_event->param.master_connect.conidx);
else
gap_security_pairing_req(p_event->param.master_connect.conidx);
#else
// extern uint8_t client_id;
// gatt_discovery_all_peer_svc(client_id,p_event->param.master_encrypt_conidx);
uint8_t group_uuid[]={0x01,0x00};
gatt_discovery_peer_svc(client_id,p_event->param.master_encrypt_conidx,2,group_uuid);
#endif
mr_central_start_scan();
}
break;
到此代码修改结束!
主从都下载好后双方的打印如下:
可以看到能够正确连接SYD8811,但是notify使能失败!
抓包后发现是因为FR801XH的芯片的ATT命令和手机的有点差别,造成和SYD8811不兼容!
目前先到这里,以后有需要再分析!
本文对应的资料包为"FR801XH连接SYD8811资料合集20220511 144402.7z",如果有需要,请和博主联系!