Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
main.cpp@11:c87d37db2c6f, 2014-11-23 (annotated)
- Committer:
- manumaet
- Date:
- Sun Nov 23 11:20:46 2014 +0000
- Revision:
- 11:c87d37db2c6f
- Parent:
- 10:d077bb12d259
- Child:
- 12:985aa9843c3c
LDE fixed, receiver reset no more needed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
manumaet | 0:f50e671ffff7 | 1 | #include "mbed.h" |
manumaet | 0:f50e671ffff7 | 2 | #include "PC.h" // Serial Port via USB for debugging with Terminal |
manumaet | 0:f50e671ffff7 | 3 | #include "DW1000.h" |
manumaet | 0:f50e671ffff7 | 4 | |
manumaet | 0:f50e671ffff7 | 5 | PC pc(USBTX, USBRX, 921600); // USB UART Terminal |
manumaet | 7:e634eeafc4d2 | 6 | DW1000 dw(D11, D12, D13, D10, D14); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ) |
manumaet | 0:f50e671ffff7 | 7 | |
manumaet | 11:c87d37db2c6f | 8 | |
manumaet | 11:c87d37db2c6f | 9 | uint64_t timestamp_old = 0; |
manumaet | 11:c87d37db2c6f | 10 | //#define SENDER |
manumaet | 5:111f11c95d27 | 11 | |
manumaet | 6:d5864a1b9e17 | 12 | void Interrupthandler() { |
manumaet | 10:d077bb12d259 | 13 | /*uint8_t frameready = 0; |
manumaet | 7:e634eeafc4d2 | 14 | dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1); |
manumaet | 10:d077bb12d259 | 15 | pc.printf("Interrupt status: %X\r\n", frameready);*/ |
manumaet | 10:d077bb12d259 | 16 | |
manumaet | 10:d077bb12d259 | 17 | uint16_t framelength = 0; // get framelength |
manumaet | 10:d077bb12d259 | 18 | dw.readRegister(DW1000_RX_FINFO, 0, (uint8_t*)&framelength, 2); |
manumaet | 10:d077bb12d259 | 19 | framelength &= 0x03FF; |
manumaet | 10:d077bb12d259 | 20 | framelength -= 2; |
manumaet | 10:d077bb12d259 | 21 | |
manumaet | 10:d077bb12d259 | 22 | char* receive = dw.receiveString(); |
manumaet | 11:c87d37db2c6f | 23 | pc.printf("Received: %s %d ", receive, framelength); |
manumaet | 10:d077bb12d259 | 24 | delete[] receive; |
manumaet | 10:d077bb12d259 | 25 | |
manumaet | 11:c87d37db2c6f | 26 | uint64_t status; |
manumaet | 11:c87d37db2c6f | 27 | dw.readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5); |
manumaet | 11:c87d37db2c6f | 28 | status &= 0xFFFFFFFFFF; // only 40-Bit |
manumaet | 11:c87d37db2c6f | 29 | pc.printf("Status: %010llX ", status); |
manumaet | 11:c87d37db2c6f | 30 | |
manumaet | 11:c87d37db2c6f | 31 | uint64_t timestamp; |
manumaet | 11:c87d37db2c6f | 32 | dw.readRegister(DW1000_RX_TIME, 0, (uint8_t*)×tamp, 5); |
manumaet | 11:c87d37db2c6f | 33 | timestamp &= 0xFFFFFFFFFF; // only 40-Bit |
manumaet | 11:c87d37db2c6f | 34 | uint64_t difference = timestamp - timestamp_old; |
manumaet | 11:c87d37db2c6f | 35 | timestamp_old = timestamp; |
manumaet | 11:c87d37db2c6f | 36 | pc.printf("Timestamp: %lld\r\n", difference); |
manumaet | 11:c87d37db2c6f | 37 | |
manumaet | 11:c87d37db2c6f | 38 | /*uint8_t xtalt; // for clock tuning |
manumaet | 11:c87d37db2c6f | 39 | dw.readRegister(DW1000_FS_CTRL, 0x0E, (uint8_t*)&xtalt, 1); |
manumaet | 11:c87d37db2c6f | 40 | pc.printf("XTALT: %X\r\n", xtalt);*/ |
manumaet | 11:c87d37db2c6f | 41 | |
manumaet | 11:c87d37db2c6f | 42 | //dw.resetRX(); // TODO DONE: reset was crucial because otherwise only 1 frame is received correct, cause: LDE crashing because you have to manually initialize |
manumaet | 8:7a9c61242e2f | 43 | dw.receiveFrame(); |
manumaet | 6:d5864a1b9e17 | 44 | } |
manumaet | 6:d5864a1b9e17 | 45 | |
manumaet | 0:f50e671ffff7 | 46 | int main() { |
manumaet | 4:6240b9c7a033 | 47 | int i=0; |
manumaet | 10:d077bb12d259 | 48 | char message[1024] = ""; |
manumaet | 0:f50e671ffff7 | 49 | pc.printf("DecaWave 0.1\r\nup and running!\r\n"); |
manumaet | 0:f50e671ffff7 | 50 | |
manumaet | 0:f50e671ffff7 | 51 | dw.setEUI(0xFAEDCD01FAEDCD01); |
manumaet | 4:6240b9c7a033 | 52 | pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID()); |
manumaet | 4:6240b9c7a033 | 53 | pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI()); |
manumaet | 4:6240b9c7a033 | 54 | pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage()); |
manumaet | 0:f50e671ffff7 | 55 | |
manumaet | 4:6240b9c7a033 | 56 | // read System Configuration |
manumaet | 4:6240b9c7a033 | 57 | uint32_t conf = 0; |
manumaet | 4:6240b9c7a033 | 58 | dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4); |
manumaet | 4:6240b9c7a033 | 59 | pc.printf("%d System Configuration: %X\r\n", i, conf); |
manumaet | 4:6240b9c7a033 | 60 | |
manumaet | 7:e634eeafc4d2 | 61 | wait(1); |
manumaet | 5:111f11c95d27 | 62 | |
manumaet | 8:7a9c61242e2f | 63 | dw.callbackRX = &Interrupthandler; |
manumaet | 9:c8839de428ac | 64 | #ifndef SENDER |
manumaet | 10:d077bb12d259 | 65 | uint8_t dataframereadyinterrupt = 0x40; // only good frame 0x40 all frames 0x20 |
manumaet | 5:111f11c95d27 | 66 | dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1); |
manumaet | 7:e634eeafc4d2 | 67 | |
manumaet | 7:e634eeafc4d2 | 68 | // Receive something |
manumaet | 8:7a9c61242e2f | 69 | dw.receiveFrame(); |
manumaet | 5:111f11c95d27 | 70 | #endif |
manumaet | 5:111f11c95d27 | 71 | |
manumaet | 0:f50e671ffff7 | 72 | while(1) { |
manumaet | 0:f50e671ffff7 | 73 | i++; |
manumaet | 5:111f11c95d27 | 74 | # ifdef SENDER // to make one node sender and one receiver |
manumaet | 11:c87d37db2c6f | 75 | //message[i-1] = 'O'; |
manumaet | 11:c87d37db2c6f | 76 | //message[i] = '\0'; |
manumaet | 11:c87d37db2c6f | 77 | sprintf((char*)message, "HELLO WORLD! %d", i); |
manumaet | 11:c87d37db2c6f | 78 | //if (i < 200) |
manumaet | 11:c87d37db2c6f | 79 | pc.printf("%d Message: \"%s\" %d\r\n", i, message, strlen(message)+1); |
manumaet | 11:c87d37db2c6f | 80 | //else |
manumaet | 11:c87d37db2c6f | 81 | //pc.printf("%d Message: %d\r\n", i, strlen(message)+1); |
manumaet | 10:d077bb12d259 | 82 | dw.sendString(message); |
manumaet | 0:f50e671ffff7 | 83 | |
manumaet | 10:d077bb12d259 | 84 | char messagecheck[1024]; |
manumaet | 10:d077bb12d259 | 85 | dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1); |
manumaet | 11:c87d37db2c6f | 86 | //if (i < 200) |
manumaet | 10:d077bb12d259 | 87 | pc.printf("%d Buffer: \"%s\" %d\r\n", i, messagecheck, strlen(messagecheck)+1); |
manumaet | 11:c87d37db2c6f | 88 | //else |
manumaet | 11:c87d37db2c6f | 89 | //pc.printf("%d Buffer: %d\r\n", i, strlen(messagecheck)+1); |
manumaet | 9:c8839de428ac | 90 | /*for(int i=0; i<10; i++) { // to control Voltage |
manumaet | 9:c8839de428ac | 91 | pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage()); |
manumaet | 9:c8839de428ac | 92 | wait(0.2); |
manumaet | 9:c8839de428ac | 93 | }*/ |
manumaet | 11:c87d37db2c6f | 94 | //if (i<27) |
manumaet | 11:c87d37db2c6f | 95 | wait(1); |
manumaet | 11:c87d37db2c6f | 96 | //else |
manumaet | 11:c87d37db2c6f | 97 | //wait(3); |
manumaet | 8:7a9c61242e2f | 98 | #else |
manumaet | 11:c87d37db2c6f | 99 | pc.printf("%d Waiting... ", i); |
manumaet | 11:c87d37db2c6f | 100 | |
manumaet | 11:c87d37db2c6f | 101 | uint64_t status; |
manumaet | 11:c87d37db2c6f | 102 | dw.readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5); |
manumaet | 11:c87d37db2c6f | 103 | status &= 0xFFFFFFFFFF; // only 40-Bit |
manumaet | 11:c87d37db2c6f | 104 | pc.printf("Status: %010llX\r\n", status); |
manumaet | 11:c87d37db2c6f | 105 | |
manumaet | 10:d077bb12d259 | 106 | wait(1); |
manumaet | 0:f50e671ffff7 | 107 | # endif |
manumaet | 4:6240b9c7a033 | 108 | |
manumaet | 0:f50e671ffff7 | 109 | } |
manumaet | 0:f50e671ffff7 | 110 | } |