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
xbee900hp.cpp
- Committer:
- ottaviano3
- Date:
- 2015-04-22
- Revision:
- 1:b97d46c5d7ce
- Parent:
- 0:8c8a8244e590
- Child:
- 2:7f4ddf710a44
File content as of revision 1:b97d46c5d7ce:
#include "xbee900hp.h" /** * Initialize the xBee Module */ 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); _pin_attn.fall(this, &xbee900hp::readDataISR); } /** * Destructor */ xbee900hp::~xbee900hp() {} /** * Read Data ISR */ void xbee900hp::readDataISR() { // Nothing Yet } /** * Reset xBee to SPI mode */ void xbee900hp::reset() { // Set Xbee to SPI mode _pin_rst = 0; // Minimum pulse is 1ms wait_ms(1); _pin_rst = 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); } 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); }