Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
mknoll
PostPosted: Jan 27, 2010 - 03:36 AM
Rookie


Joined: Aug 09, 2005
Posts: 30


I am working on custom BitCloud software for an endpoint that will communicate with a SerialNet coordinator. Is this configuration supported?

So far, I am unable to get the endpoint to join the PAN. I have my PAN set the same. In SerialNet:

Code:
AT+WPANID?
+WPANID:AAAAAAAAAAAAAA10


On the endpoind, in Configuration:

Code:
CS_EXT_PANID = 0xAAAAAAAAAAAAAA10LL


I have the channel mask on the endpoint set to all 2.4ghz channels:

Code:
CS_CHANNEL_MASK = 0x7FFF800l


When the endpoint starts I never recieve a joined message on the SerialNet. I have tested the two physical devices, both running SerialNet, and they were able to communicate.

I copied the Makefile and Configuration file from the lowpower example. The code is a copy/paste mostly from the lowpower example and the user's guide. It is very basic, only currently intended to join the network. The code I used is:

Code:
#include <zdo.h>
#include <usart.h> 

#define NWK_ADDR 10
#define NWK_UID 0x11AAAAAAAAAAAA10LL


#define APP_USART_TX_BUFFER_SIZE             500        // USART Tx buffer size

// USART Tx buffer
static uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE];

// USART descriptor (required by stack)
static HAL_UsartDescriptor_t usartDescriptor =
{
  .tty             = APP_USART_CHANNEL,
  .mode            = USART_MODE_ASYNC,
  .baudrate        = USART_BAUDRATE_38400,
  .dataLength      = USART_DATA8,
  .parity          = USART_PARITY_NONE,
  .stopbits        = USART_STOPBIT_1,
  .rxBuffer        = NULL,
  .rxBufferLength  = 0,
  .txBuffer        = usartTxBuffer,
  .txBufferLength  = APP_USART_TX_BUFFER_SIZE,
  .rxCallback      = NULL,
  .txCallback      = NULL,
  .flowControl     = USART_FLOW_CONTROL_NONE,
};

void init(void);
static void startNetwork(void);

typedef enum
{
   SENSOR_STATE_INITIAL,          // Initial (after RESET) state
   SENSOR_STATE_JOINING,          // Wait while higher layer join network
   SENSOR_STATE_JOINED,           // Joined network
   SENSOR_STATE_START_MEASURE,    // Device is not in sleep state and the temperature must be measured
   SENSOR_STATE_MEASURING,        // Temperature measuring
   SENSOR_STATE_MESSAGE_SENDING,  // Current temperature sending to the coordinator
   SENSOR_STATE_SLEEP_PREPARE,    // Message was sent successfully. Node ready to sleep.
   SENSOR_STATE_SLEEP,            // Actually sleep state
   SENSOR_STATE_AWAKENING         // Node was interrupted. Awakening.
} SensorState_t;

static SensorState_t sensorState = SENSOR_STATE_INITIAL;    // Current device state

static ZDO_StartNetworkReq_t  zdoStartNetworkReq;              // Request parameters for network start


/*******************************************************************************
  Description: application task handler.

  Parameters: none.
 
  Returns: nothing.
*******************************************************************************/
void APL_TaskHandler(void)
{
   if(sensorState != SENSOR_STATE_INITIAL)
   {
      char msg[] = "Task";
      HAL_WriteUsart  (&usartDescriptor, msg, 4);
   }

   switch (sensorState)
   {
      // node is in initial state
      case SENSOR_STATE_INITIAL:          // Initial (after RESET) state
         init();
         break;
      case SENSOR_STATE_JOINING:          // Wait while higher layer join network
         break;
      case SENSOR_STATE_JOINED:           // Joined network
         break;
      case SENSOR_STATE_START_MEASURE:    // Device is not in sleep state and the temperature must be measured
      case SENSOR_STATE_MEASURING:        // Temperature measuring
      case SENSOR_STATE_MESSAGE_SENDING:  // Current temperature sending to the coordinator
      case SENSOR_STATE_SLEEP_PREPARE:    // Message was sent successfully. Node ready to sleep.
      case SENSOR_STATE_SLEEP:            // Actually sleep state
      case SENSOR_STATE_AWAKENING:        // Node was interrupted. Awakening.
         break;
   }
}


