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:40:55 2016 +0000
Revision:
9:d4542525b218
Parent:
7:3cb67634fa4e
Child:
10:f559e7af4fe6
Updated comments and API to be more helpful.

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