54
Simple BLE sensor application using Nordic semi Shenzen– Aug 2013 John So

Shenzhen Noridqweeqwc_BLE Sensor App

Embed Size (px)

DESCRIPTION

eqweqweqw

Citation preview

Page 1: Shenzhen Noridqweeqwc_BLE Sensor App

Simple BLE sensor application

using Nordic semi

Shenzen– Aug 2013John So

Page 2: Shenzhen Noridqweeqwc_BLE Sensor App

Nordic BLE

Solutions

2Simple BLE Sensor Application

Page 3: Shenzhen Noridqweeqwc_BLE Sensor App

Nordic semi Bluetooth low energy devices

3Simple BLE Sensor Application

External

MCU

nRF8001 , Bluetooth Connectivity

solution.

Uses an external MCU for user

application. Visual editor for Bluetooth low energy

configuration. Drivers available for multiple MCUs.

nRF8002 , Bluetooth Proximity solution.

Single chip solution.

No software coding required.

Visual editor to do configuration.

nRF51822 and nRF51922 , Bluetooth low energy

and multi protocol solution

Single chip solution.

ARM Cortex-M0nRF51822

nRF51922

nRF8002

nRF8001

Page 4: Shenzhen Noridqweeqwc_BLE Sensor App

nRF8001

Feature Highlight

4Simple BLE Sensor Application

Page 5: Shenzhen Noridqweeqwc_BLE Sensor App

nRF8001

� Operates in the peripheral role

� Integrated Host stack

� Integrated Link Layer

� Qualified radio

Simple BLE Sensor Application

GATT Server GATT Client

ACI

External

MCU

Page 6: Shenzhen Noridqweeqwc_BLE Sensor App

nRF8001

6Simple BLE Sensor Application

External

MCU

nRF8001

ACI Command

ACI Event

� Simple ACI command and Event interface

� nRFgo Studio as the visual editor for creating

Bluetooth Services and Characteristics

� ACI drivers available for multiple MCU platforms

� Requires 5 lines for connection

� ACI is an SPI slave with additional handshake lines

Use the SPI master on your MCU or implement the SPI

in software

� MISO, MOSI, SCK, REQN (similar to a Chip

select), RDYN (nRF8001 is ready)

Page 7: Shenzhen Noridqweeqwc_BLE Sensor App

nRF8001

7Simple BLE Sensor Application

External

MCU

nRF8001

ACI Command

ACI Event

� Optional ACTIVE line to show when the nRF8001

radio is in use and the duration of use

� Optional DC-DC to reduce power consumption

� Optional 32 KHz Crystal (Can use the built-in 32 KHz

internal oscillator)

� Option to supply 16MHz clock from external source

and avoid using the 16MHz Crystal

Page 8: Shenzhen Noridqweeqwc_BLE Sensor App

nRF8001

8Simple BLE Sensor Application

� nRF8001 includes a GATT Server and GATT client

� ACI interfaces to the GATT Server and GATT

� Portable C Source code available for ACI library for porting

to your MCU. Implementations available on multiple MCU platforms

� Demo to Send/Receive Data from an Arduino board to the iPhone using the Bluetooth low energy Shield for Arduino

UART over BLE (proprietary Service)

� ACI Commands and Event used in UART over BLE

� ACI Setup

� ACI Connect

� ACI Pipe Status Event

� ACI Send Data

� ACI Data Received Event

GATT

Proprietary Service over

Generic Attribute Profile

Page 9: Shenzhen Noridqweeqwc_BLE Sensor App

Advertise

9BLE Simple Sensor application

Connect

nRF UART app for iOSnRF UART app for Samsung Galaxy S4

Send and Receive data

ArduinoBluetooth low energy shield (nRF8001)

nRF2740 and nRF2741 modules can

be used with the Arduino.

The modules are included with the

Nordic semi nRF8001 Development kit

Use the ble_uart_project _template in

Bluetooth low energy SDK

for Arduino

http://devzone.nordicsemi.com/arduino

Page 10: Shenzhen Noridqweeqwc_BLE Sensor App

nRF8002

features highlight

10Simple BLE Sensor Application

Page 11: Shenzhen Noridqweeqwc_BLE Sensor App

nRF8002

11Simple BLE Sensor Application

nRF8002

� Single chip solution for proximity solutions

� Link Loss, Immediate Alert, Battery, TX power Services

Find Me and Alert Notification Profiles

� 3 Digital Outputs, 1 PWM output

2 Digital Inputs (Buttons, LEDs, Buzzers and Vibration)