/*******************************************************************************
  Description: just a stub.

  Parameters: are not used.
 
  Returns: nothing.
*******************************************************************************/
void ZDO_MgmtNwkUpdateNotf(ZDO_MgmtNwkUpdateNotf_t *nwkParams)
{
   nwkParams = nwkParams;  // Unused parameter warning prevention
}


/*******************************************************************************
  Description: just a stub.

  Parameters: none.
 
  Returns: nothing.
*******************************************************************************/
void ZDO_WakeUpInd(void)
{
}

/*******************************************************************************
  Description: just a stub.

  Parameters: none.
 
  Returns: nothing.
*******************************************************************************/
void ZDO_SleepInd(void)
{
}

/********************************************************************
  Description: ZDO_StartNetwork primitive confirmation was received.
  Parameters: confirmInfo - confirmation information
  Returns:    none
********************************************************************/
static void ZDO_StartNetworkConf(ZDO_StartNetworkConf_t *confInfo)
{
   char msg[] = "NWKConf";
   HAL_WriteUsart  (&usartDescriptor, msg, 7);

   // Joined network successfully
   if (ZDO_SUCCESS_STATUS == confInfo->status)     // Network was started successfully
   {
      char msg[] = "NWKSucc";
      HAL_WriteUsart  (&usartDescriptor, msg, 7);

      sensorState = SENSOR_STATE_JOINED;

      SYS_PostTask(APL_TASK_ID);
   }
}

void init(void)
{
   HAL_OpenUsart(&usartDescriptor); // Open USART

   char msg[] = "INIT";
   HAL_WriteUsart  (&usartDescriptor, msg, 4);

   DeviceType_t appDeviceType = DEVICE_TYPE_END_DEVICE;
   CS_WriteParameter(CS_DEVICE_TYPE_ID, &appDeviceType);

   bool rxOnWhenIdle = false;
   CS_WriteParameter(CS_RX_ON_WHEN_IDLE_ID, &rxOnWhenIdle);

/*   // Set UID and short network address
   uint64_t nwkUID = NWK_UID;
   CS_WriteParameter(CS_UID_ID, &nwkUID);

   ShortAddr_t nwkAddr = NWK_ADDR;
   CS_WriteParameter(CS_NWK_ADDR_ID, &nwkAddr);
*/
   startNetwork();
}

static void startNetwork(void)
{
   zdoStartNetworkReq.ZDO_StartNetworkConf = ZDO_StartNetworkConf; // Network started confirm handler
   ZDO_StartNetworkReq(&zdoStartNetworkReq); // start network
   sensorState = SENSOR_STATE_JOINING;

   char msg[] = "NWKSTART";
   HAL_WriteUsart  (&usartDescriptor, msg, 8);

}


While debugging I get the "INIT" and "NWKSTART" messages as expected. I never get a "NWKConf".

I tried the code with all USART debug info commented out, mostly fearing HAL_WriteUsart() could not be called during a callback. It did not join the network.

I tried setting CS_UID_ID and CS_NWK_ADDR_ID both through the commented out code and through the Configuration file.

Anyone have any ideas? Is this configuration even supported by SerialNet, or must all nodes joining SerialNet also run SerialNet?


Thanks,
Mike
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jan 27, 2010 - 08:51 AM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4870
Location: San Jose, CA

Try to specify exact channel in CS_CHANNEL_MASK (on which coordinator is waiting).

First of all you need to find out why start confirm is never returned, this is not normal. Try starting coordinator instead of ED, is confirm returned?

Generally SerialNet must work with SerialNet, but they use regular ZigBee so at this point there should be no problems.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
mknoll
PostPosted: Jan 28, 2010 - 05:11 AM
Rookie


Joined: Aug 09, 2005
Posts: 30


