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
gatebit
PostPosted: Jul 17, 2012 - 11:46 AM
Newbie


Joined: Jul 17, 2012
Posts: 6


In addition here is my APL_TaskHandler function:

Code:

void APL_TaskHandler(void)
{
  switch (appState)
  {
    // Node has initial state
    case APP_INITING_STATE:
      simpleDescriptor.AppDeviceId = CPU_TO_LE16(1);
      simpleDescriptor.AppProfileId = CPU_TO_LE16(1);
      simpleDescriptor.endpoint = END_POINT;
      simpleDescriptor.AppDeviceVersion = 1;

      BSP_OpenLeds();
      endpointParams.simpleDescriptor = &simpleDescriptor;

        // All other states mean Router
        appDeviceType = DEVICE_TYPE_ROUTER;
        endpointParams.APS_DataInd = NULL;

      CS_WriteParameter(CS_DEVICE_TYPE_ID, &appDeviceType);
      appInitUARTManager();  // Init UART manager

      // Configure and start network starting timer
      startingNetworkTimer.interval = APP_TIMER_STARTING_NETWORK;
      startingNetworkTimer.mode     = TIMER_REPEAT_MODE;
      startingNetworkTimer.callback = startingNetworkTimerFired;
      HAL_StartAppTimer(&startingNetworkTimer);

      appState = APP_NETWORK_STARTING_STATE; // Switch state
      SYS_PostTask(APL_TASK_ID);
      break;

    case APP_NETWORK_STARTING_STATE:
      {
        // Configure network start parameters
        networkParams.ZDO_StartNetworkConf = ZDO_StartNetworkConf;

        // Start network
        ZDO_StartNetworkReq(&networkParams);
        break;
      }

    // Node is in network
    case APP_IN_NETWORK_STATE:

      appRouterTaskHandler();
      break;

    // Node is out of network
    case APP_NO_NETWORK_STATE:
      break;

    default:
      break;
  }
}


The configuration.h:
Code:

#ifndef _CONFIGURATION_H_
#define _CONFIGURATION_H_

//-----------------------------------------------
// Disables board-specific peripherals support
//-----------------------------------------------
//#define APP_DISABLE_BSP 1
#define APP_DISABLE_BSP 0

//-----------------------------------------------
// Includes board-specific peripherals support in application.
//-----------------------------------------------
#include <BoardConfig.h>

//-----------------------------------------------
// Atmel communication interfaces identifiers.
// Supported interfaces are platform and application dependent.
//-----------------------------------------------
#define APP_INTERFACE_USART 0x01
#define APP_INTERFACE_VCP 0x02
#define APP_INTERFACE_SPI 0x03
#define APP_INTERFACE_UART 0x04
#define APP_INTERFACE_USBFIFO 0x05

//-----------------------------------------------
// Atmel external memory identifiers.
// Supported memory is platform and application dependent.
//-----------------------------------------------
#define AT25F2048  0x01
#define AT45DB041  0x02
#define AT25DF041A 0x03

// Enables or disables request of APS Acknowledgement for outgoing frames.
#define APP_USE_APS_ACK 0
//#define APP_USE_APS_ACK 1

// Device type detection (for the boards without DIP switches)
//#define APP_DEVICE_TYPE DEV_TYPE_COORDINATOR
//Device is Router
#define APP_DEVICE_TYPE DEV_TYPE_ROUTER

// Period of sending throughput value to USART (ms)
#define APP_TIMER_TRACK_PERIOD 1000

// Packet transmission start delay (ms)
#define APP_TIMER_DELAY_PERIOD 1000

//-----------------------------------------------
//BOARD_MESHBEAN
//-----------------------------------------------
#ifdef BOARD_MESHBEAN
  // Enable this option if target board belongs to MNZB-EVBx family
  #define BSP_MNZB_EVB_SUPPORT 0
  //#define BSP_MNZB_EVB_SUPPORT 1
 
  // Defines primary serial interface type to be used by application.
  #define APP_INTERFACE APP_INTERFACE_USART
 
  // Defines USART interface name to be used by application.
  #define APP_USART_CHANNEL USART_CHANNEL_1
