IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
A (Short) Introduction to ZigBee
Christian Trodhandl
Embedded Computing Systems GroupVienna University of Technology
Europe
April 19, 2007
Trodhandl Introduction to ZigBee 1
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Outline
1 Introduction
2 Protocol OverviewNode TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
3 Atmel ZigBee NodesHardwareLibrary
4 Example Application
Trodhandl Introduction to ZigBee 2
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Outline
1 Introduction
2 Protocol OverviewNode TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
3 Atmel ZigBee NodesHardwareLibrary
4 Example Application
Trodhandl Introduction to ZigBee 3
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
The ZigBee standard for wireless sensor networks
Application domain: Personal Area Network (PAN).
Short range operation, low cost sensors, low powerconsumption.
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).
Trodhandl Introduction to ZigBee 4
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Outline
1 Introduction
2 Protocol OverviewNode TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
3 Atmel ZigBee NodesHardwareLibrary
4 Example Application
Trodhandl Introduction to ZigBee 5
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Different Node Types in a ZigBee Network
Full Function Device (FFD): Can communicate with everytype of device. A FFD can operate in three different modes:
PAN Coordinator: Sends beacon frames, provides routinginformation, manages short, network-specific addressesCoordinator: Acts as router.Normal device.
Reduced Function Device (RFD): Can only talk to a singleFFD.
Trodhandl Introduction to ZigBee 6
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Different Node Types in a ZigBee Network
Full Function Device (FFD): Can communicate with everytype of device. A FFD can operate in three different modes:
PAN Coordinator: Sends beacon frames, provides routinginformation, manages short, network-specific addresses
Coordinator: Acts as router.Normal device.
Reduced Function Device (RFD): Can only talk to a singleFFD.
Trodhandl Introduction to ZigBee 6
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Different Node Types in a ZigBee Network
Full Function Device (FFD): Can communicate with everytype of device. A FFD can operate in three different modes:
PAN Coordinator: Sends beacon frames, provides routinginformation, manages short, network-specific addressesCoordinator: Acts as router.
Normal device.
Reduced Function Device (RFD): Can only talk to a singleFFD.
Trodhandl Introduction to ZigBee 6
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Different Node Types in a ZigBee Network
Full Function Device (FFD): Can communicate with everytype of device. A FFD can operate in three different modes:
PAN Coordinator: Sends beacon frames, provides routinginformation, manages short, network-specific addressesCoordinator: Acts as router.Normal device.
Reduced Function Device (RFD): Can only talk to a singleFFD.
Trodhandl Introduction to ZigBee 6
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Different Node Types in a ZigBee Network
Full Function Device (FFD): Can communicate with everytype of device. A FFD can operate in three different modes:
PAN Coordinator: Sends beacon frames, provides routinginformation, manages short, network-specific addressesCoordinator: Acts as router.Normal device.
Reduced Function Device (RFD): Can only talk to a singleFFD.
Trodhandl Introduction to ZigBee 6
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Star Network
In the star topology, the PAN coordinator chooses a unique (withinits radio sphere of influence) PAN id. All attached nodes can onlytalk to the central PAN coordinator.
Trodhandl Introduction to ZigBee 7
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Peer-to-Peer Network
Within a peer-to-peer topology, each FFD can communicate withany other device within its range. A RFD may only communicatewith a single FFD at a given time.
Trodhandl Introduction to ZigBee 8
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Multi-Cluster Network
Larger networks may be established by forming multi-clustertopologies. Each cluster has a single cluster head that isresponsible for coordination within the cluster.
Trodhandl Introduction to ZigBee 9
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
The IEEE 802.15.4-2003/ZigBee Protocol Stack
The IEEE 802.15.4-2003 standard describes the physical andMAC layer.
ZigBee builds on the IEEE standard and defines the networkand application layer.
Trodhandl Introduction to ZigBee 10
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
The IEEE 802.15.4-2003/ZigBee Protocol Stack
The IEEE 802.15.4-2003 standard describes the physical andMAC layer.
ZigBee builds on the IEEE standard and defines the networkand application layer.
Trodhandl Introduction to ZigBee 10
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
The IEEE 802.15.4-2003/ZigBee Protocol Stack
The IEEE 802.15.4-2003 standard describes the physical andMAC layer.
ZigBee builds on the IEEE standard and defines the networkand application layer.
Trodhandl Introduction to ZigBee 10
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
The IEEE 802.15.4-2003/ZigBee Protocol Stack
The IEEE 802.15.4-2003 standard describes the physical andMAC layer.
ZigBee builds on the IEEE standard and defines the networkand application layer.
Trodhandl Introduction to ZigBee 10
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
The IEEE 802.15.4-2003/ZigBee Protocol Stack
The IEEE 802.15.4-2003 standard describes the physical andMAC layer.
ZigBee builds on the IEEE standard and defines the networkand application layer.
Trodhandl Introduction to ZigBee 10
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication 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), 916MHz (US)
Trodhandl Introduction to ZigBee 11
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication 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
Trodhandl Introduction to ZigBee 12
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Network (NWK) Layer
The lower level of the ZigBee protocol builds on the MAC layer ofIEEE 802.15.4.
Topology specific routing
Security
New device configuration
Network startup
Trodhandl Introduction to ZigBee 13
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Network (NWK) Layer (cont.)
Joining/leaving a network
Addressing
Neighbour discovery
Route discovery
Reception control
Trodhandl Introduction to ZigBee 14
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication 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
Trodhandl Introduction to ZigBee 15
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Addressing
Each ZigBee node has a unique 64 bit MAC address
Additionally the Coordinator maintains a table to map the 64bit addresses to network-specific 16 bit addresses
Within each node, the application can define up to 240Application endpoints.
Trodhandl Introduction to ZigBee 16
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Media Access (CSMA/CA)
The IEEE 802.15.4 standard describes the CSMA/CA mechanismto access the wireless channel:
A device that wishes to transmit data frames waits for arandom backoff.
If the channel is clear after the backoff, the data istransmitted.
If the channel is busy, the device waits for another randomperiod.
(Optional) Acknowledgment frames are sent immediately afterthe corresponding data frames without using the CSMA/CAmechanism.
Trodhandl Introduction to ZigBee 17
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication 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 attacheddevices, identifies the PAN, and describes the superframestructure.
Any device that wishes to send data uses the CSMA/CAmechanism, 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 thesuperframe.
Trodhandl Introduction to ZigBee 18
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Frame Types
The IEEE standard defines four different frame types:
A beacon frame: Sent by the coordinator to announce thenetwork and contains the superframe structure.
A data frame: Used for data transfer
An acknowledgment frame: To confirm the successfulreception of a frame.
A MAC command frame: For handling MAC peer entitycontrol transfers.
Trodhandl Introduction to ZigBee 19
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Service Primitives
Defines the communication between different layers of theprotocol:
Request: Passed from user to the underlying layer to initiate aservice.
Indication: To indicate an internal event that is significant tothe user.
Response: To complete a procedure invoked by an Indicationprimitive.
Confirm: Passed to the user application to convey the resultsof a previous service request.
Trodhandl Introduction to ZigBee 20
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Node TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
Service Primitives (cont.)
Trodhandl Introduction to ZigBee 21
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
HardwareLibrary
Outline
1 Introduction
2 Protocol OverviewNode TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
3 Atmel ZigBee NodesHardwareLibrary
4 Example Application
Trodhandl Introduction to ZigBee 22
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
HardwareLibrary
ATAVRRZ200 Demonstration Kit
The Atmel ATAVRRZ200 demonstration kit contains the followingcomponents:
Five ZigBee nodes, each equipped with an ATmega1281 8 bitAVR microcontroller and an AT86FR230 ratio controller.
Three buttons and three LEDs on each board.
Additional LCD board.
Power supply over battery.
USB programming adapter.
Trodhandl Introduction to ZigBee 23
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
HardwareLibrary
ATAVRRZ200 Demonstration Kit (cont.)
Trodhandl Introduction to ZigBee 24
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
HardwareLibrary
Interface between Microcontroller and transceiver
Microcontroller communicates with transceiver over SPIinterface.
Additionally, an interrupt and a timer clock is supplied to themicrocontroller.
Trodhandl Introduction to ZigBee 25
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
HardwareLibrary
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 theavr-gcc and iar C compiler.
Only IEEE 802.15.4-2003 support.
ZigBee layer has to be implemented within the application (noendpoint-to-endpoint support).
Library uses timer 1 with ICP.
Library calls (for request and response) are prefixed withwpan .
The application may define certain callback functions that areinvoked by the library (for confirm and indication events).This callback functions are prefixed with usr .
Trodhandl Introduction to ZigBee 26
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Outline
1 Introduction
2 Protocol OverviewNode TypesNetwork TopologyProtocol Stack ArchitectureCommunication between Nodes
3 Atmel ZigBee NodesHardwareLibrary
4 Example Application
Trodhandl Introduction to ZigBee 27
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Example device application
The following application code shows how to use the Atmel MAClibrary for implementing a device application.The application starts the MAC stack and associates with thecoordinator node. (Code snippets taken from the demos suppliedwith the Atmel MAC library, see disclaimer)
Trodhandl Introduction to ZigBee 28
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Including Header Files
/∗ I n c l u d e i n t e r r u p t . h f o r the s e i ( ) macro ∗/#inc lude < av 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 ∗/#inc lude ” wpan de f i n e s . h”
/∗ i e e e c o n s t . h ho l d s IEEE 8 0 2 . 1 5 . 4 c on s t a n t sand a t t r i b u t e d e f i n i t i o n s ∗/
#inc lude ” 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 ra l l l i b r a r y f u n c t i o n s ∗/
#inc lude ”wpan mac . h”
Trodhandl Introduction to ZigBee 29
IntroductionProtocol Overview
Atmel ZigBee NodesExample 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 ruc t{
u i n t 1 6 t d e v i c e s h o r t a d d r e s s ;u i n t 8 t coo rd add re s s mode ;u i n t 6 4 t c o o r d add r e s s ;u i n t 1 6 t pan i d ;u i n t 8 t l o g i c a l c h a n n e l ;u i n t 8 t msdu handle ;d e v i c e s t a t e t s t a t e ;
} d e v i c e s t a t u s t ;
s t a t i c d e v i c e s t a t u s t d s t a t u s ;
Trodhandl Introduction to ZigBee 30
IntroductionProtocol Overview
Atmel ZigBee NodesExample 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 eo f ( d s t a t u s ) ) ;/∗ i n i t IO po r t s . . . . ∗//∗ i n i t mac l a y e r ∗/wpan i n i t ( ) ;
SET STATE( INIT DONE ) ;/∗ enab l e i n t e r r u p t s ∗/s e i ( ) ;return ;
}
Trodhandl Introduction to ZigBee 31
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Define main user task
s t a t i c void sw i t c h t a s k ( void ){
/∗ do someth ing . . . ∗/
i f ( s end da ta ){
/∗ send data ∗/wpan mcpsdata addr t a i ;a i . SrcAddrMode = WPAN ADDRMODE SHORT;a i . SrcPANId = d s t a t u s . p an 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 s t a t u s . coo rd add re s s mode ;
Trodhandl Introduction to ZigBee 32
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Define main user task (cont.)
a i . DstPANId = d s t a t u s . p an i d ;a i . DstAddr = d s t a t u s . c o o r d add r e s s ;wpan mcps da ta r eque s t (&a i ,
d s t a t u s . msdu handle++,WPAN TXOPT ACK,( void ∗) & d s t a t u s . l ed ,s i z eo f ( u i n t 8 t ) ) ;
}return ;
}
Trodhandl Introduction to ZigBee 33
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Define a callback function for received data
void u s r mcp s d a t a i n d (wpan mcpsdata addr t ∗ pAddr In fo ,u i n t 8 t mpduLinkQual i ty ,u i n t 8 t Secu r i t yUse ,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) &&
( pAddr In fo−>DstPANId == d s t a t u s . p an i d ) ){
/∗ do someth ing wi th r e c e i v e d data ∗/}
}
Trodhandl Introduction to ZigBee 34
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Main function
i n t main ( void ){
a p p l i c a t i o n i n i t ( ) ;/∗ send r e s e t , scan r eque s t , . . . ∗/mac do r e s e t ( ) ;whi le (1 ){
whi le ( wpan task ( ) ){
/∗ s h o r t runn ing t a s k s ∗/}sw i t c h t a s k ( ) ; /∗ main u s e r t a s k ∗/
}}
Trodhandl Introduction to ZigBee 35
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Some References
IEEE.IEEE std 802.15.4-2003: Wireless medium access control (MAC) and physicallayer (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) RadioTransceiver User Guide.2325 Orchard Parkway, San Jose, California, July 2006.Available at http://www.atmel.com.
Trodhandl Introduction to ZigBee 36
IntroductionProtocol Overview
Atmel ZigBee NodesExample Application
Thank you for your attention!Questions?
Trodhandl Introduction to ZigBee 37
IntroductionProtocol Overview
Atmel ZigBee NodesExample 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 thefollowing conditions are met:1. Redistributions of source code must retain the above copyright notice, this list of conditions and the followingdisclaimer.2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and thefollowing 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 withoutspecific 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.
Trodhandl Introduction to ZigBee 38