I set the CS_CHANNEL_MASK on both to 20000, the device did not join the network.

I will try making the SerialNet node an end point and the BitCloud node the coordinator tomorrow.

I noted my WinAVR version is 20100110, but BitCloud's last release was on 11/09. Are they compatible? Is there a specific version of WinAVR I should be using?

Thanks agian,
Mike
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jan 28, 2010 - 06:19 AM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4870
Location: San Jose, CA

mknoll wrote:
I set the CS_CHANNEL_MASK on both to 20000, the device did not join the network.

But confirm is returned? Until confirmation is returned it useless to try to join devices.

mknoll wrote:
I noted my WinAVR version is 20100110, but BitCloud's last release was on 11/09. Are they compatible? Is there a specific version of WinAVR I should be using?


Generally it is not recommended to use different version of compiler. If nothing else will help try to change compiler version.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
mknoll
PostPosted: Jan 28, 2010 - 04:22 PM
Rookie


Joined: Aug 09, 2005
Posts: 30


Quote:
But confirm is returned? Until confirmation is returned it useless to try to join devices.


I think I may not understand the terminology correctly. I am calling ZDO_StartNetworkReq(), and not getting the callback. The SerialNet coordinator does not send any messages that the device has joined the network. Wouldn't the confirmation be confirming the end point joined the network?

Which version of WinAVR matches the BitCloud SDK from 11/09?

Thanks again,
Mike
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jan 28, 2010 - 05:58 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4870
Location: San Jose, CA

mknoll wrote:
I am calling ZDO_StartNetworkReq(), and not getting the callback.


This needs to be fixed first. Callback should be called anyway some time after request was called. Status field will show if node joined (or tell the reason for failure). This timeout may vary but should not exceed 15 seconds or so for channel mask with only one channel in it.

Post your code (complete, so I could compile it run here).

mknoll wrote:
Which version of WinAVR matches the BitCloud SDK from 11/09?


20090513
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
mknoll
PostPosted: Jan 28, 2010 - 07:08 PM
Rookie


Joined: Aug 09, 2005
Posts: 30


Quote:
20090513


I do not see a 20090513 version:

http://sourceforge.net/projects/winavr/files/

There is a 20090313, was that just a typo?

Thanks,
Mike
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jan 28, 2010 - 07:17 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4870
Location: San Jose, CA

mknoll wrote:
There is a 20090313, was that just a typo?


Not typo, just bad memory Smile You need 20090313.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
mknoll
PostPosted: Jan 29, 2010 - 12:11 AM
Rookie


Joined: Aug 09, 2005
Posts: 30


I switched to WinAVR-200913, which did not correct the issue.

I also tried switching the node to a coordinator, as you suggested. I have included my code below.

On the serial port I only received the "INIT" and "NWKSTART" messages, indicating the ZDO_StartNetworkReq() request was made. I let it run for a couple minutes and did not receive the expected "NWKJoin" or "NWKFail" messages indicating I received the ZDO_StartNetworkConf() callback.

I am very confused. How can a coordinator fail to start? My understanding is the coordinator is not dependent on any other nodes, so it should start regardless. Can you see any trouble with my code?

Thanks again,
Mike

Snippets from my Configuration file:

Code:

STACK_TYPE = ALL_DEVICES_TYPES

APP_NWK_NODE_ADDRESS = 0x0000

CS_NWK_UNIQUE_ADDR = true
CS_NEIB_TABLE_SIZE = 8
CS_MAX_CHILDREN_AMOUNT = 7
CS_MAX_CHILDREN_ROUTER_AMOUNT = 0
CS_ROUTE_TABLE_SIZE = 8
CS_END_DEVICE_SLEEP_PERIOD = 10000
#CS_CHANNEL_MASK = "(1l<<0x0f)"
CS_CHANNEL_MASK = 0x20000
CS_CHANNEL_PAGE = 0
CS_EXT_PANID = 0xAAAAAAAAAAAAAA10LL

CS_UID = 0x2222333344448810LL



Code:

Code:

