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
Diff: xbee900hp.cpp
- Revision:
- 1:b97d46c5d7ce
- Parent:
- 0:8c8a8244e590
- Child:
- 2:7f4ddf710a44
diff -r 8c8a8244e590 -r b97d46c5d7ce xbee900hp.cpp --- a/xbee900hp.cpp Mon Apr 20 21:04:26 2015 +0000 +++ b/xbee900hp.cpp Wed Apr 22 15:31:18 2015 +0000 @@ -3,13 +3,13 @@ /** * 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) +xbee900hp::xbee900hp(PinName pin_mosi,PinName pin_miso,PinName pin_sck,PinName pin_attn, PinName pin_rst) + : _pin_rst(pin_rst), _pin_attn(pin_attn), _xbeespi(pin_mosi,pin_miso,pin_sck) { _xbeespi.format(8,0); _xbeespi.frequency(1000000); - - reset(); + + _pin_attn.fall(this, &xbee900hp::readDataISR); } /** @@ -17,7 +17,12 @@ */ xbee900hp::~xbee900hp() {} - +/** +* Read Data ISR +*/ +void xbee900hp::readDataISR() { + // Nothing Yet +} /** * Reset xBee to SPI mode @@ -25,17 +30,10 @@ 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); } @@ -100,4 +98,38 @@ // finally write checksum _xbeespi.write(checksum); +} + +void xbee900hp::writeSetting(char command[2], unsigned int value) { + // checksum Variables + unsigned int checksum = 0; + unsigned int checksumsub = 0; + + // Start config, send frames for SPI pins enable + _xbeespi.write(0x7E); + _xbeespi.write(0x00); + _xbeespi.write(0x05); + + // Frame type (config) + _xbeespi.write(0x08); + checksumsub += 0x08; + _xbeespi.write(0x00); + + + // AT Command + for (int i = 0; i < 2; i++) { + _xbeespi.write(*command); + checksumsub += (*(command++)); + } + + // Value to set + _xbeespi.write(value); + checksumsub += value; + + // Calculate checksum + checksumsub = checksumsub & 0xFF; + checksum = 0xFF - checksumsub; + + // finally write checksum + _xbeespi.write(checksum); } \ No newline at end of file