Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

10

Click here to load reader

description

This paper describes how to create a ZigBeeSmart Energy Device using the MSP430F54xxas the host application processor to theCC2530-ZNP (ZigBee Pro Network Processor).

Transcript of Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

Page 1: Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

Introduction

This paper describes how to create a ZigBee

Smart Energy Device using the MSP430F54xx

as the host application processor to the

CC2530-ZNP (ZigBee Pro Network Proces-

sor). The physical interface between the

MSP430 and the CC2530-ZNP is discussed,

as well as the software application frame-

work used to drive the CC2530-ZNP. This

paper assumes that the reader is familiar

with basic ZigBee concepts and terminology.

The CC2530-ZNP contains the core

ZigBee Pro stack and exposes API interfac-

es to the host processor for configuration of

the stack and data transfer. In the sample

application installer that is provided by TI,

these APIs are abstracted by an application

framework called the ZAP (ZigBee Applica-

tion Processor) framework, which makes it

easy for an application developer to write

sophisticated ZigBee Smart Energy applica-

tions, among others (e.g., Home Automa-

tion and manufacturer-specific profiles).

TI has provided an extensive framework to

make application development easy and

thus re-use of this application framework

is highly encouraged. However, for appli-

cation developers that choose to use the

CC2530-ZNP but still want to build their

application framework from the ground up,

the ZigBee Smart Energy sample applica-

tion suite serves as great reference code

of how to interface with the CC2530-ZNP.

Creating a ZigBee® Smart Energy Device with the MSP430F54xx and the CC2530-ZNP (ZigBee Pro Network Processor)

Physical interface and development platformAlthough the CC2530-ZNP supports UART, USB, and SPI interfaces, we’ll be discussing

use of the SPI interface. Table 1 shows the recommended pin connection between the host

processor and the CC2530-ZNP, which matches the interconnect used by the EXP430F5438

Experimenter Board where the MSP430F5438 USCI B0 is used in 3-wire SPI mode.

To test this connection, one can obtain a CC2530EMK [which contains 2× CC2530 evalu-

ation modules (EMs)] and 2× EXP430F5438 Experimenter Boards separately. This setup is

shown in Figure 1 on the following page. One will also need the SmartRF05EB board which

is used to program the CC2530EM modules. The SmartRF05EB board comes included with

either the CC2530DK, CC2530ZDK, or CC2520DK.

Zin Kyaw,Systems Application Engineer

Texas Instruments

W H I T E P A P E R

MSP430F5438 Direction CC2530-ZNP Direction

P3.0 Out P1.4 (SS) In

P3.1 (UCB0SIMO) Out P1.6 (MOSI) In

P3.2 (UCB0SOMI) In P1.7 (MISO) Out

P3.3 (UCB0CLK) Out P1.5 (SCLK) In

P1.2 Out RESET_N In

P1.4 In P0.4 (SRDY) Out

P1.6 Out P0.3 (MRDY) In

P8.2 OutP2.0 (CFG1, driven HIGH for SPI transport)

In

N/CConfigured as input with pull-up

P1.2 (CFG0) In

Table 1. MSP430F5438 to CC2530-ZNP interconnect.

Page 2: Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

Creating a ZigBee® Smart Energy Device with the MSP430F54xx and the CC2530-ZNP January 2010

(ZigBee Pro Network Processor)

2 Texas Instruments

The software application framework is built upon the OSAL (Operating System Abstraction Layer) operat-

ing system (see reference [2] for more information) from TI. OSAL provides services for task management,

power management, non-volatile memory, dynamic memory management, software timers, event generation,

inter- and intra-task messaging (or message queues), and a seamless interface to the layer that abstracts

the board support package (BSP) called the Hardware Abstraction Layer (HAL). The ZAP framework re-uses

the architecture of the ZigBee® application framework on TI’s ZigBee stack (Z-Stack™). Each layer of the

application framework is organized as a task within OSAL, and the HAL task is always given top priority, as

shown in the system diagram of OSAL ZAP services in Figure 2. The HAL task is the fi rst task that runs and

Software application framework

Figure 1. Development platform for MSP430F54xx/CC2530-ZNP

Application

HAL

ZAP

ZCL

osal_init_system

osal_start_system

main

Tasks

serv

iced

inth

iso

rder

Figure 2. System diagram of OSAL ZAP services

Page 3: Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

3Texas Instruments

