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:43:10 2016 +0000
Revision:
14:55631bb4aa44
Parent:
13:273adaa03a61
Child:
15:3bb82129f3a8
edt

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