Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DecaWave by
Diff: DW1000/DW1000.cpp
- Revision:
- 7:e634eeafc4d2
- Parent:
- 4:6240b9c7a033
- Child:
- 8:7a9c61242e2f
--- a/DW1000/DW1000.cpp Tue Nov 18 13:39:50 2014 +0000 +++ b/DW1000/DW1000.cpp Tue Nov 18 14:06:48 2014 +0000 @@ -1,10 +1,12 @@ #include "DW1000.h" -DW1000::DW1000(PinName MOSI, PinName MISO, PinName SCLK, PinName CS) : spi(MOSI, MISO, SCLK), cs(CS) +DW1000::DW1000(PinName MOSI, PinName MISO, PinName SCLK, PinName CS, PinName IRQ) : spi(MOSI, MISO, SCLK), cs(CS), irq(IRQ) { deselect(); // Chip must be deselected first spi.format(8,0); // Setup the spi for standard 8 bit data and SPI-Mode 0 (GPIO5, GPIO6 open circuit or ground on DW1000) spi.frequency(1000000); // with a 1MHz clock rate (worked up to 49MHz in our Test) + + irq.rise(this, &DW1000::ISR); } uint32_t DW1000::getDeviceID() { @@ -23,23 +25,6 @@ writeRegister(DW1000_EUI, 0, (uint8_t*)&EUI, 8); } -void DW1000::sendFrame(char* message, int length) { - writeRegister(DW1000_TX_BUFFER, 0, (uint8_t*)message, length); // fill buffer - - uint16_t framelength = length+2; // put length of frame including 2 CRC Bytes - writeRegister(DW1000_TX_FCTRL, 0, (uint8_t*)&framelength, 1); - - uint8_t txstart = 0x02; // trigger sending process - writeRegister(DW1000_SYS_CTRL, 0, &txstart, 1); -} - -void DW1000::resetRX() { - uint8_t resetrx = 0xE0; //set rx reset - writeRegister(DW1000_PMSC, 3, &resetrx, 1); - resetrx = 0xf0; //clear RX reset - writeRegister(DW1000_PMSC, 3, &resetrx, 1); -} - float DW1000::getVoltage() { uint8_t buffer[7] = {0x80, 0x0A, 0x0F, 0x01, 0x00}; // algorithm form DW1000 User Manual p57 writeRegister(DW1000_RF_CONF, 0x11, buffer, 2); @@ -52,6 +37,26 @@ return Voltage; } +void DW1000::sendFrame(char* message, int length) { + writeRegister(DW1000_TX_BUFFER, 0, (uint8_t*)message, length); // fill buffer + + uint16_t framelength = length+2; // put length of frame including 2 CRC Bytes + writeRegister(DW1000_TX_FCTRL, 0, (uint8_t*)&framelength, 1); + + uint8_t txstart = 0x02; // trigger sending process + writeRegister(DW1000_SYS_CTRL, 0, &txstart, 1); +} + +void DW1000::ISR() { + callbackRX(); +} + +void DW1000::resetRX() { + uint8_t resetrx = 0xE0; //set rx reset + writeRegister(DW1000_PMSC, 3, &resetrx, 1); + resetrx = 0xf0; //clear RX reset + writeRegister(DW1000_PMSC, 3, &resetrx, 1); +} // SPI Interface ------------------------------------------------------------------------------------ void DW1000::readRegister(uint8_t reg, uint16_t subaddress, uint8_t *buffer, int length)