#include <zdo.h>
#include <usart.h> 
#include <string.h>

#define NWK_ADDR 10
#define NWK_UID 0x11AAAAAAAAAAAA10LL


#define APP_USART_TX_BUFFER_SIZE             500        // USART Tx buffer size

// USART Tx buffer
static uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE];

// USART descriptor (required by stack)
static HAL_UsartDescriptor_t usartDescriptor =
{
  .tty             = APP_USART_CHANNEL,
  .mode            = USART_MODE_ASYNC,
  .baudrate        = USART_BAUDRATE_38400,
  .dataLength      = USART_DATA8,
  .parity          = USART_PARITY_NONE,
  .stopbits        = USART_STOPBIT_1,
  .rxBuffer        = NULL,
  .rxBufferLength  = 0,
  .txBuffer        = usartTxBuffer,
  .txBufferLength  = APP_USART_TX_BUFFER_SIZE,
  .rxCallback      = NULL,
  .txCallback      = NULL,
  .flowControl     = USART_FLOW_CONTROL_NONE,
};

void init(void);
static void startNetwork(void);

typedef enum
{
   SENSOR_STATE_INITIAL,          // Initial (after RESET) state
   SENSOR_STATE_JOINING,          // Wait while higher layer join network
   SENSOR_STATE_JOINED,           // Joined network
   SENSOR_STATE_NONETWORK,
   SENSOR_STATE_START_MEASURE,    // Device is not in sleep state and the temperature must be measured
   SENSOR_STATE_MEASURING,        // Temperature measuring
   SENSOR_STATE_MESSAGE_SENDING,  // Current temperature sending to the coordinator
   SENSOR_STATE_SLEEP_PREPARE,    // Message was sent successfully. Node ready to sleep.
   SENSOR_STATE_SLEEP,            // Actually sleep state
   SENSOR_STATE_AWAKENING         // Node was interrupted. Awakening.
} SensorState_t;

static SensorState_t sensorState = SENSOR_STATE_INITIAL;    // Current device state

static ZDO_StartNetworkReq_t  zdoStartNetworkReq;              // Request parameters for network start

static uint8_t msgBuffer[10];

/*******************************************************************************
  Description: application task handler.

  Parameters: none.
 
  Returns: nothing.
*******************************************************************************/
void APL_TaskHandler(void)
{
   if(sensorState != SENSOR_STATE_INITIAL)
   {
      memcpy(msgBuffer, "Task\n\r", 6);
      HAL_WriteUsart  (&usartDescriptor, msgBuffer, 6);
   }

   switch (sensorState)
   {
      // node is in initial state
      case SENSOR_STATE_INITIAL:          // Initial (after RESET) state
         init();
         break;

      case SENSOR_STATE_JOINING:          // Wait while higher layer join network
         break;
      case SENSOR_STATE_JOINED:           // Joined network
         memcpy(msgBuffer, "NWKJoin\n\r", 9);
         HAL_WriteUsart  (&usartDescriptor, msgBuffer, 9);
         break;

      case SENSOR_STATE_NONETWORK:
         memcpy(msgBuffer, "NWKFail\n\r", 9);
         HAL_WriteUsart  (&usartDescriptor, msgBuffer, 9);
         break;

      case SENSOR_STATE_START_MEASURE:    // Device is not in sleep state and the temperature must be measured
      case SENSOR_STATE_MEASURING:        // Temperature measuring
      case SENSOR_STATE_MESSAGE_SENDING:  // Current temperature sending to the coordinator
      case SENSOR_STATE_SLEEP_PREPARE:    // Message was sent successfully. Node ready to sleep.
      case SENSOR_STATE_SLEEP:            // Actually sleep state
      case SENSOR_STATE_AWAKENING:        // Node was interrupted. Awakening.
         break;
   }
}


/*******************************************************************************
  Description: just a stub.

  Parameters: are not used.
 
  Returns: nothing.
*******************************************************************************/
void ZDO_MgmtNwkUpdateNotf(ZDO_MgmtNwkUpdateNotf_t *nwkParams)
{
   nwkParams = nwkParams;  // Unused parameter warning prevention
}


