基于zigbee技术的main程序.docx

上传人:b****3 文档编号:3851290 上传时间:2022-11-25 格式:DOCX 页数:21 大小:20.13KB
下载 相关 举报
基于zigbee技术的main程序.docx_第1页
第1页 / 共21页
基于zigbee技术的main程序.docx_第2页
第2页 / 共21页
基于zigbee技术的main程序.docx_第3页
第3页 / 共21页
基于zigbee技术的main程序.docx_第4页
第4页 / 共21页
基于zigbee技术的main程序.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

基于zigbee技术的main程序.docx

《基于zigbee技术的main程序.docx》由会员分享,可在线阅读,更多相关《基于zigbee技术的main程序.docx(21页珍藏版)》请在冰豆网上搜索。

基于zigbee技术的main程序.docx

基于zigbee技术的main程序

/**

*@filetalk.c

*@authorMCDApplicationTeam

*@briefAnexampleofRFapplicationwhichshowspoint-to-point802.15.4wirelesscommunicationusingtheSTM32W108microcontroller.

*

--Copyright2011bySTMicroelectronics.Allrightsreserved.*80*-->

*\sectionIAR_projectIARproject

\ctalk.eww

*\subsectionIAR_project_configurationsIARprojectconfigurations

-\cSTM32W108-STM32W108IARconfiguration

-\cSTM32W108-btl-STM32W108IARconfigurationfornodeswithOTAbootloader

*\sectionPrebuilt_imagesPrebuiltimages

-...\\prebuilt\\talk.s37Prebuiltversion

-...\\prebuilt\\talk-btl.s37PrebuiltversionforOTAbootloader

*\sectionJumper_settingsJumpersettings

@table

----------------------------------------------

|Jumpername|STM32W108|

----------------------------------------------

|JP1,ifavailable|Don'tcare|

|P1,ifavailable|1-2(battery)5-6(USB)|

@endtable

*\sectionBoard_supportedBoardsupported

@table

|Boardname|Boardrevision|STM32W108|

--------------------------------------------------

|Primer2+MB850|A|-|

|MB851|A,B|X|

|MB851|C|X|

|MB954|A|X|

|MB954|B|X|

|MB950|A|X|

|MB951|A|X|

@endtable

*\sectionSerial_IOSerialI/O

Theapplicationwilllistenforkeystypedinonenodeanditwillsendthemtotheremotenode.

TheremotenodewilllistenforRFmessagesanditwilloutputthemintheserialport.

Inotherwordseverythingtypedinonenodewillbevisibletotheothernodeandviceversa.

@table

|Parametername|Value|Unit|

--------------------------------------------------

|Baudrate|115200|bit/sec|

|Databits|8|bit|

|Parity|None|bit|

|Stopbits|1|bit|

@endtable

*\sectionLEDs_descriptionLEDsdescription

@table

|LEDname|Event|STM32W108|

-------------------------------------------------------------------------------------------------------------------------------

|D1|Buttonpress|Onwhenabuttonispressed,offwhenthemessagecorrespondingtothebuttonpressissent|

|D3|Buttonpress|None|

|D1|RFmessagereceived|Accordingtotablein@refButtons_description|

|D3|RFmessagereceived|Accordingtotablein@refButtons_description|

|D1+D3|Errorintx|Flashtogetherforasecond|

@endtable

\sectionButtons_descriptionButtonsdescription

ButtonpressesontheboardwillresultinsendinganRFmessagetotheotherboardand

theactiontakenbytheotherboardisdescribedinthefollowingtable

@table

|Buttonname|STM32W108|

-----------------------------------------------------------------------

|S1|ToggleledD1intheremotenode|

|S2,ifavailable|ToggleledD3intheremotenode|

|S3,ifavailable|ToggleledsD1andD3intheremotenode|

|S4,ifavailable|BlinksledD1forfewsecondsintheremotenode|

|S5,ifavailable|BlinksledD3forfewsecondsintheremotenode|

@endtable

\sectionUsageUsage

Thisdemoshowtwousecasescenarions:

-RS232cablereplacement

-Simpleremotecontrolimplmentation

Youneedtousetwoboardstoexercisethedemo.

Stepbystepinstructionsareasfollow:

-#Loadthetwoboardswithtalkapplication,thatis:

stm32w_flasher.exe-pCOMxx-f-rtalk.s37

-#Openaterminalonbothboardsandyoushouldbeabletoseethekeystrokesfromoneterminalsenttotheotherterminal.ThisisanRS232cablereplacementdemo.

-#PushanybuttonononeboardandobservethecorrespondingactionontheotherboardsLEDs.Thisisasimpleremotecontrolimplementation

\noteNotesandlimitations

\liYoucannotusemorethantwonodeswithtalkapplicationinthesameradiorange,sinceRFconflictswillarise

**/