� No software coding required

� Configure with a Visual Editor (nRFgo Studio)

� Production settings generated from nRFgo Studio

� iOS app sample code available (nRF Proximity)

Page 12: Shenzhen Noridqweeqwc_BLE Sensor App

nRF8002 Development Kit

12Simple BLE Sensor Application

nRF8002

� • Fully functional Bluetooth low energy proximity tag

� • Buzzer

� • LEDs

� • Buttons

Page 13: Shenzhen Noridqweeqwc_BLE Sensor App

nRF51822

features highlight

13Simple BLE Sensor Application

Page 14: Shenzhen Noridqweeqwc_BLE Sensor App

nR

F5

18

22

Memory 256kB Flash, 16kB RAM

128kB Flash, 16kB RAM

Analog and

digital I/O

2x SPI Master, 2x 2-wire Master, UART, 10-bit ADC,

Quadrature Demodulator

System Peripherals 16-channel PPI, 128-bit AES ECB/CCM/AAR co-

processor, RNG, Temp sensor, Watchdog

Oscillators 16/32 MHz XO, 32kHz XO

16 MHz RC, 32kHz ± 250ppm RC

Timers / Counters 2 × 16-bit Timers, 1 × 24-bit Timer , 2 × 24-bit RTC

Power Supply (Supply range)

LDO (1.8 to 3.6V), LDO bypass (1.75 to 1.95V)

Buck DC/DC (2.1 to 3.6V)

Software stacks S110 -Bluetooth® low energy Softdevice

Gazell 2.4GHz RF (SDK)

Package options (GPIO count)

6x6mm 48-pin QFN (31)

3.5x3.8mm 62-ball WLCSP (32)

nRF51822 ICMulti-protocol Bluetooth® low energy / 2.4GHz RF SoC

Processor16 MHz 32-bit

ARM Cortex-M0 CPU

256kB/

128kB

Flash

AH

B Lite

bu

s

16kB

RAM

GPIO RadioMulti-protocol 2.4GHz

AP

B b

us

Oscillators

Power

Supply

Timers / Counters

Analog I/O

Digital I/O

System Peripherals

Page 15: Shenzhen Noridqweeqwc_BLE Sensor App

S110 Softdevice

S110 Bluetooth® low energy Software Stack

nR

F5

18

22

� Complete Bluetooth® low energy software stack� Production-ready, qualified stack� Controller, Host, Services and Profiles

� Peripheral and Broadcaster role

� S110 Softdevice � Controller

� Host stack up to GATT and GAP

� L2CAP, GATT and GAP APIs� Thread-safe, asynchronous and event driven API

� Memory isolation between application and protocol stack for robustness and security

� Pre-compiled hex

� nRF51 SDK� Services, profiles and example code

� Source code

� Support for non-concurrent multi-protocol with 2.4GHz RF protocols

nRF518xx SoC

SVC APIs

Link Layer

L2CAP

ATT

GATT

SMP

GAP

nRF518 SDK

Services and Profiles

S110 Software Stack

Page 16: Shenzhen Noridqweeqwc_BLE Sensor App

nRF518 SDK and Tool Chain

� Common SDK for nRF518xx ICs

� Software stacks

� S110 Bluetooth® low energy

� Gazell™ 2 Proprietary 2.4GHz RF

� Software Libraries

� Common for all nRF51 ICs

� ARM CMSIS (-CORE, -SVD, -DSP)

� Enhanced ShockBurst™ API

� Keil™ MDK-ARM tool chain

� IDE, Compiler, Programming, debug

and simulation

� Free -Lite edition up to 32kB code

nR

F5

18

22

nRF518 SDK

Bluetooth® low

energy

Services and Profiles

nRF518xx SoC

S110 Softdevice

Gazell 2

Protocols

Softdevice API

S110 Software Stack Gazell 2 Software

Stack

Driv

ers

Software Libraries

(Common nRF51 ICs)

ARM CMSIS

Example application code

ES

B A

PI

Page 17: Shenzhen Noridqweeqwc_BLE Sensor App

17

nRF51 Solution: IO signals can use any pin (Pin Crossbar)

� Low cost 2 layer PCBs are possible

� Simple layout of external components

nRF51 Solution: SoftDevice power management API

� 1 API call will make your application low power

nRF51 Solution: Programmable Peripheral Interconnect (PPI)

� True real-time system

nRF51 Solution: Direct transfer between peripherals and RAM (EasyDMA)

� No CPU or code required to copy packet data

