Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
Diff: DW1000/DW1000.cpp
- Revision:
- 12:985aa9843c3c
- Parent:
- 11:c87d37db2c6f
- Child:
- 13:b4d27bf7062a
diff -r c87d37db2c6f -r 985aa9843c3c DW1000/DW1000.cpp --- a/DW1000/DW1000.cpp Sun Nov 23 11:20:46 2014 +0000 +++ b/DW1000/DW1000.cpp Sun Nov 23 14:34:31 2014 +0000 @@ -5,14 +5,11 @@ 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) - uint16_t ldeload[] = {0x0301, 0x8000, 0x0200}; - writeRegister(DW1000_PMSC, 0, (uint8_t*)&ldeload[0], 2); // initialise LDELOAD User Manual p22 - writeRegister(DW1000_OTP_IF, 0x06, (uint8_t*)&ldeload[1], 2); - wait_us(150); - writeRegister(DW1000_PMSC, 0, (uint8_t*)&ldeload[2], 2); + //resetAll(); // we can do a soft reset if we want to (only needed for debugging) + loadLDE(); // important everytime DW1000 initialises/awakes otherwise the LDE algorithm must be turned of or there's receiving malfunction see User Manual LDELOAD on p22 & p158 + writeRegister8(DW1000_SYS_CFG, 3, 0x20); // enable auto reenabling receiver after error irq.rise(this, &DW1000::ISR); // attach Interrupt handler to rising edge - resetRX(); } uint32_t DW1000::getDeviceID() { @@ -32,7 +29,7 @@ } float DW1000::getVoltage() { - uint8_t buffer[7] = {0x80, 0x0A, 0x0F, 0x01, 0x00}; // algorithm form DW1000 User Manual p57 + uint8_t buffer[7] = {0x80, 0x0A, 0x0F, 0x01, 0x00}; // algorithm form User Manual p57 writeRegister(DW1000_RF_CONF, 0x11, buffer, 2); writeRegister(DW1000_RF_CONF, 0x12, &buffer[2], 1); writeRegister(DW1000_TX_CAL, 0x00, &buffer[3], 1); @@ -73,14 +70,33 @@ } void DW1000::ISR() { - callbackRX(); + uint64_t status; // get the entire system status + readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5); + status &= 0xFFFFFFFFFF; // only 40-Bit + if (status & 0x4000) + callbackRX(); + if (status & 0x80) + ;//callbackTX(); // TODO: mask TX done interrupt make TX handler } -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); +void DW1000::loadLDE() { + uint16_t ldeload[] = {0x0301, 0x8000, 0x0200}; // initialise LDE algorithm LDELOAD User Manual p22 + writeRegister(DW1000_PMSC, 0, (uint8_t*)&ldeload[0], 2); // set clock to XTAL so OTP is reliable + writeRegister(DW1000_OTP_IF, 0x06, (uint8_t*)&ldeload[1], 2); // set LDELOAD bit in OTP + wait_us(150); + writeRegister(DW1000_PMSC, 0, (uint8_t*)&ldeload[2], 2); // recover to PLL clock +} + +void DW1000::resetRX() { + writeRegister8(DW1000_PMSC, 3, 0xE0); // set RX reset + writeRegister8(DW1000_PMSC, 3, 0xF0); // clear RX reset +} + +void DW1000::resetAll() { + writeRegister8(DW1000_PMSC, 0, 0x01); // set clock to XTAL + writeRegister8(DW1000_PMSC, 3, 0x00); // set All reset + wait_us(10); // wait for PLL to lock + writeRegister8(DW1000_PMSC, 3, 0xF0); // clear All reset } // SPI Interface ------------------------------------------------------------------------------------ @@ -124,5 +140,5 @@ } } -void DW1000::select() { cs = 0; } //Set CS low to start transmission -void DW1000::deselect() { cs = 1; } //Set CS high to stop transmission \ No newline at end of file +void DW1000::select() { cs = 0; } // set CS low to start transmission +void DW1000::deselect() { cs = 1; } // set CS high to stop transmission \ No newline at end of file