/**@addtogroupdemos

*Point-to-point\seetalk.cfordocumentation.

*

*@{

*/

/**@}*/

/**\condDOXYGEN_SHOULD_SKIP_THIS

*/

/*Includes------------------------------------------------------------------*/

#includePLATFORM_HEADER

#includeBOARD_HEADER

#include"hal/hal.h"

#include"hal/micro/cortexm3/uart.h"

#include"include/phy-library.h"

#include"hal/error.h"

#include"stdio.h"

#include"stdlib.h"

#ifdefDEVBOARD

#include"Lcd.h"

#include"DevBoard.h"

#endif

#ifdefBASICBOARD

#include"BasicBoard.h"

#endif

/*Privatedefine------------------------------------------------------------*/

#defineTIMEOUT_VALUE100

#defineMAX_RETRIES3

#defineBUFFER_SIZE64

#defineTYPE_SERIAL0

#defineTYPE_BUTTON1

//Definethenumberofquartersecondsbetweenperiodicmaintenanceevents.

//Theperiodiceventsdonotneedtooccurveryoften,sorunthese

//eventsonceaminute.

#definePERIODIC_MAINTENANCE_EVENTS_RATE(1*60*4)

#defineBUTTON_CLICKED1

#defineBUTTON_IDLE0

#defineBUTTON_ACTION_10

#defineBUTTON_ACTION_21

#defineBUTTON_ACTION_32

#defineBUTTON_ACTION_43

#defineBUTTON_ACTION_54

#definePTP_PAN_ID0x1406

#definePTP_SHORT_ID0x1406

#defineINACTIVE_TIMEOUT(10*4)//10seconds

/*Privatevariables---------------------------------------------------------*/

/*radioTransmitConfigvariablesrequiredfromtheSimpleMaclibraryforpacket

transmission*/

RadioTransmitConfigradioTransmitConfig={

TRUE,//waitForAck;

TRUE,//checkCca;

4,//ccaAttemptMax;

3,//backoffExponentMin;

5,//backoffExponentMax;

TRUE//appendCrc;

};

/*genericdatapacket*/

ALIGN_VAR(u8txPacket[128],2);

u8txPacket[128]={

0x0a,//length

0x61,//fcf-intrapan,ackrequest,data

0x08,//fcf-src,dstmode

0x00,//seq

BYTE_0(PTP_PAN_ID),//dstpanl

BYTE_1(PTP_PAN_ID),//dstpanh

BYTE_0(PTP_SHORT_ID),//dstaddrl

BYTE_1(PTP_SHORT_ID),//dstaddrh

0x00//data

};

/*bufferforreceivedpacket*/

u8rxPacket[128];

/*receivedpacketflag*/

volatilebooleanpacketReceived=FALSE;

/*Retriescounter*/

u8retries=MAX_RETRIES;

/*packettransmissioncompleteflag*/

volatilebooleantxComplete=TRUE;

/*PrivateFunctions---------------------------------------------------------*/

/*******************************************************************************

*FunctionName:

sendData

*Description:

Itallowstotransmitthedata

*Input:

-lenghtofthedata

*-datatobetransmitted

*-typetypeofdata(serialorbuttons)

*Output:

None

*Return:

None

*******************************************************************************/

