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

Revision:
0:8c8a8244e590
Child:
1:b97d46c5d7ce
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xbee900hp.cpp	Mon Apr 20 21:04:26 2015 +0000
@@ -0,0 +1,103 @@
+#include "xbee900hp.h"
+
+/**
+* Initialize the xBee Module
+*/
+xbee900hp::xbee900hp(PinName pin_mosi,PinName pin_miso,PinName pin_sck,PinName pin_attn, PinName pin_rst, PinName pin_dout)
+    : _pin_rst(pin_rst), _pin_attn(pin_attn), _pin_dout(pin_dout), _xbeespi(pin_mosi,pin_miso,pin_sck)
+{
+    _xbeespi.format(8,0);
+    _xbeespi.frequency(1000000);
+    
+    reset();
+}
+
+/**
+* Destructor
+*/
+xbee900hp::~xbee900hp() {}
+
+
+
+/**
+* Reset xBee to SPI mode
+*/
+void xbee900hp::reset()
+{
+    // Set Xbee to SPI mode
+    _pin_dout = 0;
+    _pin_rst = 0;
+    // Minimum pulse is 1ms
+    wait_ms(1);
+    _pin_rst = 1;
+
+    // Wait for asst pin to go low to indicate SPI mode
+    while(_pin_attn != 0) { }
+
+    _pin_dout = 1;
+
+    // wait for module to come back online
+    wait_ms(500);
+}
+
+/**
+* Send packet out on RF
+*/
+void xbee900hp::sendPacket(char* data, unsigned int length)
+{
+    // checksum
+    unsigned int checksum;
+    unsigned int checksumsub = 0;
+    
+    // start char
+    _xbeespi.write(0x7E);
+    // lenght
+    _xbeespi.write(0x00);
+    
+    unsigned int totallength = 14 + length - 1;
+    _xbeespi.write(totallength);
+
+    // frame delimter
+    _xbeespi.write(0x10);
+    checksumsub += 0x10;
+    // id for later reference 0 = no id
+    _xbeespi.write(0x00);
+
+    // destination address
+    _xbeespi.write(0x00);
+    _xbeespi.write(0x00);
+    _xbeespi.write(0x00);
+    _xbeespi.write(0x00);
+    _xbeespi.write(0x00);
+    _xbeespi.write(0x00);
+    _xbeespi.write(0xFF);
+    checksumsub += 0xFF;
+    _xbeespi.write(0xFF);
+    checksumsub += 0xFF;
+
+    // reserved field, dont change
+    _xbeespi.write(0xFF);
+    checksumsub += 0xFF;
+    _xbeespi.write(0xFE);
+    checksumsub += 0xFE;
+
+    //bcast radius
+    _xbeespi.write(0x00);
+
+    //transmit options 0x00 to disable ACK
+    _xbeespi.write(0x00);
+
+    // dat data
+    for (int i = 0; i < (length - 1); i++) {
+        _xbeespi.write(*data);
+        checksumsub += (*(data++));
+    }
+    
+
+    // Calculate checksum
+    checksumsub = checksumsub & 0xFF;
+    checksum = 0xFF - checksumsub;
+
+    // finally write checksum
+    _xbeespi.write(checksum);
+}
\ No newline at end of file