| anh_risn 
 
 
 Joined: 05 Jun 2011
 Posts: 4
 
 
 
			    
 
 | 
			
				| dsPIC zigbee problem |  
				|  Posted: Sat Aug 13, 2011 10:27 pm |   |  
				| 
 |  
				| Has anyone here ever tried using zigbee on dsPIC? I'm getting a lot of problem. The zigbee cannot initialize as a coordinator even using simple program. I call the function ezspFormNetwork(), seems like zigbee didn't give respond. I'm using PCWHD ver 4.104, since last time I updated to newest ver 4.124, the new version even cannot pass EmberInitialization.
 
 Here is my code:
 
  	  | Code: |  	  | #include<30F4013.h>
 
 #device *=16
 
 #FUSES NOWDT                    //No Watch Dog Timer
 #FUSES HS2_PLL16
 #FUSES PR_PLL                   //Primary Oscillator with PLL
 #FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
 #FUSES WPSB16                   //Watch Dog Timer PreScalar B 1:16
 #FUSES WPSA512                  //Watch Dog Timer PreScalar A 1:512
 #FUSES PUT64                    //Power On Reset Timer value 64ms
 #FUSES NOBROWNOUT               //No brownout reset
 #FUSES BORRES
 #FUSES LPOL_HIGH                //Low-Side Transistors Polarity is Active-High (PWM 0,2,4 and 6)
 //PWM module low side output pins have active high output polar
 #FUSES HPOL_HIGH                //High-Side Transistors Polarity is Active-High (PWM 1,3,5 and 7)
 //PWM module high side output pins have active high output polarity
 #FUSES NOPWMPIN                 //PWM outputs drive active state upon Reset
 #FUSES MCLR                     //Master Clear pin enabled
 #FUSES NOPROTECT                //Code not protected from reading
 #FUSES NOWRT                    //Program memory not write protected
 #FUSES NODEBUG                  //No Debug mode for ICD
 #FUSES NOCOE                    //Device will reset into operational mode
 #FUSES ICSP1                    //ICD uses PGC1/PGD1 pins
 
 //#device PASS_STRINGS=IN_RAM
 
 #use delay(clock=80000000)
 
 #define COORDINATOR   1
 //#define SLEEPY_SENSOR   1
 // Pin defines for the SPI communication
 #define PIN_EZSP_INT    PIN_B4
 #define PIN_EZSP_WAKE   PIN_B5
 #define PIN_EZSP_RESET  PIN_B8
 #define PIN_SSEL_INT    PIN_B3
 
 #define APP_CHANNEL 0x18
 #define APP_PANID   0x2608
 #define APP_POWER   0xFF
 const int8 EXTENDED_PAN_ID[8]= {0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98};
 #define CLUSTER_ID_TRACKING_DEVICE  0x0A
 
 #define SPI_BUFFER_SIZE    128
 #define SPI_XMIT_L_TO_H    0x0100
 
 #define LED1   PIN_B10
 #define LED2   PIN_B11
 
 #define SETTING_ZIGBEE_MANUALLY  1
 #define NUM_DATA  15    // Num of packet data
 
 int16 cnt_ms, cnt_s;
 
 #include <em260.h>
 #include "ember_utilities1.c"
 
 int8 messagedata[NUM_DATA];
 EmberApsFrame apsframe;
 
 int8 EmberInitialization1()
 {
 int8 k=0;
 int8 version_no;
 int8 stacktype;
 int16 stackVersion;
 SPIInit();
 EM260Reset();
 delay_ms(100);
 
 k=ask_SPI_version();
 k+=verify_SPI_status();
 if(k==0)
 {
 version_no = ezspVersion(0x02, &stacktype, &stackVersion);
 return(1);
 }
 else
 return(0);
 }
 
 #int_TIMER1
 void timer1_isr()
 {
 // Interrupt every 1ms
 cnt_ms++;
 if ((cnt_ms % 1000)==0) cnt_s++;
 set_timer1(65536-2500);
 }
 
 void main()
 {
 //######################################################################
 //Zigbee cordinator variables
 //######################################################################
 emberStatus Status;
 EmberEUI64 emLocalEui64;
 int16 childID;
 EmberEUI64 childEui64;
 EmberNodeType childType;
 int8 messagetag=0x01;
 int8 messageLength;
 int16 indexOrDestination;
 EmberNetworkParameters parameters;
 EmberNodeType nodeType;
 int8 i;
 EmberNetworkStatus NetworkState;
 
 setup_timer1( TMR_INTERNAL | TMR_DIV_BY_8 );
 set_timer1(65536-2500);                           // Interrupt every 1ms
 
 delay_ms(200);
 
 if(EmberInitialization1())
 {
 EmberConfig();
 EmberInitializeBinding();
 ezspGetEUI64(&emLocalEui64);
 EmberAddEndPoint();
 
 #ifndef SETTING_ZIGBEE_MANUALLY
 //EmberJoinNetwork(EMBER_SLEEPY_END_DEVICE);
 EmberFormNetwork();
 #else
 for(i=0;i<8;i++)
 {
 parameters.extendedPanID[i] = EXTENDED_PAN_ID[i];
 //parameters.extendedPanID[i] = 0;
 }
 parameters.panID = APP_PANID;
 parameters.radioTXPower = APP_POWER;
 parameters.radioChannel = APP_CHANNEL;
 
 Status = ezspFormNetwork(parameters);
 //ezspScanAndJoinNetwork(EMBER_SLEEPY_END_DEVICE, EMBER_ALL_802_15_4_CHANNELS_MASK, APP_POWER, parameters.extendedPanID);
 //Status=ezspGetNetworkParameters(&nodeType,parameters);
 //*******************************************
 #endif
 
 ezspPermitJoining(0xFF);
 
 // Initialize all variables here
 indexOrDestination = 0x0000;
 apsframe.profileID=0xC00F;
 apsframe.clusterID=CLUSTER_ID_TRACKING_DEVICE;
 apsframe.sourceEndpoint=0x01;
 apsframe.destinationEndpoint=0x01;
 apsframe.options=0x0000;
 apsframe.groupID=0x0000;
 apsframe.sequence=0x00;
 
 cnt_ms = cnt_s = 0;
 
 output_low(PIN_D0);     // Keep low RTS pin for sending data
 
 enable_interrupts( INT_TIMER1 );
 enable_interrupts( INTR_GLOBAL );
 
 //*******************************
 // Main program loop here...
 //*******************************
 
 while(TRUE)
 {
 //SensorApplicationTick();
 //EM260Tick();
 
 output_high(LED1);
 
 EM260Tick();
 
 output_high(LED2);
 
 SinkApplicationTick();
 
 delay_ms(200);
 output_low(LED1);
 output_low(LED2);
 delay_ms(200);
 
 }
 }  // end of main while
 }
 else
 {
 // Error cannot initialize ember zigbee
 while(TRUE)
 {
 output_high(PIN_B10);
 output_high(PIN_B11);
 delay_ms(200);
 output_low(PIN_B10);
 output_low(PIN_B11);
 delay_ms(200);
 }
 } // end of if (EmberInitialization())
 }
 
 | 
 |  |