Zigbee Module Examples

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
hal_mdb2.h File Reference

public methods for hal_mdb2.c More...

`#include "hal_mdb2.h"`
`#include "msp430x22x4.h"`

## Macros
#define | HAL_SLEEP() ( __bis_SR_register(LPM3_bits + GIE))
#define | HAL_WAKEUP() ( __bic_SR_register_on_exit(LPM3_bits))
#define | ENABLE_SRDY_INTERRUPT() (P2IE |= BIT6)
#define | DISABLE_SRDY_INTERRUPT() (P2IE &= ~BIT6)
#define | HAL_ENABLE_INTERRUPTS() (_EINT())
#define | HAL_DISABLE_INTERRUPTS() (_DINT())
#define | SRDY_INTERRUPT_FALLING_EDGE 0x01
#define | SRDY_INTERRUPT_RISING_EDGE 0x00
#define | RADIO_ON() (P3OUT |= BIT7)
#define | RADIO_OFF() (P3OUT &= ~BIT7)
#define | SET_LED0_PIN_DIRECTION() (P1DIR = BIT0)
#define | SPI_SS_SET() (P3OUT &= ~(BIT0 | BIT6))
#define | SPI_SS_CLEAR() (P3OUT |= (BIT0 | BIT6))
#define | SRDY_IS_HIGH() (P2IN & BIT6)
#define | SRDY_IS_LOW() ((~P2IN) & BIT6)
#define | DEBUG_ON() (P4OUT |= BIT4)
#define | DEBUG_OFF() (P4OUT &= BIT4)
#define | NO_WAKEUP 0
#define | WAKEUP_AFTER_TIMER 1
#define | WAKEUP_AFTER_BUTTON 2
#define | WAKEUP_AFTER_SRDY 4
#define | XTAL 8000000L
#define | TICKS_PER_MS (XTAL / 1000)
#define | VLO_NOMINAL 12000
#define | VLO_MIN (VLO_NOMINAL - (VLO_NOMINAL/4))
#define | VLO_MAX (VLO_NOMINAL + (VLO_NOMINAL/4))
#define | NUMBER_OF_LEDS 2

## Functions
void | halInit ()
void | delayMs (unsigned int ms)
void | delayUs (unsigned int us)
signed int | toggleLed (unsigned char led)
signed int | setLed (unsigned char led)
void | clearLeds ()
void | halSpiInitModule ()
void | spiWrite (unsigned char *bytes, unsigned char numBytes)
signed int | calibrateVlo ()
signed int | initTimer (unsigned char seconds)
void | oscInit ()
unsigned int | getVcc3 ()
void | halSetAllPinsToInputs (void)
signed int | halConfigureSrdyInterrrupt (unsigned char flags)

## Detailed Description

public methods for hal_mdb2.c

Rev:
  1642

Author:
  dsmith

Date:
  2012-10-31 11:17:04 -0700 (Wed, 31 Oct 2012)

# Support

Please refer to the wiki at www.anaren.com/air-wiki-zigbee for more information. Additional support is available via email at the following addresses:

- Questions on how to use the product: AIR@a.nosp@m.nare.nosp@m.n.com
- Feature requests, comments, and improvements: featu.nosp@m.rere.nosp@m.quest.nosp@m.s@te.nosp@m.slaco.nosp@m.ntro.nosp@m.ls.co.nosp@m.m
- Consulting engagements: sales.nosp@m.@tes.nosp@m.lacon.nosp@m.trol.nosp@m.s.com

# License

Copyright (c) 2012 Tesla Controls. All rights reserved. This Software may only be used with an Anaren A2530E24AZ1, A2530E24CZ1, A2530R24AZ1, or A2530R24CZ1 module. Redistribution and use in source and binary forms, with or without modification, are subject to the Software License Agreement in the file "anaren_eula.txt"

YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL ANAREN MICROWAVE OR TESLA CONTROLS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSE INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.

## Function Documentation

signed int calibrateVlo | ( |  | ) |

Required for compatibility with MSP430 libraries

Calibrate VLO. Once this is done, the VLO can be used semi-accurately for timers etc. Once calibrated, VLO is within ~2% of actual when using a 1% calibrated DCO frequency and temperature and supply voltage remain unchanged.

Returns:
  VLO frequency (number of VLO counts in 1sec), or -1 if out of range

Precondition:
  SMCLK is 4MHz
  MCLK is 8MHz
  ACLK sourced by VLO (BCSCTL3 = LFXT1S_2 in MSP430F2xxx)

Note:
  Calibration is only as good as MCLK source. Obviously, if using the internal DCO (+/- 1%) then this value will only be as good as +/- 1%. YMMV.
  On MSP430F248 or MSP430F22x2 or MSP430F22x4, must use TACCR2. On MSP430F20x2, must use TACCR0. On MSP430G2553, must use CCI0B on CCR0 Check device-specific datasheet to see which module block has ACLK as a compare input. Modify TACCTLx, TACCRx, and CCIS_x accordingly For example, see page 23 of the MSP430F24x datasheet or page 17 of the MSP430F20x2 datasheet, or page 18 of the MSP430F22x4 datasheet.
  If application will require accuracy over change in temperature or supply voltage, recommend calibrating VLO more often.

