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