TI中文支持网
TI专业的中文技术问题搜集分享网站

CC2530: 新手使用开发板无法实现组网示例

Part Number:CC2530

新手求助

实验室拿到两个zigbee节点,于是我按照书<ZigBee无线传感器网络设计与实现>配置并运行了第一个实验,使终端节点发送字符“LED”到协调器节点,然后协调器节点闪烁,代码如下

但是奇怪的是节点并没有按预期的那样工作,刷写完成后重新打开节点,节点没有任何反应

使用IAR在终端节点上进行调试,在函数UINT16 GenericApp_ProcessEvent(byte task_id, UINT16 events)处打上断点,但运行后代码并不会停止在断点处,设备会显示busy

我使用的IAR版本为10.20.1,Zstack版本为3.0.1

硬件应该是正常的,我进行刷写程序之前两个节点还是可以正常通信

代码如下:

Coordinator.h

#ifndef COORDINATOR_H
#define COORDINATOR_H

#include "zComDef.h"

#define GENERICAPP_ENDPOINT10

#define GENERICAPP_PROFID0x0F04
#define GENERICAPP_DEVICEID0x0001
#define GENERICAPP_DEVICE_VERSION0
#define GENERICAPP_FLAGS0
#define GENERICAPP_MAX_CLUSTERS1
#define GENERICAPP_CLUSTERID1



extern void GenericApp_Init( byte task_id );
extern UINT16 GenericApp_ProcessEvent( byte task_id, UINT16 events );

#endif

Coordinator.c

#include "OSAL.h"
#include "AF.h"
#include "ZDApp.h"
#include "ZDObject.h"
#include "ZDProfile.h"
#include "math.h"
#include "stdlib.h"
#include "Coordinator.h"
#include "DebugTrace.h"
#if !defined( WIN32 )
#include "OnBoard.h"
#endif
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
#include "hal_uart.h"

const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] =
{GENERICAPP_CLUSTERID
};

const SimpleDescriptionFormat_t GenericApp_SimpleDesc =
{GENERICAPP_ENDPOINT,//  int Endpoint;GENERICAPP_PROFID,//  uint16 AppProfId[2];GENERICAPP_DEVICEID,//  uint16 AppDeviceId[2];GENERICAPP_DEVICE_VERSION,//  intAppDevVer:4;GENERICAPP_FLAGS,//  intAppFlags:4;GENERICAPP_MAX_CLUSTERS,//  byte  AppNumInClusters;(cId_t *)GenericApp_ClusterList,  //  byte *pAppInClusterList;0,//  byte  AppNumInClusters;(cId_t *)NULL//  byte *pAppInClusterList;
};

endPointDesc_t GenericApp_epDesc;
byte GenericApp_TaskID;// Task ID for internal task/event processing
byte GenericApp_TransID;  // This is the unique message ID (counter)

void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pckt );
void GenericApp_SendTheMessage( void );

void GenericApp_Init( byte task_id )
{GenericApp_TaskID = task_id;GenericApp_TransID = 0;GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;GenericApp_epDesc.task_id = &GenericApp_TaskID;GenericApp_epDesc.simpleDesc= (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;GenericApp_epDesc.latencyReq = noLatencyReqs;afRegister( &GenericApp_epDesc );

}

UINT16 GenericApp_ProcessEvent( byte task_id, UINT16 events )
{afIncomingMSGPacket_t *MSGpkt;if ( events & SYS_EVENT_MSG ){MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );while ( MSGpkt ){switch ( MSGpkt->hdr.event ){case AF_INCOMING_MSG_CMD:GenericApp_MessageMSGCB( MSGpkt );break;default:break;}osal_msg_deallocate( (uint8 *)MSGpkt );MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );}return (events ^ SYS_EVENT_MSG);}return 0;
}

void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{unsigned char buffer[4] = "";switch (pkt->clusterId){case GENERICAPP_CLUSTERID:osal_memcpy(buffer, pkt->cmd.Data,3);if((buffer[0]=='L')||(buffer[1]=='E')||(buffer[2]=='D')){HalLedBlink(HAL_LED_2,0,50,500);}else{HalLedSet(HAL_LED_2,HAL_LED_MODE_ON);}break;}
}

Enddevice.c

#include "OSAL.h"
#include "AF.h"
#include "ZDApp.h"
#include "ZDObject.h"
#include "ZDProfile.h"
#include "Coordinator.h"
#include "DebugTrace.h"


#if !defined( WIN32 )
#include "OnBoard.h"
#endif

#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
#include "hal_uart.h"

#define SEND_DATA_EVENT 0x01

