Sei sulla pagina 1di 46

Introduction

Protocol Overview
Atmel ZigBee Nodes
Example Application

A (Short) Introduction to ZigBee

Christian Trödhandl

Embedded Computing Systems Group


Vienna University of Technology
Europe

April 19, 2007

Trödhandl Introduction to ZigBee 1


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Outline

1 Introduction

2 Protocol Overview
Node Types
Network Topology
Protocol Stack Architecture
Communication between Nodes

3 Atmel ZigBee Nodes


Hardware
Library

4 Example Application

Trödhandl Introduction to ZigBee 2


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Outline

1 Introduction

2 Protocol Overview
Node Types
Network Topology
Protocol Stack Architecture
Communication between Nodes

3 Atmel ZigBee Nodes


Hardware
Library

4 Example Application

Trödhandl Introduction to ZigBee 3


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

The ZigBee standard for wireless sensor networks

Application domain: Personal Area Network (PAN).


Short range operation, low cost sensors, low power
consumption.
Topology: Star or Peer-to-Peer.
Access control: Beacon or CSMA/CA.
Reliable data transfer.
Data rates: 250 kb/s (2450 MHz band), 40 kb/s (915 MHz),
20 kb/s (868 MHz).

Trödhandl Introduction to ZigBee 4


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Outline

1 Introduction

2 Protocol Overview
Node Types
Network Topology
Protocol Stack Architecture
Communication between Nodes

3 Atmel ZigBee Nodes


Hardware
Library

4 Example Application

Trödhandl Introduction to ZigBee 5


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Different Node Types in a ZigBee Network

Full Function Device (FFD): Can communicate with every


type of device. A FFD can operate in three different modes:

Trödhandl Introduction to ZigBee 6


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Different Node Types in a ZigBee Network

Full Function Device (FFD): Can communicate with every


type of device. A FFD can operate in three different modes:
PAN Coordinator: Sends beacon frames, provides routing
information, manages short, network-specific addresses

Trödhandl Introduction to ZigBee 6


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Different Node Types in a ZigBee Network

Full Function Device (FFD): Can communicate with every


type of device. A FFD can operate in three different modes:
PAN Coordinator: Sends beacon frames, provides routing
information, manages short, network-specific addresses
Coordinator: Acts as router.

Trödhandl Introduction to ZigBee 6


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Different Node Types in a ZigBee Network

Full Function Device (FFD): Can communicate with every


type of device. A FFD can operate in three different modes:
PAN Coordinator: Sends beacon frames, provides routing
information, manages short, network-specific addresses
Coordinator: Acts as router.
Normal device.

Trödhandl Introduction to ZigBee 6


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Different Node Types in a ZigBee Network

Full Function Device (FFD): Can communicate with every


type of device. A FFD can operate in three different modes:
PAN Coordinator: Sends beacon frames, provides routing
information, manages short, network-specific addresses
Coordinator: Acts as router.
Normal device.
Reduced Function Device (RFD): Can only talk to a single
FFD.

Trödhandl Introduction to ZigBee 6


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Star Network

In the star topology, the PAN coordinator chooses a unique (within


its radio sphere of influence) PAN id. All attached nodes can only
talk to the central PAN coordinator.

Trödhandl Introduction to ZigBee 7


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Peer-to-Peer Network

Within a peer-to-peer topology, each FFD can communicate with


any other device within its range. A RFD may only communicate
with a single FFD at a given time.

Trödhandl Introduction to ZigBee 8


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Multi-Cluster Network

Larger networks may be established by forming multi-cluster


topologies. Each cluster has a single cluster head that is
responsible for coordination within the cluster.

Trödhandl Introduction to ZigBee 9


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

The IEEE 802.15.4-2003/ZigBee Protocol Stack


The IEEE 802.15.4-2003 standard describes the physical and
MAC layer.

Trödhandl Introduction to ZigBee 10


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

The IEEE 802.15.4-2003/ZigBee Protocol Stack


The IEEE 802.15.4-2003 standard describes the physical and
MAC layer.

Trödhandl Introduction to ZigBee 10


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

The IEEE 802.15.4-2003/ZigBee Protocol Stack


