Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
Diff: DW1000/DW1000.cpp
- Revision:
- 39:bb57aa77b015
- Parent:
- 38:8ef3b8d8b908
- Child:
- 40:5ce51b7e3118
--- a/DW1000/DW1000.cpp Sun Feb 22 11:41:18 2015 +0000 +++ b/DW1000/DW1000.cpp Sun Feb 22 17:40:38 2015 +0000 @@ -12,10 +12,10 @@ // Configuration TODO: make method for that writeRegister8(DW1000_SYS_CFG, 3, 0x20); // enable auto reenabling receiver after error + writeRegister16(DW1000_TX_FCTRL, 1, 0x2800 | 0x0100 | 0x0080); // use 2048 symbols preable (0x2800), 16MHz pulse repetition frequency (0x0100), 110kbps bit rate (0x0080) see p.69 of DW1000 User Manual writeRegister8(DW1000_SYS_CFG, 2, 0x40); // enable special receiving option for 110kbps!! (0x40) see p.64 of DW1000 User Manual [DO NOT enable 1024 byte frames (0x03) becuase it generates disturbance of ranging don't know why...] - writeRegister16(DW1000_TX_FCTRL, 1, 0x2800 | 0x0100 | 0x0080); // use 2048 symbols preable (0x2800), 16MHz pulse repetition frequency (0x0100), 110kbps bit rate (0x0080) see p.69 of DW1000 User Manual - irq.rise(this, &DW1000::ISR); // attach Interrupt handler to rising edge + irq.rise(this, &DW1000::ISR); // attach interrupt handler to rising edge of interrupt pin from DW1000 } void DW1000::setCallbacks(void (*callbackRX)(void), void (*callbackTX)(void)) { @@ -85,22 +85,10 @@ if (length >= 125) length = 125; // check for maximim length a frame can have with 127 Byte frames writeRegister(DW1000_TX_BUFFER, 0, message, length); // fill buffer - #if 0 // switch draft for slower data rate and original working 6.8Mbps - uint8_t backup = readRegister8(DW1000_TX_FCTRL, 1); // put length of frame - length += 2; // including 2 CRC Bytes - //length = ((backup & 0xFC) << 8) | (length & 0x03FF); - length = ((0x80 & 0xFC) << 8) | (length & 0x03FF); // for slower data rate and therefore more range TODO: put in a modular configuration not a fixed value - writeRegister16(DW1000_TX_FCTRL, 0, length); - - backup = readRegister8(DW1000_TX_FCTRL, 2); // change preamble length - uint8_t preamble_reg = (backup & 0xC0) | (0x29 & 0x3F); // for longer preamble to match slower data rate TODO: put in a modular configuration not a fixed value - //writeRegister8(DW1000_TX_FCTRL, 2, preamble_reg); - #else - uint8_t backup = readRegister8(DW1000_TX_FCTRL, 1); // put length of frame - length += 2; // including 2 CRC Bytes - length = ((backup & 0xFC) << 8) | (length & 0x03FF); - writeRegister16(DW1000_TX_FCTRL, 0, length); - #endif + uint8_t backup = readRegister8(DW1000_TX_FCTRL, 1); // put length of frame + length += 2; // including 2 CRC Bytes + length = ((backup & 0xFC) << 8) | (length & 0x03FF); + writeRegister16(DW1000_TX_FCTRL, 0, length); stopTRX(); // stop receiving writeRegister8(DW1000_SYS_CTRL, 0, 0x02); // trigger sending process by setting the TXSTRT bit @@ -216,5 +204,11 @@ } } -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() { // always called to start an SPI transmission + irq.disable_irq(); // disable interrupts from DW1000 during SPI becaus this leads to crashes! TODO: if you have other interrupt handlers attached on the micro controller, they could also interfere. + cs = 0; // set Cable Select pin low to start transmission +} +void DW1000::deselect() { // always called to end an SPI transmission + cs = 1; // set Cable Select pin high to stop transmission + irq.enable_irq(); // reenable the interrupt handler +} \ No newline at end of file