const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] =
{GENERICAPP_CLUSTERID
};

const SimpleDescriptionFormat_t GenericApp_SimpleDesc =
{GENERICAPP_ENDPOINT,//  int Endpoint;GENERICAPP_PROFID,//  uint16 AppProfId[2];GENERICAPP_DEVICEID,//  uint16 AppDeviceId[2];GENERICAPP_DEVICE_VERSION,//  intAppDevVer:4;GENERICAPP_FLAGS,//  intAppFlags:4;0,//  byte  AppNumInClusters;(cId_t*)NULL,//  byte *pAppInClusterList;GENERICAPP_MAX_CLUSTERS,//  byte  AppNumInClusters;(cId_t*)GenericApp_ClusterList,  //  byte *pAppInClusterList;
};

endPointDesc_t GenericApp_epDesc;
byte GenericApp_TaskID;// Task ID for internal task/event processing
byte GenericApp_TransID;  // This is the unique message ID (counter)
devStates_t GenericApp_NwkState;

void GenericApp_MessageMSGCB(afIncomingMSGPacket_t* pckt);
void GenericApp_SendTheMessage(void);
int8 readTemp(void);
uint16 ReadHumi(void);
void To_string(uint8* dest, uint8* src, uint8 l);

void GenericApp_Init(byte task_id)
{GenericApp_TaskID = task_id;GenericApp_NwkState = DEV_INIT;GenericApp_TransID = 0;GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;GenericApp_epDesc.task_id = &GenericApp_TaskID;GenericApp_epDesc.simpleDesc= (SimpleDescriptionFormat_t*)&GenericApp_SimpleDesc;GenericApp_epDesc.latencyReq = noLatencyReqs;afRegister(&GenericApp_epDesc);
}

UINT16 GenericApp_ProcessEvent(byte task_id, UINT16 events)
{afIncomingMSGPacket_t* MSGpkt;if (events & SYS_EVENT_MSG){MSGpkt = (afIncomingMSGPacket_t*)osal_msg_receive(GenericApp_TaskID);while (MSGpkt){switch (MSGpkt->hdr.event){case ZDO_STATE_CHANGE:GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status);if (GenericApp_NwkState == DEV_END_DEVICE || GenericApp_NwkState == DEV_ROUTER){GenericApp_SendTheMessage();}break;default:break;}osal_msg_deallocate((uint8*)MSGpkt);MSGpkt = (afIncomingMSGPacket_t*)osal_msg_receive(GenericApp_TaskID);}return (events ^ SYS_EVENT_MSG);}return 0;
}

void GenericApp_SendTheMessage(void)
{unsigned char theMessageData[4] = "LED";afAddrType_t my_DstAddr;my_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;my_DstAddr.endPoint = GENERICAPP_ENDPOINT;my_DstAddr.addr.shortAddr = 0x0000;AF_DataRequest(&my_DstAddr, &GenericApp_epDesc,GENERICAPP_CLUSTERID,3,theMessageData,&GenericApp_TransID,AF_DISCV_ROUTE,AF_DEFAULT_RADIUS);HalLedBlink(HAL_LED_2,0,50,500);
}

void To_string(uint8* dest, uint8* src, uint8 l)
{uint8* xad;uint8 i = 0;uint8 ch;xad = src + l - 1;for (i = 0;i < l;i++, xad--){ch = (*xad >> 4) & 0x0F;dest[i << 1] = ch + ((ch < 10) ? '0' : '7');ch = *xad & 0x0F;dest[(i << 1) + 1] = ch + ((ch < 10) ? '0' : '7');}
}

有人能帮帮我吗?谢谢!

li yun:

代码是直接在ZStack提供的GenericApp工程上修改的

另外编译过程会有这两个warning 不知道有没有关系

Warning[w6]: Type conflict for external/entry "macCfg", in module mac_beacon against external/entry in module mac_cfg; types have different memory attributes Warning[w6]: Type conflict for external/entry "macTxSlottedDelay", in module mac_beacon against external/entry in module mac_tx; types have different memory

,

Kevin Qiu1:

将抓包文件传上来看一下

下面文档展示了例程的基本说明:

Z-Stack 3.0 Sample Application User's Guide.pdf

通过按键应该可以正常入网

,

li yun:

是我的开发板版本太老,zstack版本太新,换了zstack2.5.1a就好了,谢谢

,

Kevin Qiu1:

好的,感谢反馈

赞(0)
未经允许不得转载:TI中文支持网 » CC2530: 新手使用开发板无法实现组网示例
分享到: 更多 (0)