DW1000 UWB driver based on work of Matthias Grob & Manuel Stalder - ETH Zürich - 2015
Revision 11:b4ea3e12f15e, committed 2016-04-21
- Comitter:
- AndyA
- Date:
- Thu Apr 21 16:31:15 2016 +0000
- Parent:
- 9:326bf149c8bc
- Commit message:
- removed LEDs;
Changed in this revision
DW1000.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/DW1000.cpp Wed Apr 20 11:03:41 2016 +0000 +++ b/DW1000.cpp Thu Apr 21 16:31:15 2016 +0000 @@ -9,7 +9,7 @@ DW1000Setup newSetup(DW1000Setup::tunedDefault); systemConfig.applyConfig(&newSetup); - deselect(); // Chip must be deselected first + cs.write(1); // 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(SPIRATE_PLL); // with a 1MHz clock rate (worked up to 49MHz in our Test) @@ -387,7 +387,7 @@ // transmit power: 0 to 33.5 dB gain in steps of 0.5. Inputs are in 10ths of a dB (0 to 335) void DW1000::setTxPower(float normalPowerdB, float boost500, float boost250, float boost125) { - + if(normalPowerdB > 33.5) normalPowerdB = 33.5; @@ -417,7 +417,7 @@ powerReg |= powerToRegValue(boost250) << 16; powerReg |= powerToRegValue(boost125) << 24; writeRegister32(DW1000_TX_POWER,0,powerReg); - + systemConfig.setSmartTxPower(normalPowerdB,boost500,boost250,boost125); // update the systemConfig } @@ -741,23 +741,13 @@ void DW1000::sendFrame(uint8_t* message, uint16_t length) { - //if (length >= 1021) length = 1021; // check for maximim length a frame can have with 1024 Byte frames [not used, see constructor] if (length >= 125) length = 125; // check for maximim length a frame can have with 127 Byte frames - uint8_t len_7bit = length; - writeRegister(DW1000_TX_BUFFER, 0, message, len_7bit); // fill buffer + writeRegister(DW1000_TX_BUFFER, 0, message, length); // fill buffer - /* support for frames over 127 bytes - 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); - */ - len_7bit += 2; // including 2 CRC Bytes - writeRegister8(DW1000_TX_FCTRL, 0, len_7bit); + writeRegister8(DW1000_TX_FCTRL, 0, length+2); stopTRX(); // stop receiving writeRegister8(DW1000_SYS_CTRL, 0, 0x02 | 0x80); // trigger sending process by setting the TXSTRT bit -// startRX(); // enable receiver again } void DW1000::setupSyncedFrame(uint8_t* message, uint16_t length) @@ -991,24 +981,29 @@ void DW1000::readRegister(uint8_t reg, uint16_t subaddress, uint8_t *buffer, int length) { + __disable_irq(); + cs.write(0); setupTransaction(reg, subaddress, false); for(int i=0; i<length; i++) // get data buffer[i] = spi.write(0x00); - deselect(); + cs.write(1); + __enable_irq(); } void DW1000::writeRegister(uint8_t reg, uint16_t subaddress, uint8_t *buffer, int length) { + __disable_irq(); + cs.write(0); setupTransaction(reg, subaddress, true); for(int i=0; i<length; i++) // put data spi.write(buffer[i]); - deselect(); + cs.write(1); + __enable_irq(); } void DW1000::setupTransaction(uint8_t reg, uint16_t subaddress, bool write) { reg |= (write * DW1000_WRITE_FLAG); // set read/write flag - select(); if (subaddress > 0) { // there's a subadress, we need to set flag and send second header byte spi.write(reg | DW1000_SUBADDRESS_FLAG); if (subaddress > 0x7F) { // sub address too long, we need to set flag and send third header byte @@ -1020,16 +1015,4 @@ } else { spi.write(reg); // say which register address we want to access } -} - -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