voidsendData(u8length,u8*data,u8type)

{

while(txComplete==FALSE);

txPacket[8]=type;

halCommonMemCopy(txPacket+9,data,length);

txPacket[0]=length+2+7+1;

txPacket[3]++;/*incrementsequencenumber*/

txComplete=FALSE;

ST_RadioTransmit(txPacket);

}/*endsendSerialData()*/

/*******************************************************************************

*FunctionName:

getButtonStatus

*Description:

Returnwhetherabuttonhasbeenpressedandreleased

*Input:

-button

*Output:

None

*Return:

BUTTON_CLICKEDorBUTTON_IDLE

*******************************************************************************/

int8ugetButtonStatus(HalBoardButtonbutton)

{

if(halGetButtonStatus(button)==BUTTON_PRESSED){

//Indicatebuttonpressiondetected

halSetLed(LED_D1);

/*Waitforrelease*/

while(halGetButtonStatus(button)==BUTTON_PRESSED);

halCommonDelayMilliseconds(50);

while(halGetButtonStatus(button)==BUTTON_PRESSED);

returnBUTTON_CLICKED;

}else{

returnBUTTON_IDLE;

}

}

/*******************************************************************************

*FunctionName:

buttonAction

*Description:

SendpackettoremotenodeandshortlyflashedLED_D1

*Input:

-button

*Output:

None

*Return:

None

*******************************************************************************/

voidbuttonAction(int8ubuttonAction)

{

sendData(1,&buttonAction,TYPE_BUTTON);

}

/*******************************************************************************

*FunctionName:

ledAction

*Description:

Performsomeledtogglingaccordingtothebuttonreceivedfrom

*remotenode

*Input:

-button

*Output:

None

*Return:

None

*******************************************************************************/

voidledAction(int8ubuttonAction)

{

int32ui;

if(buttonAction==BUTTON_ACTION_1){

halToggleLed(LED_D1);

}elseif(buttonAction==BUTTON_ACTION_2){

halToggleLed(LED_D3);

}elseif(buttonAction==BUTTON_ACTION_3){

halToggleLed(LED_D1);

halToggleLed(LED_D3);

}elseif(buttonAction==BUTTON_ACTION_4){

halClearLed(LED_D1);

for(i=0;i<5;i++){

halToggleLed(LED_D1);

halCommonDelayMilliseconds(200);

}

}elseif(buttonAction==BUTTON_ACTION_5){

halClearLed(LED_D3);

for(i=0;i<5;i++){

halToggleLed(LED_D3);

halCommonDelayMilliseconds(200);

}

}

}

/*******************************************************************************

*FunctionName:

processInput

*Description:

Itprocessesserialinputandbuttonpresses

*Input:

None

*Output:

None

*Return:

None

*******************************************************************************/

voidprocessInput(void)

{

staticu8buffer[BUFFER_SIZE];

staticu8bufferSize=0;

staticu32bufferTimeout=TIMEOUT_VALUE;

if(bufferSize==0)

bufferTimeout=TIMEOUT_VALUE;

if(__io_getcharNonBlocking(buffer+bufferSize))

{

bufferSize+=1;

}

if(getButtonStatus(BUTTON_S1)==BUTTON_CLICKED){

buttonAction(BUTTON_ACTION_1);

}elseif(getButtonStatus(BUTTON_S2)==BUTTON_CLICKED){

buttonAction(BUTTON_ACTION_2);

}elseif(getButtonStatus(BUTTON_S3)==BUTTON_CLICKED){

buttonAction(BUTTON_ACTION_3);

}elseif(getButtonStatus(BUTTON_S4)==BUTTON_CLICKED){

buttonAction(BUTTON_ACTION_4);

}elseif(getButtonStatus(BUTTON_S5)==BUTTON_CLICKED){

buttonAction

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教学研究 > 教学反思汇报

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1