mbedgroup
/
DecaWave
k
Fork of DecaWave by
main.cpp@20:257d56530ae1, 2014-11-25 (annotated)
- Committer:
- manumaet
- Date:
- Tue Nov 25 15:22:53 2014 +0000
- Revision:
- 20:257d56530ae1
- Parent:
- 19:e94bc88c1eb0
- Child:
- 21:23bf4399020d
minor changes to API, before implementing autoack and timing try
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 | 7:e634eeafc4d2 | 6 | DW1000 dw(D11, D12, D13, D10, D14); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ) |
manumaet | 0:f50e671ffff7 | 7 | |
manumaet | 15:e1fea7e2aff1 | 8 | const float timeunit = 1/(128*499.2e6); |
manumaet | 14:8041c9b68406 | 9 | int i=0; |
manumaet | 17:8afa5f9122da | 10 | char message[1200] = ""; |
manumaet | 11:c87d37db2c6f | 11 | uint64_t timestamp_old = 0; |
manumaet | 14:8041c9b68406 | 12 | |
manumaet | 18:bbc7ca7d3a95 | 13 | void callbackRX(int framelength) { |
manumaet | 20:257d56530ae1 | 14 | if (framelength<200) { |
manumaet | 16:96879e1c99f2 | 15 | char* receive = dw.receiveString(); // receive a string |
manumaet | 16:96879e1c99f2 | 16 | pc.printf("Received: \"%s\" %d ", receive, framelength); |
manumaet | 16:96879e1c99f2 | 17 | delete[] receive; |
manumaet | 16:96879e1c99f2 | 18 | } else |
manumaet | 16:96879e1c99f2 | 19 | pc.printf("Received! %d ", framelength); |
manumaet | 10:d077bb12d259 | 20 | |
manumaet | 18:bbc7ca7d3a95 | 21 | pc.printf("Status: %010llX ", dw.getStatus()); |
manumaet | 11:c87d37db2c6f | 22 | |
manumaet | 18:bbc7ca7d3a95 | 23 | uint64_t timestamp = dw.readRegister40(DW1000_RX_TIME, 0); |
manumaet | 11:c87d37db2c6f | 24 | uint64_t difference = timestamp - timestamp_old; |
manumaet | 11:c87d37db2c6f | 25 | timestamp_old = timestamp; |
manumaet | 15:e1fea7e2aff1 | 26 | //pc.printf("Timestamp: %lld\r\n", difference); |
manumaet | 20:257d56530ae1 | 27 | pc.printf("Timestamp: %fs\r\n", difference*timeunit); // TODO: gives some wrong values because of timer overflow |
manumaet | 17:8afa5f9122da | 28 | dw.startRX(); |
manumaet | 6:d5864a1b9e17 | 29 | } |
manumaet | 6:d5864a1b9e17 | 30 | |
manumaet | 18:bbc7ca7d3a95 | 31 | void callbackTX() { |
manumaet | 18:bbc7ca7d3a95 | 32 | char messagecheck[1200]; |
manumaet | 18:bbc7ca7d3a95 | 33 | dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1); |
manumaet | 18:bbc7ca7d3a95 | 34 | if (i < 200) |
manumaet | 18:bbc7ca7d3a95 | 35 | pc.printf("%d Sent: \"%s\" %d ", i, messagecheck, strlen(message)+1); |
manumaet | 18:bbc7ca7d3a95 | 36 | else |
manumaet | 18:bbc7ca7d3a95 | 37 | pc.printf("%d Sent! %d ", i, strlen(message)+1); |
manumaet | 18:bbc7ca7d3a95 | 38 | pc.printf("Status: %010llX\r\n", dw.getStatus()); |
manumaet | 18:bbc7ca7d3a95 | 39 | } |
manumaet | 18:bbc7ca7d3a95 | 40 | |
manumaet | 0:f50e671ffff7 | 41 | int main() { |
manumaet | 20:257d56530ae1 | 42 | pc.printf("DecaWave 0.1\r\nup and running!\r\n"); |
manumaet | 20:257d56530ae1 | 43 | dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection |
manumaet | 4:6240b9c7a033 | 44 | pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID()); |
manumaet | 4:6240b9c7a033 | 45 | pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI()); |
manumaet | 4:6240b9c7a033 | 46 | pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage()); |
manumaet | 0:f50e671ffff7 | 47 | |
manumaet | 18:bbc7ca7d3a95 | 48 | dw.callbackRX = &callbackRX; // TODO: must not jump to NULL & setter |
manumaet | 18:bbc7ca7d3a95 | 49 | dw.callbackTX = &callbackTX; |
manumaet | 14:8041c9b68406 | 50 | |
manumaet | 14:8041c9b68406 | 51 | // Receiver initialisation |
manumaet | 20:257d56530ae1 | 52 | dw.writeRegister16(DW1000_SYS_MASK, 0, 0x4080); // TODO: RX only good frame 0x4000, RX all frames 0x2000, TX done 0x0080 |
manumaet | 17:8afa5f9122da | 53 | dw.startRX(); |
manumaet | 5:111f11c95d27 | 54 | |
manumaet | 0:f50e671ffff7 | 55 | while(1) { |
manumaet | 19:e94bc88c1eb0 | 56 | #if 1 |
manumaet | 17:8afa5f9122da | 57 | if(i < 1200) { |
manumaet | 17:8afa5f9122da | 58 | message[i] = 48+ (i%10); |
manumaet | 17:8afa5f9122da | 59 | message[i+1] = '\0'; |
manumaet | 17:8afa5f9122da | 60 | } |
manumaet | 16:96879e1c99f2 | 61 | |
manumaet | 19:e94bc88c1eb0 | 62 | wait(0.01); |
manumaet | 10:d077bb12d259 | 63 | dw.sendString(message); |
manumaet | 15:e1fea7e2aff1 | 64 | |
manumaet | 17:8afa5f9122da | 65 | #endif |
manumaet | 15:e1fea7e2aff1 | 66 | #if 0 |
manumaet | 15:e1fea7e2aff1 | 67 | pc.printf("%d Waiting... ", i); |
manumaet | 19:e94bc88c1eb0 | 68 | pc.printf("Status: %010llX\r\n", dw.getStatus()); |
manumaet | 15:e1fea7e2aff1 | 69 | wait(5); |
manumaet | 15:e1fea7e2aff1 | 70 | #endif |
manumaet | 15:e1fea7e2aff1 | 71 | i++; |
manumaet | 0:f50e671ffff7 | 72 | } |
manumaet | 0:f50e671ffff7 | 73 | } |