#endif

  // 32-bit mask of channels to be scanned before network is started. Channels that
  // should be used are marked with logical 1 at corresponding bit location.
  //  Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a
  //  Valid channel numbers for 900 MHz band are 0x00 - 0x0a
  //
  //  Notes:
  //  1. for small amount of enabled channels it is more convinient to specify list
  // of channels in the form of '(1ul << 0x0b)'
  //  2. For 900 MHz band you also need to specify channel page
  //
  //  Value range: 32-bit values:
  //  Valid channel numbers for 2.4 GHz band are 0x0b - 0x1a
  //  Valid channel numbers for 900 MHz band are 0x00 - 0x0a
  //
  //  C-type: uint32_t
  //  Can be set: at any time before network start
  //  Persistent: Yes
  #define CS_CHANNEL_MASK (1L<<0x0f)

// The parameter specifies the predefined extended PANID of the network to be
// formed (for the coordinator) or joined (for a router or an end device). For a
// router or an end device the parameter can equal 0 allowing them to join the
// first suitable network that they discover.
//
//  Value range: All 64-bit values except for 0xFFFFFFFFFFFFFFFFLL; specify a value
// in the 0x123456789ABCDEFLL format.
//  C-type: ExtPanId_t (equal to uint64_t)
//  Can be set: at any time before network start
//  Persistent: Yes
#define CS_EXT_PANID 0xAAAAAAAAAAAAAAAALL

// 64-bit Unique Identifier (UID) determining the device extended address. If this
// value is 0 stack will try to read hardware UID from external UID or EEPROM chip.
// at startup. Location of hardware UID is platform dependend and it may not be
// available on all platforms. If the latter case then UID value must be provided
// by user via this parameter. This parameter must be unique for each device in a
// network.
//
//  Value range: any 64-bit value except for broadcast extended addresses
//  C-type: ExtAddr_t
//  Can be set: at any time before network start
//  Persistent: Yes
#define CS_UID 0x0123456789012377LL

// The maximum number of direct children that a given device (the coordinator or a
// router) can have.
//
//  The parameter is only enabled for routers and the coordinator. An end device
// can not have children. If an actual number of children reaches a parameter's
// value, the node will have not been able to accept any more children joining the
// network. The parameter can be set to 0 on a router thus preventing it from
// accepting any children and can help form a desired network topology. For
// example, if the parameter is set to 0 on all routers, then the coordinator will
// be the only device that can have children and the network will have star
// topology.
//
//  Value range: from 0 to CS_NEIB_TABLE_SIZE
//  C-type: uint8_t
//  Can be set: at compile time only
//  Persistent: No
#define CS_MAX_CHILDREN_AMOUNT 2

// The maximum number of routers among the direct children of the device
//
//  The parameter determines how many routers the device can have as children. Note
// that the maximum number of end devices is equal to CS_MAX_CHILDREN_AMOUNT -
// CS_MAX_CHILDREN_ROUTER_AMOUNT.
//
//  Value range: from 0 to CS_MAX_CHILDREN_AMOUNT
//  C-type: uint8_t
//  Can be set: at compile time only
//  Persistent: No
#define CS_MAX_CHILDREN_ROUTER_AMOUNT 2

// Network depht limits amount of hops that packet may travel in the network.
// Actual maximum number of hops is network depth multiplied by 2.
//
//  The parameter determines the maximum depth of a network tree formed by
// child-parent relationships between nodes.
//
//  While joining the network the node receives beacon responses from potential
// parents containing their actual network depth and declines those which show
// values not less than the maximum network depth on the joining device. A
// potential parent will also reject a beacon from the joining device and will not
// sent a response if the joining device shows the network depth greater than it is
// allowed on the potential parent. This logic is enabled if the parameter value is
// not greater than 15. If its value is greater than 15, then device does not
// perform any checkings of the network depth, neither when joining a network nor
// when accepting other nodes as children. This allows forming long chains of
// devices across considerable distances.
//
//  The stack also uses the parameter to calculate several timeouts. Besides, the
// parameter determines the maximum radius of a data packet, that is, the maximum
// number of hops that a packet may travel, which is calculated by the following
// formula:
//
//  maximum radius = 2 * MIN(2 * maxNetworkDepth, 255)
//
//
//  These uses of the parameter do not change if its value is greater than 15.
// Therefore to enable transmitting data over long chains of devices, the parameter
// should be set to a real desired network depth, rather than to an accidental
// value over 15.
//
//  The parameter should be the same on all devices in the network.
//
//  Value range: from 0 to 255
//  C-type: uint8_t
//  Can be set: at compile time only
//  Persistent: No
#define CS_MAX_NETWORK_DEPTH 2