Page 18: Shenzhen Noridqweeqwc_BLE Sensor App

18

Problem: Application and stack code are dependent

� Re-linking the application changes the protocol stack

� Longer development time and more testing required

Application

Segment

Stack Segment

Memory Map

Re-link

Application

Linkable Libraries

Page 19: Shenzhen Noridqweeqwc_BLE Sensor App

19

nRF51 Solution: SoftDevice Architecture

� Application program is isolated from the protocol stack

� Application developer does not need to re-link the protocol stack

Application

Segment

Stack Segment

Memory Map

Re-link

Application

SoftDevice

Page 20: Shenzhen Noridqweeqwc_BLE Sensor App

20

nRF51 Solution: Automated power management

� 2 modes: ON and OFF

� Peripherals only use power when they need power

OFFON

Page 21: Shenzhen Noridqweeqwc_BLE Sensor App

nRF51822Development and

Evaluation Kit

21Simple BLE Sensor Application

Page 22: Shenzhen Noridqweeqwc_BLE Sensor App

nRF51822 Development Kit

nR

F5

18

22

� Interfaces to existing nRFgo platform

� nRFgo available separately and required

� Fully featured for full system development

� Range of I/O options via nRFgo motherboard

� RF-stable development platform

� Enables detailed measurement & test

� Current measurements

� RF measurements using SMA connector

� USB dongle for easy PC interface and debug

Module: PCB antenna

Module: SMA connector

USB dongle

Page 23: Shenzhen Noridqweeqwc_BLE Sensor App

nRF51822 Evaluation Kit

� Flexible evaluation and development

platform

� Stand-alone battery-powered system

� Portable system development

� Integrated debugger

� USB dongle for easy PC interface and

debug

nR

F5

18

22

Eval-board

Page 24: Shenzhen Noridqweeqwc_BLE Sensor App

nRF51822

Application Example

24Simple BLE Sensor Application

Page 25: Shenzhen Noridqweeqwc_BLE Sensor App

nRF51822

Application Example

25Simple BLE Sensor Application

Page 26: Shenzhen Noridqweeqwc_BLE Sensor App

Application Example : Simple BLE sensor

26Simple BLE Sensor Application

GAPGATT

ATT SMP

L2CAP

Link Layer (LL)

Physical Layer (PHY)

Ba

ttery

He

art R

ate

Connect

Co

ntro

ller

Ho

stP

rofile

s +

Ap

plica

tion

Application

Ap

plica

tion

Driv

ers

Button Wakeup

LED

Pro

files

Battery Level Sample

Advertise

Inc. BPM Dec. BPM

SoftDevice API

So

ftDe

vice

ma

na

ge

r

So

Clib

rary

S1

10

BLE

So

ftDe

vice

Page 27: Shenzhen Noridqweeqwc_BLE Sensor App

nRF51822

App Drivers

27Simple BLE Sensor Application

Page 28: Shenzhen Noridqweeqwc_BLE Sensor App

28Simple BLE Sensor Application

GAPGATT

ATT SMP

L2CAP

Link Layer (LL)

Physical Layer (PHY)

Ba

ttery

He

art R

ate

Application

Ap

plica

tion

Driv

ers

SoftDevice API

So

ftDe

vice

ma

na

ge

r

So

Clib

rary

Application drivers

Page 29: Shenzhen Noridqweeqwc_BLE Sensor App

Application drivers block diagram

29Simple BLE Sensor Application

GPIO PINCPU

PPI Controller

Timer

GPIOTE PIN

Event

Pin State

Page 30: Shenzhen Noridqweeqwc_BLE Sensor App

Part 1: Output – LED

What do we want?

� Drive output without CPU (LED flash)

� Using a Timer, PPI and GPIOTE

30Simple BLE Sensor Application

CPU

PPI Controller

Timer

GPIOTE PIN

CLEAR

COMPARE

GPIO

Page 31: Shenzhen Noridqweeqwc_BLE Sensor App

Part 1: Timer configuration

31Simple BLE Sensor Application

Timer [1]CLEAR

COMPARE [0]

Page 32: Shenzhen Noridqweeqwc_BLE Sensor App

Part 2: Input – Button wakeup

� Button wakeup from System OFF

� Using GPIO sense / DETECT

� Configure the LED on wakeup

32Simple BLE Sensor Application

CPU GPIO PINDETECT

Page 33: Shenzhen Noridqweeqwc_BLE Sensor App

Part 2: GPIO configuration

33Simple BLE Sensor Application

PIN0

OUT.0

IN.0

PIN0

IN

Sense

OUT_OVERRIDE

DIR_OVERRIDE

DETECT

OUT

O

I

O: output buffer I: input buffer

PIN_CNF[0].INPUT

PIN_CNF[0].PULL

PIN_CNF[0].DRIVE

PIN0_CNF.SENSE

PIN_CNF[0].DIR

INPUT_OVERRIDE

GPIO PIN ??

Page 34: Shenzhen Noridqweeqwc_BLE Sensor App

nRF51822

SoftDevice

34Simple BLE Sensor Application

Page 35: Shenzhen Noridqweeqwc_BLE Sensor App

nRF51 SoftDevice Architecture

� Application

� nRF51 Softdevice

� Pre-compiled binary implementing

wireless protocols

� Service (system) Call (SVC) based APIs

� 100% event-driven

� No RTOS dependencies

� Run-time protection

� No link time dependencies w/ user

application

35Simple BLE Sensor Application

GAPGATT

ATT SMP

L2CAP

Link Layer (LL)

Physical Layer (PHY)

Ba

ttery

He

art R

ate

Application

Ap

plica

tion

Driv

ers

SoftDevice API

So

ftDe

vice

ma

na

ge

r

So

Clib

rary

Page 36: Shenzhen Noridqweeqwc_BLE Sensor App

SoftDevice Architecture Benefits

36Simple BLE Sensor Application

Flexibility � No proprietary application development model or RTOS

� The Application and Stack can be updated (programmed)

separately

Ease of Development � Simple Application programmer model with no link time

dependencies

� Stack is not re-linked constantly during application

development

� Can use the free ARM MDK-Lite when application code is

less than 32Kbytes

Code safety � QA and qualification on binary going into end-user

product

� Thread-safe API

� Stack is run-time protected

� Reduced risk of Applications bugs affecting the Stack

Page 37: Shenzhen Noridqweeqwc_BLE Sensor App

Application Programming Model

37Simple BLE Sensor Application

RAM

Softdevice

Region 0

Application

Region 1

RAM_R1_BASE

0x2000 0000

0x2000 0000 +

SizeOfRAM*MSP initial value -

Call Stack

Page 38: Shenzhen Noridqweeqwc_BLE Sensor App

Interrupt forwarding, SoftDevice to Application

38Simple BLE Sensor Application

Page 39: Shenzhen Noridqweeqwc_BLE Sensor App

Softdevice

Application

Application Vector Table

System / Softdevice Vector Table

&SVC_Handler

CLENR0

CLENR0 +

0x0000 00C0

{

#include softdevice.h

...

int tmp = __SVC(X) ble_function_0(a,b,c,d)

...

}

SVC_Handler

switch (SVC_number)

case X:

Ret = ble_function_0 (arg0, arg1, arg2, arg3)

int ble_function (arg0, arg1, arg2, arg3)

{ return(ret0); }

API call using SVC from Application to SoftDevice

39Simple BLE Sensor Application

CPU-generated interrupt to

the SoftDevice SVC_Handler

Page 40: Shenzhen Noridqweeqwc_BLE Sensor App

Softdevice@Run-time

� Cortex M0 has 4 interrupt priorities

� SoftDevice uses 2 priorities to

implement its event-driven behavior

� Lower Stack (BLE Link Layer),

� Upper Stack (SVC API, BLE Host)

� Application have access to 2

priorities

� Application High – for critical

interrupts where low latency is

required. Cannot call the SVC API.

� Application Low. Used for Host

events.

40Simple BLE Sensor Application

Page 41: Shenzhen Noridqweeqwc_BLE Sensor App

41Simple BLE Sensor Application

Softdevice@Run-time

� API Calls

� Made from MAIN & App(L)

� Protocol Event

� Signaling from LowerStack done with

chained interrupts

Page 42: Shenzhen Noridqweeqwc_BLE Sensor App

Softdevice HW block protection

42Simple BLE Sensor Application

ARM

Cortex M0

Debugger

GPIO

WDT

GPIOTE

SPI

NVMC

AH

B-L

ite

Radio

Timer [0]

RTC

ECB

Radio

RTC [1]

ECB

Timer [1]

RTC [0]

Timer [2]

Timer [0]

Application has Open

access

SoftDevice Restricts

or Blocks access

SoftDevice: DISABLEDSoftDevice: ENABLED

Page 43: Shenzhen Noridqweeqwc_BLE Sensor App

Working with the SoftDevice

� Applications running with the SoftDevice must be programmed into Region 1 flash

