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_mdb1.h File Reference

public methods for hal_mdb1.c More...

`#include "msp430x24x.h"`
`#include <stdio.h>`
`#include "../Common/utilities.h"`

## Macros
#define | HAL_SLEEP() ( __bis_SR_register(LPM3_bits + GIE))
#define | HAL_WAKEUP() ( __bic_SR_register_on_exit(LPM3_bits))
#define | NUMBER_OF_LEDS 6
#define | STATUS_LED_RED BIT6
#define | STATUS_LED_GREEN BIT7
#define | STATUS_LED_YELLOW (BIT6+BIT7)
#define | STATUS_LED_OFF 0
#define | ALL_LEDS_OFF 0x3F
#define | SRDY_INTERRUPT_FALLING_EDGE 0x01
#define | SRDY_INTERRUPT_RISING_EDGE 0x00
#define | RADIO_ON() (P1OUT |= BIT2)
#define | RADIO_OFF() (P1OUT &= ~BIT2)
#define | SPI_SS_SET() (P5OUT &= ~BIT0)
#define | SPI_SS_CLEAR() (P5OUT |= BIT0)
#define | SRDY_IS_HIGH() (P1IN & BIT3)
#define | SRDY_IS_LOW() ((~P1IN) & BIT3)
#define | HAL_ENABLE_INTERRUPTS() (_EINT())
#define | HAL_DISABLE_INTERRUPTS() (_DINT())
#define | DEBUG_ON() (P6OUT |= BIT6)
#define | DEBUG_OFF() (P6OUT &= BIT6)
#define | DEBUG_TOGGLE() (P6OUT ^= BIT6)
#define | GET_MCLK_FREQ() 8000000L
#define | HAL_GET_SMCLK() 4000000L
#define | XTAL 8000000L
#define | RTS_OFF() (P1OUT |= BIT0)
#define | RTS_ON() (P1OUT &= ~BIT0)
#define | SET_LED0_PIN_DIRECTION() (P4DIR = BIT0)
#define | MASTER_BUTTON_0 0x00
#define | MASTER_BUTTON_1 0x01
#define | MASTER_BUTTON_2 0x02
#define | MASTER_BUTTON_3 0x03
#define | MASTER_BUTTON_4 0x04
#define | BUTTON_LEDS_OFF 0xFF
#define | DEBUG_CONSOLE_INIT(baud) (halUartInit(USCIA0, baud))
#define | AUX_SERIAL_PORT_INIT(baud) (halUartInit(USCIA1, baud))
#define | TIMER_A 0
#define | TIMER_B 1
#define | NO_WAKEUP 0
#define | WAKEUP_AFTER_TIMER 1
#define | WAKEUP_AFTER_SRDY 4
#define | HAL_STOP_TIMER_A() TACTL = MC_0;
#define | TIMER_MAX_SECONDS 4
#define | BIT_BANG_TX0_PORT P2OUT
#define | BIT_BANG_TX0_BIT BIT6
#define | BIT_BANG_RX0_PORT P1IN
#define | BIT_BANG_RX0_BIT BIT4
#define | DISABLE_BIT_BANG_RX0_INTERRUPT() (P1IE &= ~BIT4)
#define | ENABLE_BIT_BANG_RX0_INTERRUPT() (P1IE |= BIT4)
#define | BIT_BANG_TX1_PORT P2OUT
#define | BIT_BANG_TX1_BIT BIT7
#define | BIT_BANG_RX1_PORT P1IN
#define | BIT_BANG_RX1_BIT BIT5
#define | DISABLE_BIT_BANG_RX1_INTERRUPT() (P1IE &= ~BIT5)
#define | ENABLE_BIT_BANG_RX1_INTERRUPT() (P1IE |= BIT5)
#define | TOGGLE_DEBUG_PIN() (P4OUT ^= BIT5)
#define | RELAY_0_0FF_PORT P5OUT
#define | RELAY_0_0FF_PIN BIT5
#define | RELAY_0_ON_PORT P5OUT
#define | RELAY_0_ON_PIN BIT4
#define | RELAY_1_0FF_PORT P5OUT
#define | RELAY_1_0FF_PIN BIT7
#define | RELAY_1_ON_PORT P5OUT
#define | RELAY_1_ON_PIN BIT6

## Functions
void | halInit ()
void | toggleLed (unsigned char whichLed)
signed int | setLed (unsigned char led)
void | clearLeds ()
void | halSpiInitModule ()
void | spiWrite (unsigned char *bytes, unsigned char numBytes)
void | setModuleInterfaceToInputs (void)
signed int | initTimer (unsigned char seconds, unsigned char wakeOnTimer)
void | delayMs (unsigned int ms)
void | halEnableAuxFlowControl ()
void | oscInit ()
unsigned char | getSwitches ()
unsigned char | getButtons ()
signed char | setStatusLed (unsigned char color)
void | setButtonLeds (unsigned char buttonId)
void | clearButtonLeds ()
int | putcharAux (int c)
unsigned int | getVcc3 ()
unsigned int | getVddUnregulated ()
void | halSetAllPinsToInputs ()

## Detailed Description

public methods for hal_mdb1.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

void clearButtonLeds | ( |  | ) |

    Turns off the button LEDs and leaves status LED unchanged.

Postcondition:
  button LEDs are all off. Status LED is in the same state as it was before the method was called.

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 char getButtons | ( |  | ) |

    Reads the current status of the buttons

Returns:
  0x01 if button 1 is pressed, 0x02 if button 2 is pressed, 0x04 if button 3 is pressed, etc.

unsigned char getSwitches | ( |  | ) |

Read value of the two Dual In-Line Package (DIP) switches.

Returns:
  the state of the switches as a number from 0 to 3.

Precondition:
  DIP Switches (P2.6, P2.7) are configured as digital inputs with pull-DOWNs

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

unsigned int getVddUnregulated | ( |  | ) |

    Measures Unregulated input voltage. This feeds a 10k/1k 1% resistor divider to the MSP430 ADC input A3.

- ADC measures VCC/11 compared to 2.5V reference
- If VddUnregulated = 8V, ADC output should be (0.727/2.5)*4095 = 1191
- (eleventh8V8/2.5)*4095 = ADC reading and (8V8/2.5)*4095 = 11*ADC
- Vcc*4096 = 27.5*ADC –> and VCC=27.5*ADC/4095
- V = 8 then Vccunreg/11 = 0.801, or 2187 adc counts if using 1.5V reference
  Returns:
    Vdd Unregulated in millivolts

void halEnableAuxFlowControl | ( |  | ) |

Enables flow control (makes the pin an output) and enables communications to occur.

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

int putcharAux | ( | int | c | ) |

Send one byte via hardware UART to the auxilliary serial port. Aux Serial Port is USCIA1.

void setButtonLeds | ( | unsigned char | led | ) |

    Turns on the specified button LED. Leaves status LED unchanged.

Note:
  Button LEDs are active-LOW, Status LED is active-HIGH.

Parameters:

  whichLed | the LED to turn on.

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

signed char setStatusLed | ( | unsigned char | color | ) |

LED Control Sets the status LED to a particular color. Leaves the other LEDs unchanged. The status LED is a two-element LED (red+green) that is capable of displaying red, green, or yellow.

Note:
  Button LEDs are active-LOW, Status LED is active-HIGH.

Parameters:

  color | the color to set, must be STATUS_LED_RED, STATUS_LED_GREEN, or STATUS_LED_YELLOW.

Returns:
  -1 if invalid color, 0 if success

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

void 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.