The IEEE 802.15.4-2003 standard describes the physical and
MAC layer.
ZigBee builds on the IEEE standard and defines the network
and application layer.

Trödhandl Introduction to ZigBee 10


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

The IEEE 802.15.4-2003/ZigBee Protocol Stack


The IEEE 802.15.4-2003 standard describes the physical and
MAC layer.
ZigBee builds on the IEEE standard and defines the network
and application layer.

Trödhandl Introduction to ZigBee 10


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

The IEEE 802.15.4-2003/ZigBee Protocol Stack


The IEEE 802.15.4-2003 standard describes the physical and
MAC layer.
ZigBee builds on the IEEE standard and defines the network
and application layer.

Trödhandl Introduction to ZigBee 10


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Physical (PHY) Layer

The physical layer is responsible for:


Activation/Deactivation of transceiver.
Channel selection, assessment.
Transmission and reception of packets.
Frequency bands: 2.4 GHz (worldwide), 868 MHz (EU), 916
MHz (US)

Trödhandl Introduction to ZigBee 11


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Medium Access Control (MAC) Layer

The following services are provided by the MAC layer:


Beacon management
Channel access
Guaranteed Time Slot (GTS) management
Frame validation
Acknowledgment
Association, disassociation

Trödhandl Introduction to ZigBee 12


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Network (NWK) Layer

The lower level of the ZigBee protocol builds on the MAC layer of
IEEE 802.15.4.
Topology specific routing
Security
New device configuration
Network startup

Trödhandl Introduction to ZigBee 13


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Network (NWK) Layer (cont.)

Joining/leaving a network
Addressing
Neighbour discovery
Route discovery
Reception control

Trödhandl Introduction to ZigBee 14


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Application Layer

The application layer provides the following services:


Maintain tables for binding
Fragmentation, reassembly and reliable data transport
Provide communication endpoints for the application
Discovering devices and application services.
Initiating/responding to binding requests between endpoints

Trödhandl Introduction to ZigBee 15


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Addressing

Each ZigBee node has a unique 64 bit MAC address


Additionally the Coordinator maintains a table to map the 64
bit addresses to network-specific 16 bit addresses
Within each node, the application can define up to 240
Application endpoints.

Trödhandl Introduction to ZigBee 16


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Media Access (CSMA/CA)

The IEEE 802.15.4 standard describes the CSMA/CA mechanism


to access the wireless channel:
A device that wishes to transmit data frames waits for a
random backoff.
If the channel is clear after the backoff, the data is
transmitted.
If the channel is busy, the device waits for another random
period.
(Optional) Acknowledgment frames are sent immediately after
the corresponding data frames without using the CSMA/CA
mechanism.

Trödhandl Introduction to ZigBee 17


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Beacon Mode

The network may also utilize the so-called beacon mode:


A round (superframe) is divided into 16 equally sized slots.
Coordinator regularly sends beacon frames in the first slot.
The beacon frames are used to synchronize the attached
devices, identifies the PAN, and describes the superframe
structure.
Any device that wishes to send data uses the CSMA/CA
mechanism, but aligns the sent frames to the slots.
The PAN coordinator may assign guaranteed time slots (GTS)
to devices for low-latency or fixed data bandwidth.
Up to 7 GTS can be allocated in this way at the end of the
superframe.

Trödhandl Introduction to ZigBee 18


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Frame Types

The IEEE standard defines four different frame types:


A beacon frame: Sent by the coordinator to announce the
network and contains the superframe structure.
A data frame: Used for data transfer
An acknowledgment frame: To confirm the successful
reception of a frame.
A MAC command frame: For handling MAC peer entity
control transfers.

Trödhandl Introduction to ZigBee 19


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Service Primitives

Defines the communication between different layers of the


protocol:
Request: Passed from user to the underlying layer to initiate a
service.
Indication: To indicate an internal event that is significant to
the user.
Response: To complete a procedure invoked by an Indication
primitive.
Confirm: Passed to the user application to convey the results
of a previous service request.

Trödhandl Introduction to ZigBee 20