/*******************************************************************************
  Description: just a stub.

  Parameters: none.
 
  Returns: nothing.
*******************************************************************************/
void ZDO_WakeUpInd(void)
{
}

/*******************************************************************************
  Description: just a stub.

  Parameters: none.
 
  Returns: nothing.
*******************************************************************************/
void ZDO_SleepInd(void)
{
}

/********************************************************************
  Description: ZDO_StartNetwork primitive confirmation was received.
  Parameters: confirmInfo - confirmation information
  Returns:    none
********************************************************************/
static void ZDO_StartNetworkConf(ZDO_StartNetworkConf_t *confInfo)
{
   // Joined network successfully
   if (ZDO_SUCCESS_STATUS == confInfo->status)     // Network was started successfully
   {
      sensorState = SENSOR_STATE_JOINED;

      SYS_PostTask(APL_TASK_ID);
   }
   else
   {
      sensorState = SENSOR_STATE_NONETWORK;

      SYS_PostTask(APL_TASK_ID);
   }
}

void init(void)
{
   HAL_OpenUsart(&usartDescriptor); // Open USART

   memcpy(msgBuffer, "INIT\n\r", 6);
   HAL_WriteUsart  (&usartDescriptor, msgBuffer, 6);

//   DeviceType_t appDeviceType = DEVICE_TYPE_END_DEVICE;
   DeviceType_t appDeviceType = DEVICE_TYPE_COORDINATOR;
   CS_WriteParameter(CS_DEVICE_TYPE_ID, &appDeviceType);

   bool rxOnWhenIdle = true;
   CS_WriteParameter(CS_RX_ON_WHEN_IDLE_ID, &rxOnWhenIdle);

/*   // Set UID and short network address
   uint64_t nwkUID = NWK_UID;
   CS_WriteParameter(CS_UID_ID, &nwkUID);

   ShortAddr_t nwkAddr = NWK_ADDR;
   CS_WriteParameter(CS_NWK_ADDR_ID, &nwkAddr);
*/
   startNetwork();
}

static void startNetwork(void)
{
   zdoStartNetworkReq.ZDO_StartNetworkConf = ZDO_StartNetworkConf; // Network started confirm handler
   ZDO_StartNetworkReq(&zdoStartNetworkReq); // start network
   sensorState = SENSOR_STATE_JOINING;

   memcpy(msgBuffer, "NWKSTART\n\r", 10);
   HAL_WriteUsart  (&usartDescriptor, msgBuffer, 10);

}
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jan 29, 2010 - 07:26 AM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4870
Location: San Jose, CA

mknoll wrote:
I am very confused. How can a coordinator fail to start? My understanding is the coordinator is not dependent on any other nodes, so it should start regardless. Can you see any trouble with my code?


Coordinator not failing to start, if it was callback would be called with error code. Something else is failing.

Code looks good. Attach complete code + Makefiles + everything that is needed to build application.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
mknoll
PostPosted: Jan 29, 2010 - 01:25 PM
Rookie


Joined: Aug 09, 2005
Posts: 30


Attached is my complete build directory.

Thanks again,
Mike
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jan 29, 2010 - 02:46 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4870
Location: San Jose, CA

I found a problem. That's my bad I did not remember that you not supposed to call stack functions in first APL_TaskHandler() invocation, it should be used only to set parameters. At least in current releases, it should work as expected in the near future.

To fix your code do following:

At the end of init():
Code:

  sensorState = SENSOR_STATE_START_NETWORK;
  SYS_PostTask(APL_TASK_ID);


And add SENSOR_STATE_START_NETWORK state in APL_TaskHandler() in which call startNetwork().

After doing so I've got:
Code:

INIT
Task
NWKSTART
Task
NWKJoin
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
mknoll
PostPosted: Jan 30, 2010 - 02:13 AM
Rookie


Joined: Aug 09, 2005
Posts: 30


I got the same results. Thank you very much for your help.

Mike
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits