This is an experimental driver for the XBee 900 HP pro module's SPI connection. This driver is unfinished and stability is not guaranteed. Use with caution.

Dependents:   Sentinel_BASE Sentinel_NODE

Committer:
ottaviano3
Date:
Wed Apr 27 05:46:34 2016 +0000
Revision:
15:3bb82129f3a8
Parent:
14:55631bb4aa44
Update comment formatting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ottaviano3 0:8c8a8244e590 1 #ifndef XBEE900HP_H
ottaviano3 0:8c8a8244e590 2 #define XBEE900HP_H
ottaviano3 0:8c8a8244e590 3
ottaviano3 0:8c8a8244e590 4 #include "mbed.h"
ottaviano3 0:8c8a8244e590 5
ottaviano3 0:8c8a8244e590 6 /**
ottaviano3 0:8c8a8244e590 7 * Wrapper for the xBee 900 HP Module
ottaviano3 0:8c8a8244e590 8 */
ottaviano3 0:8c8a8244e590 9 class xbee900hp
ottaviano3 0:8c8a8244e590 10 {
ottaviano3 0:8c8a8244e590 11 public:
ottaviano3 0:8c8a8244e590 12
ottaviano3 7:3cb67634fa4e 13 /**
ottaviano3 0:8c8a8244e590 14 * Initialize the xBee Module
ottaviano3 9:d4542525b218 15 *
ottaviano3 14:55631bb4aa44 16 * @param pin_mosi -> mbed SPI MOSI pin
ottaviano3 14:55631bb4aa44 17 * @param pin_miso -> mbed SPI MISO pin
ottaviano3 14:55631bb4aa44 18 * @param pin_sck -> mbed SPI SCK pin
ottaviano3 14:55631bb4aa44 19 * @param pin_attn -> Signals that some message from the XBee module is available
ottaviano3 14:55631bb4aa44 20 * @param pin_rst -> Resets the XBee module
ottaviano3 14:55631bb4aa44 21 * @param freq -> sets the SPI clock frequency. The XBee has a maximum SPI clock rate of 3.5 MHz.
ottaviano3 7:3cb67634fa4e 22 */
ottaviano3 7:3cb67634fa4e 23 xbee900hp(PinName pin_mosi,PinName pin_miso,PinName pin_sck,PinName pin_attn, PinName pin_rst, unsigned int freq);
ottaviano3 7:3cb67634fa4e 24
ottaviano3 0:8c8a8244e590 25 /**
ottaviano3 0:8c8a8244e590 26 * Destructor
ottaviano3 0:8c8a8244e590 27 */
ottaviano3 0:8c8a8244e590 28 ~xbee900hp();
ottaviano3 7:3cb67634fa4e 29
ottaviano3 7:3cb67634fa4e 30 /**
ottaviano3 0:8c8a8244e590 31 * Subroutine to reset the xBee Module
ottaviano3 7:3cb67634fa4e 32 */
ottaviano3 0:8c8a8244e590 33 void reset();
ottaviano3 0:8c8a8244e590 34
ottaviano3 7:3cb67634fa4e 35 /**
ottaviano3 0:8c8a8244e590 36 * Send packet over spi to xBee for TX
ottaviano3 9:d4542525b218 37 *
ottaviano3 15:3bb82129f3a8 38 * @param data -> char array of the message to be sent wirelessly.
ottaviano3 15:3bb82129f3a8 39 * @param length -> then length of the char array excluding any null termination.
ottaviano3 15:3bb82129f3a8 40 * @param enMesh -> true enables DigiMesh.
ottaviano3 9:d4542525b218 41 *
ottaviano3 9:d4542525b218 42 * Returns 0 upon successful completion, else returns 1.
ottaviano3 7:3cb67634fa4e 43 */
ottaviano3 7:3cb67634fa4e 44 int sendPacket(char* data, unsigned int length, bool enMesh);
ottaviano3 7:3cb67634fa4e 45
ottaviano3 1:b97d46c5d7ce 46 /**
ottaviano3 7:3cb67634fa4e 47 * Get signal strength of last recieved packet
ottaviano3 9:d4542525b218 48 *
ottaviano3 9:d4542525b218 49 * Returns RSSI in -dBm units (0x00-0xFF), else returns 1 indicating failure.
ottaviano3 1:b97d46c5d7ce 50 */
ottaviano3 7:3cb67634fa4e 51 unsigned int getRSSI();
ottaviano3 7:3cb67634fa4e 52
ottaviano3 7:3cb67634fa4e 53 /**
ottaviano3 9:d4542525b218 54 * Set the transmission power level.
ottaviano3 15:3bb82129f3a8 55 * @param value integer value of power level. Acceptable values are 0-4.
ottaviano3 15:3bb82129f3a8 56 *
ottaviano3 15:3bb82129f3a8 57 * @returns
ottaviano3 15:3bb82129f3a8 58 * 0 upon success
ottaviano3 15:3bb82129f3a8 59 * 1 upon failure
ottaviano3 15:3bb82129f3a8 60 */
ottaviano3 15:3bb82129f3a8 61 /* Note
ottaviano3 11:9013b28438cb 62 * 0 = +7 dBm, (5 mW)
ottaviano3 11:9013b28438cb 63 * 1 = +15 dBm, (32 mW)
ottaviano3 11:9013b28438cb 64 * 2 = +18 dBm, (63 mW)
ottaviano3 11:9013b28438cb 65 * 3 = +21 dBm, (125 mW)
ottaviano3 11:9013b28438cb 66 * 4 = +24 dBm, (250 mW)
ottaviano3 7:3cb67634fa4e 67 */
ottaviano3 7:3cb67634fa4e 68 int setPower(int value);
ottaviano3 7:3cb67634fa4e 69
ottaviano3 2:7f4ddf710a44 70 /**
ottaviano3 9:d4542525b218 71 * Get serial number of XBee module
ottaviano3 9:d4542525b218 72 *
ottaviano3 9:d4542525b218 73 * Returns the XBee's unique 64-bit (0-0xFFFFFFFF) Serial/MAC address, else returns 1.
ottaviano3 3:3c3707b0f5cd 74 */
ottaviano3 7:3cb67634fa4e 75 unsigned long long getSerial();
ottaviano3 7:3cb67634fa4e 76
ottaviano3 3:3c3707b0f5cd 77 /**
ottaviano3 2:7f4ddf710a44 78 * Wait for and read incoming data packet
ottaviano3 9:d4542525b218 79 *
ottaviano3 15:3bb82129f3a8 80 * @param data -> A char array of sufficent size to contain any message you expect to recieve.
ottaviano3 15:3bb82129f3a8 81 *
ottaviano3 9:d4542525b218 82 * Returns the 64-bit (0-0xFFFFFFFF) Serial/MAC address of the sending XBee if successful, or 0 if it failed.
ottaviano3 2:7f4ddf710a44 83 */
ottaviano3 7:3cb67634fa4e 84 unsigned long long readPacket(char* data);
ottaviano3 7:3cb67634fa4e 85
ottaviano3 2:7f4ddf710a44 86 /**
ottaviano3 6:3873db4a0164 87 * Clear output buffer
ottaviano3 6:3873db4a0164 88 */
ottaviano3 6:3873db4a0164 89 void clearBuff();
ottaviano3 7:3cb67634fa4e 90
ottaviano3 6:3873db4a0164 91 /**
ottaviano3 2:7f4ddf710a44 92 * Check ATTN signal
ottaviano3 9:d4542525b218 93 *
ottaviano3 9:d4542525b218 94 * Returns the state of the ATTN pin.
ottaviano3 9:d4542525b218 95 * NOTE: This pin is inverse logic. (i.e. 0 = message waiting, 1 = no messages availiable)
ottaviano3 2:7f4ddf710a44 96 */
ottaviano3 2:7f4ddf710a44 97 int attn();
ottaviano3 7:3cb67634fa4e 98
ottaviano3 7:3cb67634fa4e 99 /**
ottaviano3 7:3cb67634fa4e 100 * Read raw data in from module
ottaviano3 9:d4542525b218 101 *
ottaviano3 9:d4542525b218 102 * Returns a single char from the XBee.
ottaviano3 9:d4542525b218 103 * NOTE: Check the status of the XBee's ATTN pin to see if data is available first.
ottaviano3 7:3cb67634fa4e 104 */
ottaviano3 9:d4542525b218 105 char xbee_getc();
ottaviano3 7:3cb67634fa4e 106
ottaviano3 7:3cb67634fa4e 107 private:
ottaviano3 0:8c8a8244e590 108 // Setup pin input types.
ottaviano3 7:3cb67634fa4e 109
ottaviano3 9:d4542525b218 110 // Reset pin (Pin 5 on XBee)
ottaviano3 0:8c8a8244e590 111 DigitalOut _pin_rst;
ottaviano3 9:d4542525b218 112 // Attention Pin (Pin 19 on XBee
ottaviano3 2:7f4ddf710a44 113 DigitalIn _pin_attn;
ottaviano3 7:3cb67634fa4e 114
ottaviano3 9:d4542525b218 115 // Define SPI connection for the XBee
ottaviano3 0:8c8a8244e590 116 SPI _xbeespi;
ottaviano3 0:8c8a8244e590 117
ottaviano3 0:8c8a8244e590 118 };
ottaviano3 0:8c8a8244e590 119
ottaviano3 7:3cb67634fa4e 120 #endif