after each subsequent task runs to completion, a branch is always taken back to the HAL task to see if it

needs to be serviced. The tasks in the diagram shown are typical of a ZAP implementation.

The ZAP layer shown in Figure 3 acts as a translation layer between Z-Stack™ APIs and ZNP APIs. There-

fore, a customer application written for the full ZigBee® stack will work as is when used on a ZAP platform

that TI supports. This saves the customer from having to learn a different application development philosophy

when using the CC2530-ZNP. In the sections ahead, we’ll examine how the ZAP layer takes care of translat-

ing application API calls to ZNP API calls for confi guration and data exchanges. For this purpose we use the

Smart Energy Sample Application Project which can be found in

C:\Texas Instruments\ZAP-MSP430-1.0.0 \Projects\zstack\ZAP\SE-SampleApp\EXP5438 after installing the

ZAP installer package.

The macro HAL_SPI_INIT() takes care of initializing the SPI interface of the MSP430™. The function

zapPhyInit() is used to initialize the ZNP hardware control signals and allow the CC2530-ZNP to run by de-

asserting the RESET_N pin. Once the ZNP has fi nished its internal initialization sequence, it signals comple-

tion to the host processor by asserting the SRDY signal. The zapPhySpiPoll() process will then retrieve the

SYS_RESET_IND command. Subsequently, the zapSysResetInd() function is called to alert the ZAP layer that

it has received the reset indication and that it can now go ahead and confi gure the ZNP. From now on, we’ll

call this the “ZNP sync event”.

Creating a ZigBee® Smart Energy Device with the MSP430F54xx and the CC2530-ZNP January 2010

(ZigBee Pro Network Processor)

Application OSAL

Taskmanagement

Dynamicmemory

management

Timers andevents

Non-volatilememory

Powermanagement

Taskmessaging

ZAP

HAL

ZigBee Cluster Library (ZCL)

Smart Energy

General

Foundation

App

SPI

Timers

AF

INTER-PAN ZMAC

Phy

LED

ADC

Util

ZNP

LCD

Keys

ZDO

Sys

Flash

DCO

CBKE

Figure 3. Layers of the ZAP framework

ZNP startup

Page 4: Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

ZNP confi guration

Registering application endpoints and ZDO

callbacks

4 Texas Instruments

The fi rst thing the user has to do is decide whether to restore the network state of the ZNP device every time

a ZNP sync event occurs. This is selectable by the compile option ZAP_NV_RESTORE. If ZAP_NV_RESTORE

is set to FALSE, the network state of the ZNP will be cleared, and default confi guration used. zapAfSync() and

zapZdoSync() are used to register application endpoints and ZDO callbacks, respectively. The host application

must do this upon every ZNP sync event since application endpoint and callback information are not saved in

ZNP non-volatile memory.

The application then makes a series of calls using znp_nv_write for the items ZCD_NV_LOGICAL_TYPE,

ZDAPP_CONFIG_PAN_ID, DEFAULT_CHANLIST to confi gure the logical device type (coordinator, router, or

end device), PAN ID, and scan channel mask, respectively. The default values from the zap.cfg confi gura-

tion fi le are taken as values. When the compile option TC_LINKKEY_JOIN is defi ned, zapCertSync() is called

to confi gure test certifi cate data for ZigBee® CBKE (Certifi cate Based Key Establishment) security. Note that

since these confi guration items are declared as global variables within the ZNP, a reset of the ZNP is not

required to change these items at runtime. Note that this confi guration of ZNP has been automated if the

ZAP_AUTO_CFG compile option is set to TRUE in zap.cfg.

Once all the confi guration changes are made, the host processor can then start the device by calling

ZDOInitDevice which in turn calls the ZDO_STARTUP_FROM_APP ZNP API function. The compile option

ZAP_ZDO_STARTUP_AREQ is used to allow the ZDO_STARTUP_FROM_APP command to be sent as an

asynchronous request (AREQ) because the device startup process (which includes scanning for networks)

could take > 400 msec. Therefore, this allows the application to service other tasks instead of having to wait

for the synchronous response (SRSP). The status of this request will be queued for the host processor as a

ZDO_STATE_CHANGE_IND command. This indication is then passed up to the application task to notify it that

the device has a valid ZigBee network address. The application then processes this event as:

Note that this network startup of ZNP has been automated if the ZAP_AUTO_START compile option is set

to TRUE in zap.cfg.

