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:41:13 2016 +0000
Revision:
13:273adaa03a61
Parent:
12:7b29ddc34cc1
Child:
14:55631bb4aa44
test

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