And I am using the Makefile_All_ZigBit_Atmega1281_Rf230B_8Mhz_Gcc configration.

Thank you very much for the help in advance!
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jul 17, 2012 - 05:04 PM
Raving lunatic


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

Code returned in StartNetworkConf is a combination of all possible codes from all layers. Prefix ZDO_* just indicates that those codes originate on ZDO layer. In your case it is likely to be one of NWK or PHY codes.

So just print the number and look what it is.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
gatebit
PostPosted: Jul 17, 2012 - 06:26 PM
Newbie


Joined: Jul 17, 2012
Posts: 6


Thanks for you quick reply.
I get 0xEA!
I have checked in the API Reference and this status code belongs to NWK_MAC_NO_BEACON_STATUS (A scan operation failed to find any network beacons.).
Why do I not get ZDO_NO_NETWORKS_STATUS (No network was found.) instead?

So it means that the problem is on the coordinator side?
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jul 17, 2012 - 06:30 PM
Raving lunatic


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

ZDO_NO_NETWORKS_STATUS is returned when there were beacons received, but none of them was suitable (wrong PAN ID, no space to join, etc).

NWK_MAC_NO_BEACON_STATUS means that there were no beacons. If you are sure that your coordinator is properly configured and is on, then it is possible that there are problems with your hardware.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
gatebit
PostPosted: Jul 20, 2012 - 12:01 PM
Newbie


Joined: Jul 17, 2012
Posts: 6


alexru, thanks for your help! However, I can't get the demo programs supplied with the BitCloud stack version 1.14 run! Routers and End devices aren't connecting to the Coordinator.

I was managed to download the earlier 1.13 version of the stack and for my surprise, all of the demo programs are working as a charm! I have to modify only the configuration.h and I have no problem at all.
A really strange thing, if I compile the code for the coordinator with the 1.14 stack, it is working fine with the 1.13 router and 1.13 end device code, but not with the 1.14 router/end device. So according to my earlier post, where I get NO_BEACON_STATUS on my router (1.14), it can not be right, because 1.13 devices can connect to the coordinator.

Any ideas? I can hardly belive that something is wrong with the fresh stack version...


Last edited by gatebit on Jul 20, 2012 - 06:01 PM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jul 20, 2012 - 04:52 PM
Raving lunatic


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

Check CS_UID parameter. It should be non-zero and unique to each node.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
gatebit
PostPosted: Jul 20, 2012 - 06:00 PM
Newbie


Joined: Jul 17, 2012
Posts: 6


I changed the CS_UID parameter in the configuration.h every time I recompiled the project (Coordinator, Router, End device).
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jul 20, 2012 - 06:51 PM
Raving lunatic


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

This is really weird, I don't know what might cause this. I would check it myself, but I just don't have any time to spare, and this probably will be this way for 1-2 weeks.

I'm assuming you don't have a sniffer?

Anyway this seems like a very specific problem that should be easy to reproduce, so you may want to contact avr@atmel.com.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
gatebit
PostPosted: Jul 20, 2012 - 06:59 PM
Newbie


Joined: Jul 17, 2012
Posts: 6


At the moment I have got no time to investigate as well. I'm happy that I have no problem with the 1.13 stack so far, I will use this version in my project.
On the other hand, I'm curious too, so I will probably contact ATMEL.
 
 View user's profile Send private message  
