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 04:43:40 2016 +0000
Revision:
11:9013b28438cb
Parent:
10:f559e7af4fe6
Child:
12:7b29ddc34cc1
edit

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 9:d4542525b218 16 * pin_mosi -> mbed SPI MOSI pin
ottaviano3 9:d4542525b218 17 * pin_miso -> mbed SPI MISO pin
ottaviano3 9:d4542525b218 18 * pin_sck -> mbed SPI SCK pin
ottaviano3 9:d4542525b218 19 * pin_attn -> Signals that some message from the XBee module is available
ottaviano3 9:d4542525b218 20 * pin_rst -> Resets the XBee module
ottaviano3 9:d4542525b218 21 * 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 9:d4542525b218 38 * data -> char array of the message to be sent wirelessly.
ottaviano3 9:d4542525b218 39 * length -> then length of the char array excluding any null termination.
ottaviano3 9:d4542525b218 40 * 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 11:9013b28438cb 55 *
ottaviano3 11:9013b28438cb 56 * 0 = +7 dBm, (5 mW)
ottaviano3 11:9013b28438cb 57 *
ottaviano3 11:9013b28438cb 58 * 1 = +15 dBm, (32 mW)
ottaviano3 11:9013b28438cb 59 *
ottaviano3 11:9013b28438cb 60 * 2 = +18 dBm, (63 mW)
ottaviano3 11:9013b28438cb 61 *
ottaviano3 11:9013b28438cb 62 * 3 = +21 dBm, (125 mW)
ottaviano3 11:9013b28438cb 63 *
ottaviano3 11:9013b28438cb 64 * 4 = +24 dBm, (250 mW)
ottaviano3 11:9013b28438cb 65 *
ottaviano3 9:d4542525b218 66 *
ottaviano3 9:d4542525b218 67 * Returns 0 upon successful completion, else returns 1.
ottaviano3 7:3cb67634fa4e 68 */
ottaviano3 7:3cb67634fa4e 69 int setPower(int value);
ottaviano3 7:3cb67634fa4e 70
ottaviano3 2:7f4ddf710a44 71 /**
ottaviano3 9:d4542525b218 72 * Get serial number of XBee module
ottaviano3 9:d4542525b218 73 *
ottaviano3 9:d4542525b218 74 * Returns the XBee's unique 64-bit (0-0xFFFFFFFF) Serial/MAC address, else returns 1.
ottaviano3 3:3c3707b0f5cd 75 */
ottaviano3 7:3cb67634fa4e 76 unsigned long long getSerial();
ottaviano3 7:3cb67634fa4e 77
ottaviano3 3:3c3707b0f5cd 78 /**
ottaviano3 2:7f4ddf710a44 79 * Wait for and read incoming data packet
ottaviano3 9:d4542525b218 80 *
ottaviano3 9:d4542525b218 81 * Returns the 64-bit (0-0xFFFFFFFF) Serial/MAC address of the sending XBee if successful, or 0 if it failed.
ottaviano3 2:7f4ddf710a44 82 */
ottaviano3 7:3cb67634fa4e 83 unsigned long long readPacket(char* data);
ottaviano3 7:3cb67634fa4e 84
ottaviano3 2:7f4ddf710a44 85 /**
ottaviano3 6:3873db4a0164 86 * Clear output buffer
ottaviano3 6:3873db4a0164 87 */
ottaviano3 6:3873db4a0164 88 void clearBuff();
ottaviano3 7:3cb67634fa4e 89
ottaviano3 6:3873db4a0164 90 /**
ottaviano3 2:7f4ddf710a44 91 * Check ATTN signal
ottaviano3 9:d4542525b218 92 *
ottaviano3 9:d4542525b218 93 * Returns the state of the ATTN pin.
ottaviano3 9:d4542525b218 94 * NOTE: This pin is inverse logic. (i.e. 0 = message waiting, 1 = no messages availiable)
ottaviano3 2:7f4ddf710a44 95 */
ottaviano3 2:7f4ddf710a44 96 int attn();
ottaviano3 7:3cb67634fa4e 97
ottaviano3 7:3cb67634fa4e 98 /**
ottaviano3 7:3cb67634fa4e 99 * Read raw data in from module
ottaviano3 9:d4542525b218 100 *
ottaviano3 9:d4542525b218 101 * Returns a single char from the XBee.
ottaviano3 9:d4542525b218 102 * NOTE: Check the status of the XBee's ATTN pin to see if data is available first.
ottaviano3 7:3cb67634fa4e 103 */
ottaviano3 9:d4542525b218 104 char xbee_getc();
ottaviano3 7:3cb67634fa4e 105
ottaviano3 7:3cb67634fa4e 106 private:
ottaviano3 0:8c8a8244e590 107 // Setup pin input types.
ottaviano3 7:3cb67634fa4e 108
ottaviano3 9:d4542525b218 109 // Reset pin (Pin 5 on XBee)
ottaviano3 0:8c8a8244e590 110 DigitalOut _pin_rst;
ottaviano3 9:d4542525b218 111 // Attention Pin (Pin 19 on XBee
ottaviano3 2:7f4ddf710a44 112 DigitalIn _pin_attn;
ottaviano3 7:3cb67634fa4e 113
ottaviano3 9:d4542525b218 114 // Define SPI connection for the XBee
ottaviano3 0:8c8a8244e590 115 SPI _xbeespi;
ottaviano3 0:8c8a8244e590 116
ottaviano3 0:8c8a8244e590 117 };
ottaviano3 0:8c8a8244e590 118
ottaviano3 7:3cb67634fa4e 119 #endif