Postcondition:
  Timer A settings restored to what they were beforehand except for TACCR0 which is reset.

Required for compatibility with MSP430 libraries

Calibrate VLO. Once this is done, the VLO can be used semi-accurately for timers etc. Once calibrated, VLO is within ~2% of actual when using a 1% calibrated DCO frequency and temperature and supply voltage remain unchanged.

Returns:
  VLO frequency (number of VLO counts in 1sec), or -1 if out of range

Precondition:
  SMCLK is 4MHz
  MCLK is 8MHz
  ACLK sourced by VLO (BCSCTL3 = LFXT1S_2 in MSP430F2xxx)

Note:
  Calibration is only as good as MCLK source. Obviously, if using the internal DCO (+/- 1%) then this value will only be as good as +/- 1%. YMMV.
  On MSP430F248 or MSP430F22x2 or MSP430F22x4, must use TACCR2. On MSP430F20x2, must use TACCR0. On MSP430G2553, must use CCI0B on CCR0 Check device-specific datasheet to see which module block has ACLK as a compare input. Modify TACCTLx, TACCRx, and CCIS_x accordingly For example, see page 23 of the MSP430F24x datasheet or page 17 of the MSP430F20x2 datasheet, or page 18 of the MSP430F22x4 datasheet.
  If application will require accuracy over change in temperature or supply voltage, recommend calibrating VLO more often.

Postcondition:
  Timer A settings restored to what they were beforehand except for TACCR0 which is reset.

    Calibrate VLO. Once this is done, the VLO can be used semi-accurately for timers etc.

Once calibrated, VLO is within ~2% of actual when using a 1% calibrated DCO frequency and temperature and supply voltage remain unchanged.

Returns:
  VLO frequency (number of VLO counts in 1sec), or -1 if out of range

Precondition:
  SMCLK is 4MHz
  MCLK is 8MHz
  ACLK sourced by VLO (BCSCTL3 = LFXT1S_2; in MSP430F2xxx)

Note:
  Calibration is only as good as MCLK source. Obviously, if using the internal DCO (+/- 1%) then this value will only be as good as +/- 1%. YMMV.
  On MSP430F248 or MSP430F22x2 or MSP430F22x4, must use TACCR2. On MSP430F20x2, must use TACCR0. Check device-specific datasheet to see which module block has ACLK as a compare input. For example, see page 23 of the MSP430F24x datasheet or page 17 of the MSP430F20x2 datasheet, or page 18 of the MSP430F22x4 datasheet.
  If application will require accuracy over change in temperature or supply voltage, recommend calibrating VLO more often.

Postcondition:
  Timer A settings changed
  ACLK divide by 8 bit cleared

void clearLeds | ( |  | ) |

Turns OFF LEDs.

Postcondition:
  LEDs are turned off.

    Turns OFF the specified LED. Required for Module examples.

Parameters:

  led | the LED to turn off, must be 0,1,2,3,4.

Returns:
  0 if success, -1 if invalid LED specified

    Turns OFF LEDs.

Postcondition:
  LEDs are turned off.

void delayMs | ( | unsigned int | delay | ) |

    A fairly accurate blocking delay for waits in the millisecond range. Good for 1mSec to 1000mSec.

At 1MHz, error of zero for 100mSec or 1000mSec. For 10mSec, error of 100uSec. At 1mSec, error is 20uSec. At 8MHz, error of zero for 1000mSec. Note that accuracy will depend on the clock source. MSP430F2xx internal DCO is typically +/-1%. For better timing accuracy, use a timer, or a crystal.

Precondition:
  TICKS_IN_ONE_MS is defined correctly

Parameters:

  delay | number of milliseconds to delay

unsigned int getVcc3 | ( |  | ) |

Reads the MSP430 supply voltage using the Analog to Digital Converter (ADC) and internal voltage reference.

Returns:
  Vcc supply voltage, in millivolts

    Measures Vcc to the MSP430, nominally 3300mV

- ADC measures VCC/2 compared to 2.5V reference
- If Vcc = 3.3V, ADC output should be (1.65/2.5)*4095 = 2703
- (halfVcc/2.5)*4095 = ADC reading and (Vcc/2.5)*4095 = 2*ADC
- Vcc*4096 = 5*ADC –> and VCC=5*ADC/4095
  Returns:
    Vcc in millivolts

      Reads the MSP430 supply voltage using the Analog to Digital Converter (ADC).

  On MDB2, this is approx. 3600mV
  Returns:
    Vcc supply voltage, in millivolts

void halInit | ( |  | ) |

Configures hardware for the particular hardware platform:

- Ports: sets direction, interrupts, pullup/pulldown resistors etc.
- Holds radio in reset (active-low)

Configures hardware for the particular hardware platform:

- Ports: sets direction, interrupts, pullup/pulldown resistors etc.
- Holds radio in reset (active-low)
  Postcondition:
    the board is configured for proper operation.
  Configures hardware for the particular board
  - Initializes clocks
  - Ports: including purpose, direction, pullup/pulldown resistors etc.
  - Holds radio in reset (active-low)