Introduction Node Types
Protocol Overview Network Topology
Atmel ZigBee Nodes Protocol Stack Architecture
Example Application Communication between Nodes

Service Primitives (cont.)

Trödhandl Introduction to ZigBee 21


Introduction
Protocol Overview Hardware
Atmel ZigBee Nodes Library
Example Application

Outline

1 Introduction

2 Protocol Overview
Node Types
Network Topology
Protocol Stack Architecture
Communication between Nodes

3 Atmel ZigBee Nodes


Hardware
Library

4 Example Application

Trödhandl Introduction to ZigBee 22


Introduction
Protocol Overview Hardware
Atmel ZigBee Nodes Library
Example Application

ATAVRRZ200 Demonstration Kit

The Atmel ATAVRRZ200 demonstration kit contains the following


components:
Five ZigBee nodes, each equipped with an ATmega1281 8 bit
AVR microcontroller and an AT86FR230 ratio controller.
Three buttons and three LEDs on each board.
Additional LCD board.
Power supply over battery.
USB programming adapter.

Trödhandl Introduction to ZigBee 23


Introduction
Protocol Overview Hardware
Atmel ZigBee Nodes Library
Example Application

ATAVRRZ200 Demonstration Kit (cont.)

Trödhandl Introduction to ZigBee 24


Introduction
Protocol Overview Hardware
Atmel ZigBee Nodes Library
Example Application

Interface between Microcontroller and transceiver

Microcontroller communicates with transceiver over SPI


interface.
Additionally, an interrupt and a timer clock is supplied to the
microcontroller.

Trödhandl Introduction to ZigBee 25


Introduction
Protocol Overview Hardware
Atmel ZigBee Nodes Library
Example Application

Atmel MAC Library for AT86RF230 transmitters

Atmel supplies a programming library for its transceiver modules:


The library is called libl2 rdk230 rel.a and is available for the
avr-gcc and iar C compiler.
Only IEEE 802.15.4-2003 support.
ZigBee layer has to be implemented within the application (no
endpoint-to-endpoint support).
Library uses timer 1 with ICP.
Library calls (for request and response) are prefixed with
wpan .
The application may define certain callback functions that are
invoked by the library (for confirm and indication events).
This callback functions are prefixed with usr .

Trödhandl Introduction to ZigBee 26


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Outline

1 Introduction

2 Protocol Overview
Node Types
Network Topology
Protocol Stack Architecture
Communication between Nodes

3 Atmel ZigBee Nodes


Hardware
Library

4 Example Application

Trödhandl Introduction to ZigBee 27


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Example device application

The following application code shows how to use the Atmel MAC
library for implementing a device application.
The application starts the MAC stack and associates with the
coordinator node. (Code snippets taken from the demos supplied
with the Atmel MAC library, see disclaimer)

Trödhandl Introduction to ZigBee 28


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Including Header Files

/∗ I n c l u d e i n t e r r u p t . h f o r t h e s e i ( ) macro ∗/
#i n c l u d e < a v r / i n t e r r u p t . h>

/∗ d e f i n e s f o r demo a p p l i c a t i o n s ∗/
#i n c l u d e ” w p a n d e f i n e s . h”

/∗ i e e e c o n s t . h h o l d s IEEE 8 0 2 . 1 5 . 4 c o n s t a n t s
and a t t r i b u t e d e f i n i t i o n s ∗/
#i n c l u d e ” i e e e c o n s t . h”

/∗ wpan mac . h i n c l u d e s f u n c t i o n d e f i n i t i o n s f o r
a l l l i b r a r y f u n c t i o n s ∗/
#i n c l u d e ” wpan mac . h”

Trödhandl Introduction to ZigBee 29


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Define a variable to hold our status

/∗ d e f i n e s t a t u s v a r i a b l e ∗/
typedef s t r u c t
{
uint16 t device short address ;
u i n t 8 t coord address mode ;
uint64 t coord address ;
uint16 t pan id ;
uint8 t logical channel ;
u i n t 8 t msdu handle ;
device state t state ;
} device status t ;

static device status t d status ;

Trödhandl Introduction to ZigBee 30


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Function to initialize the application