� The SoftDevice will reserve RAM and sandbox some peripheral interfaces

� All “Restricted” peripherals must now be accessed via the nrf_ SVC API

� A Hard Fault will occur if the application accesses the registers via CMSIS directly

43Simple BLE Sensor Application

Page 44: Shenzhen Noridqweeqwc_BLE Sensor App

44Simple BLE Sensor Application

GAPGATT

ATT SMP

L2CAP

Link Layer (LL)

Physical Layer (PHY)

Ba

ttery

He

art R

ate

Application

Ap

plica

tion

Driv

ers

SoftDevice API

So

ftDe

vice

ma

na

ge

r

So

Clib

rary

Bluetooth® low energy API

Page 45: Shenzhen Noridqweeqwc_BLE Sensor App

� Generic Access Profile (GAP)

� Generic Attribute Profile Server (GATTS)

� API calls as SuperVisor Calls

� Switches Core to SV priority

� Each SV Call numbered

� Events as SoftWare Interrupts

� Always through SWI2

� Interrupt priority: Level 0

� ble_evt_get()

� For all BLE events

� From ISR or main context

45Simple BLE Sensor Application

Application

GAP API GATTS API

SVC SVCSWI2

ble_evt_get()

Bluetooth® low energy API

Page 46: Shenzhen Noridqweeqwc_BLE Sensor App

BLE API: GAP

46Simple BLE Sensor Application

GAP

ConnectionSVC

EVT

GAP ServiceSVC

Device Name

Appearance

PPCP

AdvertiserSVC

EVTAdv Data

SecuritySVC

EVT

Keys

Page 47: Shenzhen Noridqweeqwc_BLE Sensor App

BLE API: Connection Sequence

47Simple BLE Sensor Application

App BLE Stack Central

BLE_GAP_EVT_CONNECTED

BLE_GAP_EVT_DISCONNECTED

ble_gap_adv_start()

Adv DataAdv Data

scan()

ble_gap_adv_data_set() Adv Data

connect()

disconnect()ble_gap_disconnect()

Page 48: Shenzhen Noridqweeqwc_BLE Sensor App

BLE API: GATTS

48Simple BLE Sensor Application

GATTSATT Table Population

and Local Access

SVC

EVT GATT hierarchy

enforcement

SVC

EVT

ATT Protocol

Server Initiated (HVx)

ATT Table Access

Control

ATT Table

Service

Char.

Char.

Service

Char.

Char.

Page 49: Shenzhen Noridqweeqwc_BLE Sensor App

BLE API: Service population

49Simple BLE Sensor Application

App BLE Stack

Handle UUID Value

ble_gatts_characteristic_add(HSL, FINGER)

0x0004 CHAR HSL

0x0005 HSL FINGER

ble_gatts_characteristic_add(HRM, 80bpm)

0x0002 CHAR HRM

0x0003 HRM 80bpm

ble_gatts_service_add(HRS)

0x0001 SERVICE HRS

Page 50: Shenzhen Noridqweeqwc_BLE Sensor App

BLE API: Service Discovery - Enabling Notifications

50Simple BLE Sensor Application

App BLE Stack Central

ATT Table

HVN ATT Packet 87

HRM Char.

80bpm83bpm87bpm

ATT Write Request (enable Notifications)

ATT Write Response

ble_gatts_hvx(0x0003, 87bpm )

Notifications

Service

Discovery

BLE_GATT_EVT_WRITE (WRITE_REQ,

data=enable Notifications)

Page 51: Shenzhen Noridqweeqwc_BLE Sensor App

Application block diagram

51Simple BLE Sensor Application

GPIOPIN

CPUApp Timer

Event

PIN

READ

ADCCPU operation

SEND NOTIFICATION

GAPGATT

ATT SMP

L2CAP

Link Layer (LL)

Physical Layer (PHY)

SoftDevice API

So

ftDe

vice

ma

na

ge

r

So

Clib

rary

Page 52: Shenzhen Noridqweeqwc_BLE Sensor App

Application block diagram

52Simple BLE Sensor Application

MAIN

Program

BLE Stack

process

BLE Event

process

Button

SampleHRS Notify

Battery

Notify

Application

Interrupt

BLE Stack Interrupt

BLE Event Interrupt

(SWI)

Page 53: Shenzhen Noridqweeqwc_BLE Sensor App

DEMO

Shenzen– Aug 2013John So

Page 54: Shenzhen Noridqweeqwc_BLE Sensor App

Simple BLE sensor application

using Nordic semi

Shenzen– Aug 2013John So