void halSetAllPinsToInputs | ( | void |  | ) |

Configures all module interface signals as inputs to allow the module to be programmed. Toggles LED0 quickly to indicate application is running.

    Configures all module interface signals as inputs to allow the module to be programmed.

Toggles LED0 quickly to indicate application is running.

void halSpiInitModule | ( |  | ) |

Initializes the Serial Peripheral Interface (SPI) interface to the Zigbee Module (ZM).

Note:
  Maximum module SPI clock speed is 4MHz. SPI port configured for clock polarity of 0, clock phase of 0, and MSB first.
  The Stellaris LaunchPad uses SSI2 to communicate with module

Precondition:
  SPI pins configured correctly:
  - Clock, MOSI, MISO configured as SPI function
  - Chip Select configured as an output
  - SRDY configured as an input.

Postcondition:
  SPI port is configured for communications with the module.

Initializes the Serial Peripheral Interface (SPI) interface to the Zigbee Module (ZM).

Note:
  Maximum module SPI clock speed is 4MHz. SPI port configured for clock polarity of 0, clock phase of 0, and MSB first.
  On the FRAM board the MSP430 uses USCIB0 SPI port to communicate with the module.

Precondition:
  SPI pins configured correctly:
  - Clock, MOSI, MISO configured as SPI function
  - Chip Select configured as an output
  - SRDY configured as an input.

Postcondition:
  SPI port is configured for communications with the module.

Initializes the Serial Peripheral Interface (SPI) interface to the Zigbee Module (ZM).

Note:
  Maximum module SPI clock speed is 4MHz. SPI port configured for clock polarity of 0, clock phase of 0, and MSB first.
  On the MDB2 the MSP430 uses USCIB0 SPI port to communicate with the module.

Precondition:
  SPI pins configured correctly:
  - Clock, MOSI, MISO configured as SPI function
  - Chip Select configured as an output
  - SRDY configured as an input.

Postcondition:
  SPI port is configured for communications with the module.

Initializes the SPI interface to the Module.

Note:
  Module SPI clock speed < 4MHz. SPI port configured for clock polarity of 0, clock phase of 0, and MSB first.
  On MDB the RFIC SPI port is USCIB1
  Modify this method for other hardware implementations.

Precondition:
  SPI pins configured correctly: Clock, MOSI, MISO configured as SPI function; Chip Select configured as an output; SRDY configured as an input.

Postcondition:
  SPI port is configured for RFIC communications.

void oscInit | ( |  | ) |

Initializes Oscillator: configures MCLK to 25MHz using internal PLL (SYSCTL_USE_PLL) calibrated to 8MHz external crystal (SYSCTL_XTAL_8MHZ).

Note:
  PLL native frequency = 200MHz, so divide by 8 (SYSCTL_SYSDIV_8) to get 25MHz
  ADC requires either the PLL or a 16MHz clock source

Initializes Oscillator: turns off WDT, configures MCLK = 8MHz using internal DCO & sets SMCLK = 4MHz.

See also:
  MSP430FR57xx_UCS_01.c

Initializes Oscillator: turns off WDT, configures MCLK to 8MHz using internal DCO and sets SMCLK to 4MHz

    Initializes Oscillator

- turns off WDT
- Configures MCLK to 8MHz using internal DCO
- Sets SMCLK to 4MHz

- Configures ACLK to use external xtal.

  Initializes Oscillator: turns off WDT, configures MCLK = 8MHz using internal DCO & sets SMCLK = 4MHz

signed int setLed | ( | unsigned char | led | ) |

    Turns ON the specified LED.

Parameters:

  led | the LED to turn on, must be 0,1,2,3,4.

Returns:
  0 if success, -1 if invalid LED specified

void spiWrite | ( | unsigned char * | bytes,
|  | unsigned char | numBytes
| ) |  |

Sends a message over SPI to the Module. SPI uses a "write-to-read" approach to read data out, you must write data in. This is a private method that gets wrapped by other methods, e.g. spiSreq(), spiPoll(), etc. To Write, set *bytes, numBytes. To Read, set *bytes only. Don't need to set numBytes because Module will stop when no more bytes read.

Parameters:

  bytes | the data to be sent or received.
  numBytes | the number of bytes to be sent. This same buffer will be overwritten with the received data.

Note:
  Modify this method for other hardware implementations.

Precondition:
  SPI port configured for writing
  Module has been initialized

Postcondition:
  bytes contains received data, if any

See also:
  Stellaris Application Note spma002.pdf, "Adding 32kB of Serial SRAM to a Stellaris Microcontroller"

Used to communicate with Zigbee module

signed int toggleLed | ( | unsigned char | whichLed | ) |

    Toggles the specified button LED.

Parameters:

  whichLed | the LED to toggle, must be 0-4.

Postcondition:
  The specified button LED is toggled. Status LED is unchanged.

Todo:
  this should read from a globals file based on the type of device, how many LEDs, etc.