Reply with quote Back to top
0xCAFE10CC
PostPosted: Dec 16, 2012 - 01:26 AM
Newbie


Joined: Dec 15, 2012
Posts: 2


Hallo, I'm trying to use module ATZB-24-A2 with my own simple PCB and sample project Blink.
There are connected 3 LEDS, 3 buttons and 3 sliders according to Meshnetisc schematics (http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=1016670#1016670).
I'm using BitCloud_ZIGBIT_1_14_0 and Atmel AVR Toolchain 3.4.1. Compiled Blink.srec was copied with bootloader into module.

For some reason LEDs connected to GPIO-GPIO2 does not blink.

Measured values:
Vcc = 2.99V Icc=2.6mA
CPU_CLK: f=1.00MHz Vpp=2.9V
OSC32K_OUT: f~32.761kHz, Vpp=931mV

When I'm copying original file WSNDemo_Coord_Rf230B.srec to module then after reset and after about 2 seconds flash two LEDs (G+B) for about 0.2 s. Then lit red LED. So LEDs are connected properly. But I think there should also some LED blink.

In Makefile I'm using setting:
Code:
PROJECT_NAME = MeshBean
CONFIG_NAME = All_ZigBit_Atmega1281_Rf230B_8Mhz_Gcc


In configuration.h I have added after #include <BoardConfig.h> (according to http://www.avrfreaks.net/index.php?name ... 6#822696):
Code:
#undef _TEMPERATURE_SENSOR_
#undef _LIGHT_SENSOR_
#undef _BATTERY_SENSOR_
#undef _SLIDERS_
#undef _BUTTONS_
#undef _LCD_
#define OMIT_READING_SENSORS


and also changed CS_UID to:
Code:
#define CS_UID 0x01LL


What can I do to make LEDs blinking with firmware Blink.srec?
Thanks.
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Dec 17, 2012 - 05:05 PM
Raving lunatic


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

Blink is very basic, so all those changes you've made are not necessary (except may be CS_UID), it should just work.

Your problem might be related to this topic: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=123950. Just make changes to the linker file as described and it should work fine.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
0xCAFE10CC
PostPosted: Dec 17, 2012 - 11:34 PM
Newbie


Joined: Dec 15, 2012
Posts: 2


Hallo alexru, thank you for answer. Then it was not hard to find a solution.

I made changes in linkerScr/atmega1281.ld:
Code:
- after KEEP (*(.init8)) was added
*(.init9)
KEEP (*(.init9))

- deleted DISCARD section:
/DISCARD/ :
{
  *(.init9)
  *(.fini*)
}


Now is generated file bigger.
Code:
old:
   text      data       bss       dec       hex   filename
   5276      4096      2490     11862      2e56   All_ZigBit_Atmega1281_Rf230B_8Mhz_Gcc/Exe/Blink.elf
new:
   text      data       bss       dec       hex   filename
  94750      4256      4257    103263     1935f   All_ZigBit_Atmega1281_Rf230B_8Mhz_Gcc/Exe/Blink.elf


And it works - blinks !
Thank you very much.
 
 View user's profile Send private message  
Reply with quote Back to top
ssergeievich
PostPosted: Feb 20, 2013 - 10:42 AM
Newbie


Joined: Nov 24, 2008
Posts: 17


Hello guys,

I have implemented some firmware that uses BitCloud stack, based on SerialNet firmware (with AT commands). Response to one of my query commands (AT+SENS?) is 10bit ADC readouts from 4 ADC channels (ADC0,1,2,3) and is working excellent. Now, I would like to use all of the available ATZB-24-A2 ADC channels (all 8 channels) of the MCU ATMEGA1281, by disabling JTAG in firmware. Unfortunately, this doesn't work. Sad

Here is the code:
Code:
      // Disabling the JTAG - must be executed twice within 4 clock cycles
      MCUCR |=(1<<JTD);
      MCUCR |=(1<<JTD);
      
      Uint16   tempVal;
      char   i;
      tempStr[0] = 0;
      tempResults[0] = 0;      
      
      for(i=0;i<8;i++)
      {
         mibSrv.adcConf = 1<<i;
         adcOpen(mibSrv.adcConf);
         adcStart(i);
         while (!adcGet(&tempVal));
         adcClose();
         utoa(tempVal,tempStr,10);
         strcat(tempResults,tempStr);
         if(i<3)
            strcat(tempResults,",");
         tempStr[0] = 0;
      }
      
      
      
      // Parameter write out
      pParam->subParams[0].str = tempResults;
      resCode = SN_RES_CODE_OK;

I have also added all these channels to the enum HAL_AdcChannelNumber_t - HAL_ADC_CHANNEL4, 5, 6 and 7 in adc.h in BitCloud stack->include folder.

Does anyone have an idea how this should be implemented?

Best regards,
Sergei
 
 View user's profile Send private message  
Reply with quote Back to top
ssergeievich
PostPosted: Feb 20, 2013 - 11:13 AM
Newbie


Joined: Nov 24, 2008
Posts: 17


Me again... Smile

I am providing you with additional info concerning my previous question. So, here is the code for the functions used in prev. post:

Code:

void adcOpen(Uint8 channel)
{
  adcParam.bufferPointer = &sample;
  adcParam.callback = adcCalback;
  adcParam.voltageReference = AREF;
  adcParam.resolution = RESOLUTION_10_BIT;
  adcParam.sampleRate = ADC_4800SPS;
  adcParam.selectionsAmount = 2;
  HAL_OpenAdc(&adcParam);
  adcState = IDLE;
  adcMask = channel;
}
void adcClose(void)
{
  adcMask = 0;
  HAL_CloseAdc();
}
void adcStart(Uint8 channel)
{
  volatile Uint8 i = (1 << channel);
  HAL_AdcChannelNumber_t adcChannel = HAL_ADC_CHANNEL0;
  if(0 != (adcMask & i))
  {
    adcState = BUSY;
    switch (channel)
    {
     
     case 0:
      adcChannel = HAL_ADC_CHANNEL0;
      break;
     // :ajkalos}
     case 1:
        adcChannel = HAL_ADC_CHANNEL1;
        break;
      case 2:
        adcChannel = HAL_ADC_CHANNEL2;
        break;
      case 3:
        adcChannel = HAL_ADC_CHANNEL3;
        break;
     
      case 4:
        adcChannel = HAL_ADC_CHANNEL4;
        break;
     case 5:
        adcChannel = HAL_ADC_CHANNEL5;
        break;
     case 6:
        adcChannel = HAL_ADC_CHANNEL6;
        break;
     case 7:
        adcChannel = HAL_ADC_CHANNEL7;
        break;
    
      default:
        adcChannel = -1;//HAL_ADC_CHANNEL0;
    }
    HAL_ReadAdc(adcChannel);
  }
}
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Feb 20, 2013 - 05:02 PM
Raving lunatic


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

Just adding lines to enum is not enough, you also need to change the code that handles ADC. Look at the function halStartAdc() in HAL\avr\atmega1281\common\src\halAdc.c. The first if will treat your extended channels as differential channels.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
ssergeievich
PostPosted: Feb 21, 2013 - 12:22 PM
Newbie


Joined: Nov 24, 2008
Posts: 17


Thank you alexru once again for pointing me to the right track. For others which might have the same problem, I made these changes in BitCloud halADC.c - halStartAdc function (disabling digital inputs on appropriate pins):
Code:
if (HAL_ADC_CHANNEL7 >= channel) // instead HAL_ADC_CHANNEL3 >= channel
  {
    DIDR0 = (1 << channel);
  }

and also this small change of function HAL_ReadAdc in adc.c (for returning the correct ADC readout):

Code:
if (((channel > HAL_ADC_CHANNEL7) && (channel < HAL_ADC_DIFF_CHANNEL0)) || (channel > HAL_ADC_DIFF_CHANNEL7))  // instead channel > HAL_ADC_CHANNEL3
    return -1;

Everything works perfectly right now.

Regards,
Sergei
 
 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