Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
main.cpp@1:1311e7af0a5c, 2014-11-16 (annotated)
- Committer:
- manumaet
- Date:
- Sun Nov 16 10:04:00 2014 +0000
- Revision:
- 1:1311e7af0a5c
- Parent:
- 0:f50e671ffff7
- Child:
- 2:16e45ff70baf
no more work, before revert
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 | 1:1311e7af0a5c | 30 | # if 0 // 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 | 1:1311e7af0a5c | 33 | //sprintf((char*)message, "%d World!!", 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 | 0:f50e671ffff7 | 39 | uint16_t framelength = 13; // put length of frame |
manumaet | 0:f50e671ffff7 | 40 | dw.writeRegister(DW1000_TX_FCTRL, 0, (uint8_t*)&framelength, 1); |
manumaet | 0:f50e671ffff7 | 41 | |
manumaet | 1:1311e7af0a5c | 42 | if ((i % 2) == 0) { |
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 | 0:f50e671ffff7 | 51 | //uint8_t frameready = 0; // check if frame received |
manumaet | 0:f50e671ffff7 | 52 | //while (frameready != 0x20) { |
manumaet | 0:f50e671ffff7 | 53 | // i++; |
manumaet | 0:f50e671ffff7 | 54 | // pc.printf("%d Waiting for frame... \r\n", i); |
manumaet | 0:f50e671ffff7 | 55 | // dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 13); |
manumaet | 0:f50e671ffff7 | 56 | // wait(0.5); |
manumaet | 0:f50e671ffff7 | 57 | //} |
manumaet | 0:f50e671ffff7 | 58 | |
manumaet | 0:f50e671ffff7 | 59 | uint8_t receive[13] = "NOTHING IN!!"; // get data from buffer |
manumaet | 0:f50e671ffff7 | 60 | dw.readRegister(DW1000_RX_BUFFER, 0, receive, 13); |
manumaet | 0:f50e671ffff7 | 61 | pc.printf("Message received: %s\r\n", receive); |
manumaet | 0:f50e671ffff7 | 62 | # endif |
manumaet | 0:f50e671ffff7 | 63 | |
manumaet | 0:f50e671ffff7 | 64 | wait(0.5); |
manumaet | 0:f50e671ffff7 | 65 | } |
manumaet | 0:f50e671ffff7 | 66 | } |