nrf51822教程 第一课 BLE Advertising 蓝牙广播

BLE Advertising, a beginner's tutorial

the purpose of this tutorial is to get you started with the basics of the nRF5x and Bluetooth Low Energy (BLE). The tutorial is fairly superficial and is meant to be a hands-on introduction to BLE advertising and broadcasting of a limited payload. It is intended to be a fun way to get you started with something functional, and maybe inspire you to go further with BLE. Here you will not learn details of the BLE protocol, but we will have a quick look at what you should know before making an advertising device.

Before we begin

Table of context

    1. Before we begin
    2. The "Hello world" example
    3. Advertising
      • RSSI
      • Addresses
      • Address types
      • Advertising types
      • Bonding
    4. Advertising data
    5. Scan response data

Change Log 2016.03.14: Updated tutorial to suit SDK V11.0.0 and the possibility to use both nRF51 and nRF52 kits.

 

Equipment and software

To complete this tutorial you will need the following:

 

Other kits, dongles and software versions might work as well, but this is what I have used. This tutorial will not cover how to install and setup the software. Please search the forum if you run into trouble before posting questions here.

 

Necessary prior knowledge

It is expected that you have basic knowledge of how to use Keil, MCP and nRFgo Studio and how to download your application to your kit. Please browse the  Tutorial section  and the  Infocenter  to find guides on how to use your equipment and compile your first BLE application.  Here  is an excellent blogpost that I highly recommend you read. It provides a more in depth explanation on how advertising works and is a natural supplement to this tutorial.

 

If you run into troubles please browse devzone, look for documentation on our Infocenter, and read the user guides for your kits. I urge you to post any questions you might have on the forum and not below the tutorial. This makes it is easier for other users and Nordic employees to see and search for your question and you will actually most likely get a faster response(!).

The “Hello world” example

First thing first: download the example code from github. It is based on the template example found in the SDK V11.0.0, but stripped of all code that is not necessary for our purpose. There is still quite a lot of code left though, which is used to initiate and utilize processes running in the background. The code is not essential for this tutorial and can be left as is. If you are curious of what it is anyway then here are some links to documentation on some of the modules that are used in the code:

 

  1. The Device Manager. This is a module that handles active and bonded connections. Since this tutorial is about advertising and not connections it is not really relevant. Still I chose to leave it in the code as it is extensively used in more advanced examples, so I figured you might just as well get used to it being there and it doesn't do any harm.
  2. The Button Support Package (bsp). This module is used to handle the LEDs and the buttons. In this example you will notice that an LED is blinking when your board is advertising. After 180 seconds the board will stop advertising and go to sleep. Then you can push Button 1 and the board will wake up and start advertising again. All this is handled by the bsp module.
  3. Various _evt() and _dispatch() functions. These are functions that handle BLE and system events that originates in the Softdevice. They also allow your application to take various actions based on what is going on in the Softdevice. We will not dwell on these functions in this tutorial.

To compile the example download the files and copy the folder "nrf5x-ble-tutorial-advertising" to "your_SDK_folder\examples\ble_peripheral". Your main.c file should then be found in the folder "your_SDK_folder\examples\ble_peripheral\nrf5x-ble-tutorial-advertising". If you need help with this please have a look at this thread on devzone: Compiling github projects. Open the project file "ble_app_tutorial_advertising.uvprojx" and hit “Build”. It should compile without any errors or warnings.

 

Advertising

Now, let us have some fun right away. Make sure you have programmed the correct SoftDevice to your nRF5x DK kit and compiled the example successfully. Then hit the download button in Keil and load the example onto your kit as well. Open MCP and start discovery using your nRF51 Dongle as master emulator. To learn how to use MCP and a master emulator read this tutorial: Testing and using a simple BLE application. A device named “HelloWorld” should show up in the list of discovered devices as shown in the picture below.

What you see in the picture is:

    • The device name as defined in our main.c file. Try to search for #define DEVICE_NAME in your code and change the string to something of your own choice (just don’t make it too long). Now compile and download your application again and see how your device name has changed.
    • The Bluetooth Device Address. Similar to a Media Access Control address (MAC address), but not necessarily universally unique.
    • The Received Signal Strength Indicator (RSSI). This is a value of how good your signal strength is. Move your kit around or lay your hand over the PCB antenna on your kit and see how the RSSI changes.

 

The Advertising packet

Now expand the "HelloWorld" device tree by clicking on the little cross to the left. You should see something similar to the next image.  Your first advertising packet

 

What you see here is:

 

RSSI

The Received Signal
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值