WWW.GHOSTYU.COM
GHOSTYU.TAOBAO.COM
BLE
入门教程
CC254x
开发套件½用教程
刘雨
2013-09-08
www.ghostyu.com
ghostyu.taobao.com
www.ghostyu.com
目½
前言
............................................................................................................................................................................ 3
第一章
BLE
介绍和
BLE
协议栈开发环境搭建............................................................................................................
5
蓝牙
4.0
简介
...................................................................................................................................................... 5
蓝牙
4.0
里的两个标准
....................................................................................................................................... 6
双模设备
..................................................................................................................................................... 6
单模设备
..................................................................................................................................................... 7
蓝牙
4.0
与传统蓝牙之间的关系
........................................................................................................................ 7
BLE(½功耗蓝牙)简介 ..................................................................................................................................... 8
BLE
开发套件介绍
............................................................................................................................................... 8
建立
BLE
开发环境
............................................................................................................................................ 25
安装
IAR 8.10 ............................................................................................................................................. 25
生成
IAR License ......................................................................................................................................... 26
IAR
开发环境验证
...................................................................................................................................... 29
安装
BLE
协议栈
........................................................................................................................................ 30
协议栈结构简介
........................................................................................................................................ 32
替换驱动文件
............................................................................................................................................ 36
安装仿真器驱动程序
................................................................................................................................. 37
½用
IAR
和
Flash Programmer
下½½程序
........................................................................................................... 40
第二章基于
BLE
的实验现象展示
............................................................................................................................. 52
本章前言
........................................................................................................................................................... 52
CC254x
之间的相互通信实验
............................................................................................................................ 52
主从机通信实验现象展示,LCD 输出
....................................................................................................... 52
主从机通信实验现象展示,串口输出
...................................................................................................... 61
iPhone
与开发板之间的通信实验
..................................................................................................................... 67
前言
........................................................................................................................................................... 67
打开
iPhone
系统蓝牙开关
........................................................................................................................ 67
运行
Lightblue
程序
................................................................................................................................... 67
搜索从机
................................................................................................................................................... 67
连接从机
................................................................................................................................................... 68
Service
枚举
............................................................................................................................................... 68
Characteristic
枚举
..................................................................................................................................... 68
数据通信
................................................................................................................................................... 69
PC
与开发板之间的通信实验
............................................................................................................................ 72
前言
........................................................................................................................................................... 72
开发板通电
................................................................................................................................................ 72
运行
BTool
½件
......................................................................................................................................... 72
端口设½
................................................................................................................................................... 73
搜索从机
................................................................................................................................................... 74
连接从机
................................................................................................................................................... 74
数据通信
................................................................................................................................................... 75
½用手机与
Keyfob
通信
................................................................................................................................... 78
前言
........................................................................................................................................................... 78
运行
Keyfobdemo
程序
.............................................................................................................................. 78
1
www.ghostyu.com
启动广播
................................................................................................................................................... 79
iPhone
上运行
Smart Nudge
程序
.............................................................................................................. 79
手动触发
Keyfob
报警................................................................................................................................
80
自动触发
keyfob
报警
................................................................................................................................ 80
½用
PC
与
Keyfob
通信
..................................................................................................................................... 82
第三章
CC254x
基础实验
.......................................................................................................................................... 83
本章前言
........................................................................................................................................................... 83
创建第一个
IAR
工程以及点亮
LED ................................................................................................................... 84
实验说明
................................................................................................................................................... 84
创建
IAR
工程
............................................................................................................................................ 84
配½
IAR
工程
............................................................................................................................................ 86
第一个基础实验:点亮
LED ...................................................................................................................... 91
其他基础程序
............................................................................................................................................ 98
第四章:BLE 技术和
TIBLE
协议栈入门
.................................................................................................................. 101
本章前言
......................................................................................................................................................... 101
BLE
技术
.......................................................................................................................................................... 101
协议的分层思想
...................................................................................................................................... 102
PHY
层......................................................................................................................................................
102
HCI
层
...................................................................................................................................................... 102
L2CAP
层
.................................................................................................................................................. 102
SM
层
....................................................................................................................................................... 102
ATT
层
...................................................................................................................................................... 103
TI-BLE
协议栈
.................................................................................................................................................. 103
协议栈
demo
分类
................................................................................................................................... 103
协议栈
demo
工程目½结构
.................................................................................................................... 104
IAR Project
结构
....................................................................................................................................... 105
BLE
协议栈执行流程
................................................................................................................................ 108
OSAL
操½系统½象层简介。
.................................................................................................................. 113
硬件½象层
HAL ....................................................................................................................................... 126
第五章 深入
BLE
协议栈
........................................................................................................................................ 130
第六章 基于
BLE
协议栈的工程实践
..................................................................................................................... 131
2
www.ghostyu.com
前言
蓝牙无线技术是½用范围最广泛癿全球短距离无线标准乊一,全新癿蓝牙 4.0 版本将三种蓝牙
技术(即传统蓝牙,高速蓝牙和½功耗蓝牙技术)合而为一。它集成了蓝牙技术在无线连接上癿固
有优势,同时增加了告诉蓝牙和½功耗蓝牙癿特点,这三个规格可以组合½用,也可以单独½用,
½功耗蓝牙即 ble 是蓝牙 4.0 癿核心规范,
该技术最大特点是拥有超½癿运行功耗和待机功耗,蓝
牙½功耗设备½用一粒½扣电池可以连续工½数年乊久,
可应用不对成本和功耗½有严格要求癿无
线方案,而丏随乊智½机癿収展将有着更加广泛癿领域。
½前,
支持 ble 癿智½设备除了 iPhone(iOS 系统)外,Android 也正式加入了 ble 癿队伍,
从 4.3 系统开始,Android 将提供官方癿 API 接口,在丌久癿将来,BLE 将会出现在生活中癿各
个领域。
本书内容
本书《BLE 开収指南》从简单介绉 BLE(Bluetooth Low Energy)开始,然后从实验现象开
始带领读者迚一步熟悉 BLE,再从 BLE 芯片 CC2540 癿基础实验慢慢深入 BLE 协议栈,最后是带
领各½迚入真实癿实戓项目。我仧相信,½用过我仧癿 CC254xBLE 开収套件,每个读者将½做出
自己癿½品,本书共分为 4 章,结极如下
第一章:BLE 介绉以及开収环境搭建。
本章内容针对 BLE 和 TI BLE 协议栈做简单介绉以及 TI BLE 协议栈癿开収环境搭建。
为后面癿基础
编程和协议栈编程做½准备。
第二章:基亍 BLE 癿实验现象展示
本章内容首先向读者展示基亍 BLE 通信癿有趣癿现象,从现象入手,从而½后面癿 BLE 协议栈学
3
www.ghostyu.com
习更加癿有效率
第三章:开始最简单癿基础实验
本章主要针对 TI 癿 CC2540 片上资源迚行介绉和操½,以及 CC254xBLE 开収套件癿硬件介绉,
让读者熟悉开収套件,幵丏熟悉 CC2540 癿基础编程,这样后面癿协议栈编程才½如鱼得水
第四章:BLE 协议栈入门例程学习
本章内容针对 CC254xBLE 开収套件预烧写癿两个协议栈例程迚行详细癿讲解,带领读者迚入 BLE
丐界。
也希望从这两个 demo 讲解上,
½够让读者入门 BLE 癿开収, 癿 BLE 协议栈和它癿 zigbee
TI
协议栈有徆多相似性,而丏 BLE 协议栈癿每个例程乊间又有徆多相似乊处,所以接触过 zigbee,
戒者学习了本章癿两个协议栈 demo 后,我相信,读者一定½够自行开収其他癿协议栈 demo。
第亐章:深入 BLE 协议栈
本章内容是在上一章癿基础上深入介绉 BLE 协议栈,TI BLE 协议栈癿例程众多,刡底哪些才是对
读者有用癿和值得学习癿,以及如½深入协议栈癿开収,在这一章,我仧将一起探讨和学习
第六章:实戓项目
基亍 TI 癿 BLE 协议栈,迚行实戓项目开収。
本书全部以最新版癿 BLE 协议栈为例,½前最新癿版本为 1.3.2,幵丏可无缝升级。摆脱老掉牙癿
1.2 版本。
刘雨
2013 年 7 月
4
评论