基于zigbee技术的main程序Word文档格式.docx
《基于zigbee技术的main程序Word文档格式.docx》由会员分享,可在线阅读,更多相关《基于zigbee技术的main程序Word文档格式.docx(21页珍藏版)》请在冰豆网上搜索。
|Jumpername|STM32W108|
|JP1,ifavailable|Don'
tcare|
|P1,ifavailable|1-2(battery)5-6(USB)|
@endtable
*\sectionBoard_supportedBoardsupported
|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.
|Parametername|Value|Unit|
|Baudrate|115200|bit/sec|
|Databits|8|bit|
|Parity|None|bit|
|Stopbits|1|bit|
*\sectionLEDs_descriptionLEDsdescription
|LEDname|Event|STM32W108|
-------------------------------------------------------------------------------------------------------------------------------
|D1|Buttonpress|Onwhenabuttonispressed,offwhenthemessagecorrespondingtothebuttonpressissent|
|D3|Buttonpress|None|
|D1|RFmessagereceived|Accordingtotablein@refButtons_description|
|D3|RFmessagereceived|Accordingtotablein@refButtons_description|
|D1+D3|Errorintx|Flashtogetherforasecond|
\sectionButtons_descriptionButtonsdescription
ButtonpressesontheboardwillresultinsendinganRFmessagetotheotherboardand
theactiontakenbytheotherboardisdescribedinthefollowingtable
|Buttonname|STM32W108|
-----------------------------------------------------------------------
|S1|ToggleledD1intheremotenode|
|S2,ifavailable|ToggleledD3intheremotenode|
|S3,ifavailable|ToggleledsD1andD3intheremotenode|
|S4,ifavailable|BlinksledD1forfewsecondsintheremotenode|
|S5,ifavailable|BlinksledD3forfewsecondsintheremotenode|
\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"
hal/micro/cortexm3/uart.h"
include/phy-library.h"
hal/error.h"
stdio.h"
stdlib.h"
#ifdefDEVBOARD
#include"
Lcd.h"
DevBoard.h"
#endif
#ifdefBASICBOARD
BasicBoard.h"
/*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:
*******************************************************************************/
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()*/
getButtonStatus
Returnwhetherabuttonhasbeenpressedandreleased
-button
BUTTON_CLICKEDorBUTTON_IDLE
int8ugetButtonStatus(HalBoardButtonbutton)
if(halGetButtonStatus(button)==BUTTON_PRESSED){
//Indicatebuttonpressiondetected
halSetLed(LED_D1);
/*Waitforrelease*/
while(halGetButtonStatus(button)==BUTTON_PRESSED);
halCommonDelayMilliseconds(50);
returnBUTTON_CLICKED;
}else{
returnBUTTON_IDLE;
}
}
buttonAction
SendpackettoremotenodeandshortlyflashedLED_D1
voidbuttonAction(int8ubuttonAction)
sendData(1,&
buttonAction,TYPE_BUTTON);
ledAction
Performsomeledtogglingaccordingtothebuttonreceivedfrom
*remotenode
voidledAction(int8ubuttonAction)
int32ui;
if(buttonAction==BUTTON_ACTION_1){
halToggleLed(LED_D1);
}elseif(buttonAction==BUTTON_ACTION_2){
halToggleLed(LED_D3);
}elseif(buttonAction==BUTTON_ACTION_3){
}elseif(buttonAction==BUTTON_ACTION_4){
halClearLed(LED_D1);
for(i=0;
i<
5;
i++){
halCommonDelayMilliseconds(200);
}elseif(buttonAction==BUTTON_ACTION_5){
halClearLed(LED_D3);
processInput
Itprocessesserialinputandbuttonpresses
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){