Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
main.cpp@5:111f11c95d27, 2014-11-18 (annotated)
- Committer:
- manumaet
- Date:
- Tue Nov 18 13:35:48 2014 +0000
- Revision:
- 5:111f11c95d27
- Parent:
- 4:6240b9c7a033
- Child:
- 6:d5864a1b9e17
button tester
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 | 0:f50e671ffff7 | 6 | DW1000 dw(D11, D12, D13, D10); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS) |
manumaet | 0:f50e671ffff7 | 7 | |
manumaet | 0:f50e671ffff7 | 8 | /*uint32_t read32Bit(uint8_t reg, uint16_t subaddress) { |
manumaet | 0:f50e671ffff7 | 9 | uint32_t result = 0; |
manumaet | 0:f50e671ffff7 | 10 | |
manumaet | 0:f50e671ffff7 | 11 | }*/ |
manumaet | 0:f50e671ffff7 | 12 | |
manumaet | 5:111f11c95d27 | 13 | //#define SENDER |
manumaet | 5:111f11c95d27 | 14 | |
manumaet | 0:f50e671ffff7 | 15 | int main() { |
manumaet | 4:6240b9c7a033 | 16 | int i=0; |
manumaet | 0:f50e671ffff7 | 17 | pc.printf("DecaWave 0.1\r\nup and running!\r\n"); |
manumaet | 0:f50e671ffff7 | 18 | |
manumaet | 0:f50e671ffff7 | 19 | dw.setEUI(0xFAEDCD01FAEDCD01); |
manumaet | 4:6240b9c7a033 | 20 | pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID()); |
manumaet | 4:6240b9c7a033 | 21 | pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI()); |
manumaet | 4:6240b9c7a033 | 22 | pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage()); |
manumaet | 0:f50e671ffff7 | 23 | |
manumaet | 4:6240b9c7a033 | 24 | // read System Configuration |
manumaet | 4:6240b9c7a033 | 25 | uint32_t conf = 0; |
manumaet | 4:6240b9c7a033 | 26 | dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4); |
manumaet | 4:6240b9c7a033 | 27 | pc.printf("%d System Configuration: %X\r\n", i, conf); |
manumaet | 4:6240b9c7a033 | 28 | |
manumaet | 4:6240b9c7a033 | 29 | wait(5); |
manumaet | 5:111f11c95d27 | 30 | |
manumaet | 5:111f11c95d27 | 31 | #ifndef SENDR |
manumaet | 5:111f11c95d27 | 32 | uint8_t dataframereadyinterrupt = 0x20; // only good frame would be 0x40 |
manumaet | 5:111f11c95d27 | 33 | dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1); |
manumaet | 5:111f11c95d27 | 34 | DigitalIn button(USER_BUTTON); |
manumaet | 5:111f11c95d27 | 35 | while(1) { |
manumaet | 5:111f11c95d27 | 36 | pc.printf("Status: %X\r\n", (int)button); |
manumaet | 5:111f11c95d27 | 37 | wait(0.1); |
manumaet | 5:111f11c95d27 | 38 | } |
manumaet | 5:111f11c95d27 | 39 | #endif |
manumaet | 5:111f11c95d27 | 40 | |
manumaet | 0:f50e671ffff7 | 41 | while(1) { |
manumaet | 0:f50e671ffff7 | 42 | i++; |
manumaet | 0:f50e671ffff7 | 43 | |
manumaet | 5:111f11c95d27 | 44 | # ifdef SENDER // to make one node sender and one receiver |
manumaet | 0:f50e671ffff7 | 45 | // Send something |
manumaet | 4:6240b9c7a033 | 46 | char message[20] = "HELLO WORLD!"; |
manumaet | 4:6240b9c7a033 | 47 | sprintf((char*)message, "HELLO WORLD! %d", i); |
manumaet | 4:6240b9c7a033 | 48 | dw.sendFrame(message, 20); |
manumaet | 0:f50e671ffff7 | 49 | |
manumaet | 4:6240b9c7a033 | 50 | uint8_t messagecheck[20]; |
manumaet | 4:6240b9c7a033 | 51 | dw.readRegister(DW1000_TX_BUFFER, 0, messagecheck, 20); |
manumaet | 4:6240b9c7a033 | 52 | pc.printf("Message in buffer: %s\r\n", messagecheck); |
manumaet | 4:6240b9c7a033 | 53 | wait(2); |
manumaet | 4:6240b9c7a033 | 54 | # else |
manumaet | 0:f50e671ffff7 | 55 | |
manumaet | 0:f50e671ffff7 | 56 | // Receive something |
manumaet | 0:f50e671ffff7 | 57 | uint8_t rxenable = 0x01; // start listening |
manumaet | 0:f50e671ffff7 | 58 | dw.writeRegister(DW1000_SYS_CTRL, 1, &rxenable, 1); |
manumaet | 0:f50e671ffff7 | 59 | |
manumaet | 2:16e45ff70baf | 60 | uint8_t frameready = 0; // check if frame received |
manumaet | 4:6240b9c7a033 | 61 | while (frameready == 0 /*& 0x20) != 0x20*/) { // while no frame ready |
manumaet | 2:16e45ff70baf | 62 | i++; |
manumaet | 4:6240b9c7a033 | 63 | |
manumaet | 5:111f11c95d27 | 64 | pc.printf("%d Waiting for frame... ", i); |
manumaet | 2:16e45ff70baf | 65 | dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1); |
manumaet | 5:111f11c95d27 | 66 | pc.printf("Status: %X ", frameready); |
manumaet | 4:6240b9c7a033 | 67 | uint8_t receive[20] = "NOTHING IN!!"; // get data from buffer |
manumaet | 4:6240b9c7a033 | 68 | dw.readRegister(DW1000_RX_BUFFER, 0, receive, 20); |
manumaet | 4:6240b9c7a033 | 69 | pc.printf("Message would be: %s\r\n", receive); |
manumaet | 4:6240b9c7a033 | 70 | wait(0.3); |
manumaet | 2:16e45ff70baf | 71 | } |
manumaet | 0:f50e671ffff7 | 72 | |
manumaet | 5:111f11c95d27 | 73 | // get data from buffer |
manumaet | 5:111f11c95d27 | 74 | uint8_t receive[20] = "NOTHING IN!!"; |
manumaet | 4:6240b9c7a033 | 75 | dw.readRegister(DW1000_RX_BUFFER, 0, receive, 20); |
manumaet | 4:6240b9c7a033 | 76 | pc.printf("Message received: %s -------------------------\r\n", receive); |
manumaet | 4:6240b9c7a033 | 77 | |
manumaet | 4:6240b9c7a033 | 78 | dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1); |
manumaet | 4:6240b9c7a033 | 79 | pc.printf("Status: %X\r\n", frameready); |
manumaet | 4:6240b9c7a033 | 80 | |
manumaet | 4:6240b9c7a033 | 81 | dw.resetRX(); |
manumaet | 4:6240b9c7a033 | 82 | wait(0.5); |
manumaet | 4:6240b9c7a033 | 83 | continue; |
manumaet | 4:6240b9c7a033 | 84 | |
manumaet | 0:f50e671ffff7 | 85 | # endif |
manumaet | 4:6240b9c7a033 | 86 | |
manumaet | 0:f50e671ffff7 | 87 | } |
manumaet | 0:f50e671ffff7 | 88 | } |