Part of the application’s initialization function is to register for the SE endpoint and desired ZDO callbacks. For

example, the function zclSE_Init registers the SE endpoint description with the ZNP.

Creating a ZigBee® Smart Energy Device with the MSP430F54xx and the CC2530-ZNP January 2010

(ZigBee Pro Network Processor)

case ZDO_STATE_CHANGE:

if ((DEV_END_DEVICE == (devStates_t)(MSGpkt->hdr.status)) ||

(DEV_ROUTER == (devStates_t)(MSGpkt->hdr.status)))

{

// device is on the ZigBee network

Page 5: Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

5Texas Instruments

This translates into a ZAP proxy function called znp_afRegisterExtended() which uses the AF_REGISTER

ZNP API to register this endpoint with the ZNP.

The application can also register for certain ZDO callback notifi cations. The Energy Service Portal (ESP)

example registers for the following ZDO callbacks:

The ZDO_RegisterForZDOMsg() function then calls the ZAP proxy function znp_ZDO_RegisterForZDOMsg(),

which sends the ZDO_MSG_CB_REGISTER command to the ZNP. When the ZAP layer receives an incoming

ZDO command, the function zapZdoProcessIncoming is called. The command is then processed in the case

handler for MT_ZDO_MSG_CB_INCOMING. This command handler then calls ZDO_SendMsgCBs in order to

parse and determine which application task should receive the callback.

The ESP application uses the end device announce to detect when other devices join the SE network.

The ESP then uses the ZDO simple descriptor request to query the device for what type of device it is. Both

callbacks are processed as follows:

Creating a ZigBee® Smart Energy Device with the MSP430F54xx and the CC2530-ZNP January 2010

(ZigBee Pro Network Processor)

// register for SE endpoint

zclSE_Init( &simpleMeterSimpleDesc );

// register for end device annce and simple descriptor responses

ZDO_RegisterForZDOMsg( espTaskID, Device_annce );

ZDO_RegisterForZDOMsg( espTaskID, Simple_Desc_rsp );

static void esp_ProcessZDOMsg( zdoIncomingMsg_t *inMsg )

{

ZDO_DeviceAnnce_t devAnnce;

switch ( inMsg->clusterID )

{

case Device_annce:

{

ZDO_ParseDeviceAnnce( inMsg, &devAnnce );

simpleDescReqAddr.addrMode = (afAddrMode_t)Addr16Bit;

simpleDescReqAddr.addr.shortAddr = devAnnce.nwkAddr;

// set simple descriptor query event

osal_set_event( espTaskID, SIMPLE_DESC_QUERY_EVT );

Page 6: Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

When full ZigBee® CBKE security is used with the Certicom Elliptic Curve Cryptography (ECC) library, in order

to establish an application link key with the ESP, the function zclGeneral_KeyEstablish_InitiateKeyEstablishment

is called. This in turn sends the UTIL_ZCL_KEY_EST_INIT_EST command to the ZNP. As the entire ECC pro-

cess could take up to 20 seconds, zapPhyWait(zapAppPort, ZCL_KEY_EST_INIT_EST_WAIT) is called to tell

the low-level SPI driver to wait at least 30 seconds before timing out on the SRSP. When the key establish-

ment process completes, the zapUtilProcessIncoming function will notify the application via the MT_UTIL_

ZCL_KEY_ESTABLISH_IND handler. The application can then decide to use this indication to determine that it

can start to communicate with the ESP. For example, in the simple meter example we have:

Once the key establishment procedure is complete, sending application commands is straightforward. The

ZCL layer provides API functions to send correctly formatted SE commands, such as the following, which is

used in the simple meter example to send a report attribute command to the ESP:

6 Texas Instruments

Initiating key establishment

}

break;

case Simple_Desc_rsp:

{

ZDO_SimpleDescRsp_t *pSimpleDescRsp; // pointer to received simple desc response

pSimpleDescRsp = (ZDO_SimpleDescRsp_t *)osal_mem_alloc( sizeof( ZDO_

SimpleDescRsp_t ) );

………

case ZCL_KEY_ESTABLISH_IND:

if ((MSGpkt->hdr.status) == TermKeyStatus_Success)

{

osal_start_timerEx( simpleMeterTaskID, SIMPLEMETER_REPORT_ATTRIBUTE_EVT,

SIMPLEMETER_REPORT_PERIOD );

}

Creating a ZigBee® Smart Energy Device with the MSP430F54xx and the CC2530-ZNP January 2010

(ZigBee Pro Network Processor)

Sending Smart Energy profi le

commands

zcl_SendReportCmd( SIMPLEMETER_ENDPOINT, &ESPAddr,

ZCL_CLUSTER_ID_SE_SIMPLE_METERING, pReportCmd,

ZCL_FRAME_SERVER_CLIENT_DIR, 1, 0 );

Page 7: Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

7Texas Instruments

These commands are translated into AF_DATA_REQUEST commands that are sent to the ZNP.

In the Smart Energy Sample Application Project, there are also other device confi gurations such as the

In-Premise Display and Load Control Device that show examples of how to use commands related to Pricing

and Demand Response and Load Control, respectively.

Any incoming over-the-air message is extracted by the host processor (as an AF_INCOMING_CMD) and then

passed up to the ZCL layer. The application registers callbacks for each command that it wishes to process

on the receive side. As the ESP has to support all SE commands, all SE callbacks are registered by the ESP

application:

For example when the ESP receives a Get Current Price command from an In-Premise Display, the

esp_GetCurrentPriceCB callback function is called and the Publish Price command is sent back:

Receiving Smart Energy profi le

commands

static zclSE_AppCallbacks_t esp_SECmdCallbacks =

{

esp_GetProfi leCmdCB, // Get Profi le Command

esp_GetProfi leRspCB, // Get Profi le Response

esp_ReqMirrorCmdCB, // Request Mirror Command

esp_ReqMirrorRspCB, // Request Mirror Response

esp_MirrorRemCmdCB, // Mirror Remove Command

esp_MirrorRemRspCB, // Mirror Remove Response

esp_GetCurrentPriceCB, // Get Current Price

esp_GetScheduledPriceCB, // Get Scheduled Price

esp_PublishPriceCB, // Publish Price

esp_DisplayMessageCB, // Display Message Command

esp_CancelMessageCB, // Cancel Message Command

esp_GetLastMessageCB, // Get Last Message Command

esp_MessageConfi rmationCB, // Message Confi rmation

esp_LoadControlEventCB, // Load Control Event

esp_CancelLoadControlEventCB, // Cancel Load Control Event

esp_CancelAllLoadControlEventsCB, // Cancel All Load Control Events

esp_ReportEventStatusCB, // Report Event Status

esp_GetScheduledEventCB, // Get Scheduled Event

};

Creating a ZigBee® Smart Energy Device with the MSP430F54xx and the CC2530-ZNP January 2010

(ZigBee Pro Network Processor)

Page 8: Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

This paper has described how to create a ZigBee® Smart Energy device using the MSP430F54xx as the host

application processor to the CC2530-ZNP (ZigBee Pro Network Processor). A typical smart meter application

that would benefi t most from this type of architecture would be a gas or water meter since extended battery

life of 10 years or greater is a key requirement for these devices. The MSP430F54xx and CC2530-ZNP

combination provides a low-power and low-cost solution that meets this requirement. The ZAP software ap-

plication framework provides an easy-to-use development environment that accelerates ZigBee development

for smart meter applications.

static void esp_GetCurrentPriceCB( zclCCGetCurrentPrice_t *pCmd,

afAddrType_t *srcAddr, uint8 seqNum )

{

#if defi ned ( ZCL_PRICING )

// On receipt of Get Current Price command, the device shall send a

// Publish Price command with the information for the current time.

zclCCPublishPrice_t cmd;

osal_memset( &cmd, 0, sizeof( zclCCPublishPrice_t ) );

cmd.providerId = 0xbabeface;

cmd.priceTier = 0xfe;

// copy source address of display device that requested current pricing info so

// that esp can send messages to it using destination address of IPDAddr

osal_memcpy( &ipdAddr, srcAddr, sizeof ( afAddrType_t ) );

zclSE_Pricing_Send_PublishPrice( ESP_ENDPOINT, srcAddr, &cmd, false, seqNum );

#endif // ZCL_PRICING

}

8 Texas Instruments

Conclusion

Creating a ZigBee® Smart Energy Device with the MSP430F54xx and the CC2530-ZNP January 2010

(ZigBee Pro Network Processor)

Page 9: Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

SLYY022© 2010 Texas Instruments Incorporated

Important Notice: The products and services of Texas Instruments Incorporated and its subsidiaries described herein are sold subject to TI’s standard terms and conditions of sale. Customers are advised to obtain the most current and complete information about TI products and services before placing orders. TI assumes no lia-bility for applications assistance, customer’s applications or product designs, software performance, or infringement of patents. The publication of information regard-ing any other company’s products or services does not constitute TI’s approval, warranty or endorsement thereof.

MSP430 and Z-Stack are trademarks of Texas Instruments Incorporated. All other trademarks are the property of their respective owners.

9Texas Instruments

[1] CC2530-ZNP Interface Specifi cation, SWRA312

[2] OSAL API document, SWRA194

[3] Z-Stack™ API document, SWRA195

[4] ZCL API document, SWRA197

[5] Z-Stack Smart Energy Developer’s Guide, SWRA216

For more information on Smart Metering devices from TI, visit www.ti.com/metering, or

e-mail: [email protected]

References

Page 10: Creating a ZigBee Smart Energy Device with the MSP430F54xx and the CC2530-ZNP

IMPORTANT NOTICE

Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements,and other changes to its products and services at any time and to discontinue any product or service without notice. Customers shouldobtain the latest relevant information before placing orders and should verify that such information is current and complete. All products aresold subject to TI’s terms and conditions of sale supplied at the time of order acknowledgment.

TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TI’s standardwarranty. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except wheremandated by government requirements, testing of all parameters of each product is not necessarily performed.

TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products andapplications using TI components. To minimize the risks associated with customer products and applications, customers should provideadequate design and operating safeguards.

TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right,or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Informationpublished by TI regarding third-party products or services does not constitute a license from TI to use such products or services or awarranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectualproperty of the third party, or a license from TI under the patents or other intellectual property of TI.

Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompaniedby all associated warranties, conditions, limitations, and notices. Reproduction of this information with alteration is an unfair and deceptivebusiness practice. TI is not responsible or liable for such altered documentation. Information of third parties may be subject to additionalrestrictions.

Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids allexpress and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice. TI is notresponsible or liable for any such statements.

TI products are not authorized for use in safety-critical applications (such as life support) where a failure of the TI product would reasonablybe expected to cause severe personal injury or death, unless officers of the parties have executed an agreement specifically governingsuch use. Buyers represent that they have all necessary expertise in the safety and regulatory ramifications of their applications, andacknowledge and agree that they are solely responsible for all legal, regulatory and safety-related requirements concerning their productsand any use of TI products in such safety-critical applications, notwithstanding any applications-related information or support that may beprovided by TI. Further, Buyers must fully indemnify TI and its representatives against any damages arising out of the use of TI products insuch safety-critical applications.

TI products are neither designed nor intended for use in military/aerospace applications or environments unless the TI products arespecifically designated by TI as military-grade or "enhanced plastic." Only products designated by TI as military-grade meet militaryspecifications. Buyers acknowledge and agree that any such use of TI products which TI has not designated as military-grade is solely atthe Buyer's risk, and that they are solely responsible for compliance with all legal and regulatory requirements in connection with such use.

TI products are neither designed nor intended for use in automotive applications or environments unless the specific TI products aredesignated by TI as compliant with ISO/TS 16949 requirements. Buyers acknowledge and agree that, if they use any non-designatedproducts in automotive applications, TI will not be responsible for any failure to meet such requirements.

Following are URLs where you can obtain information on other Texas Instruments products and application solutions:

Products Applications

Amplifiers amplifier.ti.com Audio www.ti.com/audio

Data Converters dataconverter.ti.com Automotive www.ti.com/automotive

DLP® Products www.dlp.com Communications and www.ti.com/communicationsTelecom

DSP dsp.ti.com Computers and www.ti.com/computersPeripherals

Clocks and Timers www.ti.com/clocks Consumer Electronics www.ti.com/consumer-apps

Interface interface.ti.com Energy www.ti.com/energy

Logic logic.ti.com Industrial www.ti.com/industrial

Power Mgmt power.ti.com Medical www.ti.com/medical

Microcontrollers microcontroller.ti.com Security www.ti.com/security

RFID www.ti-rfid.com Space, Avionics & www.ti.com/space-avionics-defenseDefense

RF/IF and ZigBee® Solutions www.ti.com/lprf Video and Imaging www.ti.com/video

Wireless www.ti.com/wireless-apps

Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265Copyright © 2010, Texas Instruments Incorporated