/∗ d e f i n e s t a t u s v a r i a b l e ∗/
s t a t i c void a p p l i c a t i o n i n i t ( void )
{
/∗ r e s e t g l o b a l a p p l i c a t i o n s t a t u s v a r i a b l e ∗/
memset(& d s t a t u s , 0 , s i z e o f ( d s t a t u s ) ) ;
/∗ i n i t IO p o r t s . . . . ∗/
/∗ i n i t mac l a y e r ∗/
wpan init ();

SET STATE ( INIT DONE ) ;


/∗ e n a b l e i n t e r r u p t s ∗/
sei ();
return ;
}
Trödhandl Introduction to ZigBee 31
Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Define main user task

s t a t i c void s w i t c h t a s k ( void )
{
/∗ do s o m e t h i n g . . . ∗/

i f ( send data )
{
/∗ s e n d d a t a ∗/
wpan mcpsdata addr t a i ;
a i . SrcAddrMode = WPAN ADDRMODE SHORT;
a i . SrcPANId = d s t a t u s . p a n i d ;
a i . SrcAddr = d s t a t u s . d e v i c e s h o r t a d d r e s s ;
a i . DstAddrMode =
d status . coord address mode ;

Trödhandl Introduction to ZigBee 32


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Define main user task (cont.)

a i . DstPANId = d s t a t u s . p a n i d ;
a i . DstAddr = d s t a t u s . c o o r d a d d r e s s ;
w p a n m c p s d a t a r e q u e s t (& a i ,
d s t a t u s . m s d u h a n d l e ++,
WPAN TXOPT ACK,
( void ∗) & d s t a t u s . led ,
sizeof ( uint8 t ));
}
return ;
}

Trödhandl Introduction to ZigBee 33


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Define a callback function for received data

void u s r m c p s d a t a i n d (
wpan mcpsdata addr t ∗ pAddrInfo ,
u i n t 8 t mpduLinkQuality ,
uint8 t SecurityUse ,
u i n t 8 t ACLEntry , u i n t 8 t msduLength ,
u i n t 8 t ∗ msdu )
{
i f ( ( d s t a t u s . s t a t e == RUN) &&
( p A d d r I n f o −>DstPANId == d s t a t u s . p a n i d ) )
{
/∗ do s o m e t h i n g w i t h r e c e i v e d d a t a ∗/
}
}

Trödhandl Introduction to ZigBee 34


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Main function

i n t main ( v o i d )
{
application init ();
/∗ s e n d r e s e t , s c a n r e q u e s t , . . . ∗/
mac do reset ( ) ;
while (1)
{
while ( wpan task ( ) )
{
/∗ s h o r t r u n n i n g t a s k s ∗/
}
s w i t c h t a s k ( ) ; /∗ main u s e r t a s k ∗/
}
}
Trödhandl Introduction to ZigBee 35
Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Some References
IEEE.
IEEE std 802.15.4-2003: Wireless medium access control (MAC) and physical
layer (PHY) specifications for low-rate wireless personal area networks
(LR-WPANs).
Specification, IEEE, October 2003.
Available at http://www.ieee802.org.
ZigBee Alliance.
ZigBee specification.
Specification, ZigBee Alliance, December 2006.
Available at http://www.zigbee.org.
Atmel.
IEEE 802.15.4 MAC User Guide.
2325 Orchard Parkway, San Jose, California, September 2006.
Available at http://www.atmel.com.
Atmel.
ATAVRRZ200 Demonstartion Kit AT86RF230 (2450 MHz band) Radio
Transceiver User Guide.
2325 Orchard Parkway, San Jose, California, July 2006.
Available at http://www.atmel.com.
Trödhandl Introduction to ZigBee 36
Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Thank you for your attention!


Questions?

Trödhandl Introduction to ZigBee 37


Introduction
Protocol Overview
Atmel ZigBee Nodes
Example Application

Sourcecode Disclaimer
Copyright (C) 2006, Atmel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other materials provided with the distribution.
3. The name of ATMEL may not be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL ”AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,

INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS

FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL

ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR

CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE

GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER

CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Trödhandl Introduction to ZigBee 38

Potrebbero piacerti anche