Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
main.cpp@2:16e45ff70baf, 2014-11-17 (annotated)
- Committer:
- manumaet
- Date:
- Mon Nov 17 13:11:57 2014 +0000
- Revision:
- 2:16e45ff70baf
- Parent:
- 1:1311e7af0a5c
- Child:
- 3:69587fadfa87
before changing entire send/receive structure
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 | 0:f50e671ffff7 | 13 | int main() { |
manumaet | 0:f50e671ffff7 | 14 | pc.printf("DecaWave 0.1\r\nup and running!\r\n"); |
manumaet | 0:f50e671ffff7 | 15 | |
manumaet | 0:f50e671ffff7 | 16 | dw.setEUI(0xFAEDCD01FAEDCD01); |
manumaet | 0:f50e671ffff7 | 17 | |
manumaet | 0:f50e671ffff7 | 18 | int i=0; |
manumaet | 0:f50e671ffff7 | 19 | while(1) { |
manumaet | 0:f50e671ffff7 | 20 | i++; |
manumaet | 0:f50e671ffff7 | 21 | pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID()); |
manumaet | 0:f50e671ffff7 | 22 | pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI()); |
manumaet | 0:f50e671ffff7 | 23 | pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage()); |
manumaet | 0:f50e671ffff7 | 24 | |
manumaet | 0:f50e671ffff7 | 25 | // read System Configuration |
manumaet | 0:f50e671ffff7 | 26 | uint32_t conf = 0; |
manumaet | 0:f50e671ffff7 | 27 | dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4); |
manumaet | 0:f50e671ffff7 | 28 | pc.printf("%d System Configuration: %X\r\n", i, conf); |
manumaet | 0:f50e671ffff7 | 29 | |
manumaet | 2:16e45ff70baf | 30 | # if 1 // to make one node sender and one receiver |
manumaet | 0:f50e671ffff7 | 31 | // Send something |
manumaet | 0:f50e671ffff7 | 32 | uint8_t message[13] = "HELLO WORLD!"; // fill buffer |
manumaet | 2:16e45ff70baf | 33 | sprintf((char*)message, "Hello: %d!", i); |
manumaet | 0:f50e671ffff7 | 34 | dw.writeRegister(DW1000_TX_BUFFER, 0, message, 13); |
manumaet | 0:f50e671ffff7 | 35 | uint8_t messagecheck[13]; |
manumaet | 0:f50e671ffff7 | 36 | dw.readRegister(DW1000_TX_BUFFER, 0, messagecheck, 13); |
manumaet | 0:f50e671ffff7 | 37 | pc.printf("Message in buffer: %s\r\n", messagecheck); |
manumaet | 0:f50e671ffff7 | 38 | |
manumaet | 2:16e45ff70baf | 39 | uint16_t framelength = 13+2; // put length of frame |
manumaet | 0:f50e671ffff7 | 40 | dw.writeRegister(DW1000_TX_FCTRL, 0, (uint8_t*)&framelength, 1); |
manumaet | 0:f50e671ffff7 | 41 | |
manumaet | 2:16e45ff70baf | 42 | if (i == 4) { |
manumaet | 0:f50e671ffff7 | 43 | uint8_t txstart = 0x02; // trigger sending process |
manumaet | 0:f50e671ffff7 | 44 | dw.writeRegister(DW1000_SYS_CTRL, 0, &txstart, 1); |
manumaet | 0:f50e671ffff7 | 45 | } |
manumaet | 0:f50e671ffff7 | 46 | # else |
manumaet | 0:f50e671ffff7 | 47 | // Receive something |
manumaet | 0:f50e671ffff7 | 48 | uint8_t rxenable = 0x01; // start listening |
manumaet | 0:f50e671ffff7 | 49 | dw.writeRegister(DW1000_SYS_CTRL, 1, &rxenable, 1); |
manumaet | 0:f50e671ffff7 | 50 | |
manumaet | 2:16e45ff70baf | 51 | uint8_t frameready = 0; // check if frame received |
manumaet | 2:16e45ff70baf | 52 | while ((frameready & 0x20) != 0x20) { // while no frame ready |
manumaet | 2:16e45ff70baf | 53 | i++; |
manumaet | 2:16e45ff70baf | 54 | pc.printf("%d Waiting for frame... \r\n", i); |
manumaet | 2:16e45ff70baf | 55 | dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1); |
manumaet | 2:16e45ff70baf | 56 | pc.printf("%X\r\n", frameready); |
manumaet | 2:16e45ff70baf | 57 | uint8_t receive[13] = "NOTHING IN!!"; // get data from buffer |
manumaet | 2:16e45ff70baf | 58 | dw.readRegister(DW1000_RX_BUFFER, 0, receive, 13); |
manumaet | 2:16e45ff70baf | 59 | pc.printf("Message would be: %s\r\n", receive); |
manumaet | 2:16e45ff70baf | 60 | wait(0.5); |
manumaet | 2:16e45ff70baf | 61 | } |
manumaet | 0:f50e671ffff7 | 62 | |
manumaet | 0:f50e671ffff7 | 63 | uint8_t receive[13] = "NOTHING IN!!"; // get data from buffer |
manumaet | 0:f50e671ffff7 | 64 | dw.readRegister(DW1000_RX_BUFFER, 0, receive, 13); |
manumaet | 0:f50e671ffff7 | 65 | pc.printf("Message received: %s\r\n", receive); |
manumaet | 0:f50e671ffff7 | 66 | # endif |
manumaet | 0:f50e671ffff7 | 67 | |
manumaet | 0:f50e671ffff7 | 68 | wait(0.5); |
manumaet | 0:f50e671ffff7 | 69 | } |
manumaet | 0:f50e671ffff7 | 70 | } |