Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Committer:
manumaet
Date:
Mon Nov 17 16:00:28 2014 +0000
Revision:
3:69587fadfa87
Parent:
2:16e45ff70baf
Child:
4:6240b9c7a033
always getting CRC Error and HHHHHH

Who changed what in which revision?

UserRevisionLine numberNew 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 3:69587fadfa87 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 3:69587fadfa87 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 3:69587fadfa87 37 pc.printf("Message in buffer: %s\r\nHex: 0x", messagecheck);
manumaet 3:69587fadfa87 38 for (int i = 0;i < 13; i++)
manumaet 3:69587fadfa87 39 pc.printf("%X", messagecheck[i]);
manumaet 3:69587fadfa87 40 pc.printf("\r\n", messagecheck[i]);
manumaet 0:f50e671ffff7 41
manumaet 3:69587fadfa87 42 uint16_t framelength = 13; // put length of frame
manumaet 0:f50e671ffff7 43 dw.writeRegister(DW1000_TX_FCTRL, 0, (uint8_t*)&framelength, 1);
manumaet 0:f50e671ffff7 44
manumaet 3:69587fadfa87 45 //if (i==4) {
manumaet 0:f50e671ffff7 46 uint8_t txstart = 0x02; // trigger sending process
manumaet 0:f50e671ffff7 47 dw.writeRegister(DW1000_SYS_CTRL, 0, &txstart, 1);
manumaet 3:69587fadfa87 48 pc.printf("Sending...\r\n");
manumaet 3:69587fadfa87 49 //}
manumaet 0:f50e671ffff7 50 # else
manumaet 0:f50e671ffff7 51 // Receive something
manumaet 0:f50e671ffff7 52 uint8_t rxenable = 0x01; // start listening
manumaet 0:f50e671ffff7 53 dw.writeRegister(DW1000_SYS_CTRL, 1, &rxenable, 1);
manumaet 0:f50e671ffff7 54
manumaet 2:16e45ff70baf 55 uint8_t frameready = 0; // check if frame received
manumaet 2:16e45ff70baf 56 while ((frameready & 0x20) != 0x20) { // while no frame ready
manumaet 2:16e45ff70baf 57 i++;
manumaet 2:16e45ff70baf 58 pc.printf("%d Waiting for frame... \r\n", i);
manumaet 2:16e45ff70baf 59 dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1);
manumaet 3:69587fadfa87 60 pc.printf("Status: %X\r\n", frameready);
manumaet 3:69587fadfa87 61 /*uint8_t receive[13] = "NOTHING IN!!"; // get data from buffer
manumaet 2:16e45ff70baf 62 dw.readRegister(DW1000_RX_BUFFER, 0, receive, 13);
manumaet 3:69587fadfa87 63 pc.printf("Message would be: %s\r\n", receive);*/
manumaet 2:16e45ff70baf 64 wait(0.5);
manumaet 2:16e45ff70baf 65 }
manumaet 0:f50e671ffff7 66
manumaet 0:f50e671ffff7 67 uint8_t receive[13] = "NOTHING IN!!"; // get data from buffer
manumaet 0:f50e671ffff7 68 dw.readRegister(DW1000_RX_BUFFER, 0, receive, 13);
manumaet 0:f50e671ffff7 69 pc.printf("Message received: %s\r\n", receive);
manumaet 0:f50e671ffff7 70 # endif
manumaet 0:f50e671ffff7 71 wait(0.5);
manumaet 3:69587fadfa87 72 return 0;
manumaet 0:f50e671ffff7 73 }
manumaet 0:f50e671ffff7 74 }