如果在Zephyr内如何使用ESP32蓝牙

描述

在Zephyr ESP32 蓝牙驱动简析一文中简要分析了esp32 蓝牙如何集成进Zephyr,本文接着说明如果在Zephyr内使用ESP32蓝牙。

在Zepher中使用ESP32蓝牙比WIFI还要简单只要基于esp32 board编译的APP配置了CONFIG_BT=y就会默认打开ESP32蓝牙的配置CONFIG_BT_ESP32,详细可见boardsxtensaesp32Kconfig.defconfig.

之后就直接使用zephyr提供的蓝牙API进行应用编程即可。

本文不说明如何进行蓝牙编程,试跑一个Zephyr的蓝牙例程eddystone,这是Google BLE Beacon,用于蓝牙定位。

例程的配置文件如下

1

2

3

4

CONFIG_BT=y

CONFIG_BT_DEBUG_LOG=y

CONFIG_BT_PERIPHERAL=y

CONFIG_BT_DEVICE_NAME=“Zephyr Eddystone”

应用主程序如下, 实际的各种流程都在bt_ready中展开

void main(void)

{

int err;

bt_conn_cb_register(&conn_callbacks);

k_work_init_delayable(&idle_work, idle_timeout);

/* Initialize the Bluetooth Subsystem */

err = bt_enable(bt_ready);

if (err) {

printk(“Bluetooth init failed (err %d)

”, err);

}

}

编译并下载

1

2

west build -p -b esp32 zephyrproject/zephyr/samples/bluetooth/eddystone

west flash --esp-device /dev/ttyS11

运行log如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

▒▒*** Booting Zephyr OS build v2.6.0-rc1-300-g6ce0f2ee6606 ***

phy_version: 4500, 0cd6843, Sep 17 2020, 1507, 0, 2

Coex register schm btdm cb faild

Bluetooth initialized

Initial advertising as C457F8:DE (public)

Configuration mode: waiting connections.。。

[0000.911,000] 《dbg》 bt_hci_driver_esp32.hci_esp_host_rcv_pkt: Calling bt_recv(0x3fff4c28)

--- 98 messages dropped ---

[0000.911,000] 《inf》 bt_hci_core: Identity: C457F8:DE (public)

[0000.911,000] 《inf》 bt_hci_core: HCI: version 4.2 (0x08) revision 0x030e, manufacturer 0x0060

[0000.911,000] 《inf》 bt_hci_core: LMP: version 4.2 (0x08) subver 0x030e

[0000.911,000] 《dbg》 bt_hci_driver_esp32.bt_esp32_send: buf 0x3fff4c28 type 0 len 18

[0000.911,000] 《dbg》 bt_hci_driver_esp32: Final HCI buffer:

01 06 20 0f a0 00 f0 00 00 00 00 00 00 00 00 00 |。。 。。.。。 。。.。。.。。

00 07 00 |。。.

在手机上通过nrf connect可以看到”Zephyr Eddystone”

从上面可以看到zephyr上面使用ESP32蓝牙完全可以不用关心驱动,是单纯应用层的编程。

编辑:jq

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分