Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 15:e1fea7e2aff1, committed 2014-11-23
- Comitter:
- manumaet
- Date:
- Sun Nov 23 20:45:14 2014 +0000
- Parent:
- 14:8041c9b68406
- Child:
- 16:96879e1c99f2
- Commit message:
- sending of 1020 chars in one frame worked
Changed in this revision
| DW1000/DW1000.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/DW1000/DW1000.cpp Sun Nov 23 15:37:45 2014 +0000
+++ b/DW1000/DW1000.cpp Sun Nov 23 20:45:14 2014 +0000
@@ -8,6 +8,7 @@
//resetAll(); // we can do a soft reset if we want to (only needed for debugging)
loadLDE(); // important everytime DW1000 initialises/awakes otherwise the LDE algorithm must be turned of or there's receiving malfunction see User Manual LDELOAD on p22 & p158
writeRegister8(DW1000_SYS_CFG, 3, 0x20); // enable auto reenabling receiver after error
+ writeRegister8(DW1000_SYS_CFG, 2, 0x03); // enable 1024 byte frames TODO: doesn't work!!
irq.rise(this, &DW1000::ISR); // attach Interrupt handler to rising edge
}
--- a/main.cpp Sun Nov 23 15:37:45 2014 +0000
+++ b/main.cpp Sun Nov 23 20:45:14 2014 +0000
@@ -5,19 +5,19 @@
PC pc(USBTX, USBRX, 921600); // USB UART Terminal
DW1000 dw(D11, D12, D13, D10, D14); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ)
+const float timeunit = 1/(128*499.2e6);
int i=0;
bool starter = 1;
bool ping = 0;
char message[1024] = "";
uint64_t timestamp_old = 0;
-//#define DEBUGSTRING
+//#define PINGPONG
void Interrupthandler() {
/*uint8_t frameready = 0;
dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1);
pc.printf("Interrupt status: %X\r\n", frameready);*/
- starter = 0;
uint16_t framelength = 0; // get framelength TODO: just for debugging of string
dw.readRegister(DW1000_RX_FINFO, 0, (uint8_t*)&framelength, 2);
@@ -25,9 +25,10 @@
framelength -= 2;
char* receive = dw.receiveString(); // receive a string
- pc.printf("Received: %s %d ", receive, framelength);
+ pc.printf("Received: \"%s\" %d ", receive, framelength);
delete[] receive;
+# ifdef PINGPONG
uint64_t status;
dw.readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5);
status &= 0xFFFFFFFFFF; // only 40-Bit
@@ -38,8 +39,10 @@
timestamp &= 0xFFFFFFFFFF; // only 40-Bit
uint64_t difference = timestamp - timestamp_old;
timestamp_old = timestamp;
- pc.printf("Timestamp: %lld\r\n", difference);
+ //pc.printf("Timestamp: %lld\r\n", difference);
+ pc.printf("Timestamp: %fs", difference*timeunit); // TODO: gives some wrong values because of timer overflow
+ starter = 0;
wait(1); // TODO: ugly, never wait in interrupthandler!
if (ping) {
sprintf((char*)message, "PING! %d", i);
@@ -48,7 +51,8 @@
sprintf((char*)message, "PONG! %d", i);
dw.sendString(message);
}
-
+#endif
+ pc.printf("\r\n");
dw.receiveFrame();
}
@@ -71,37 +75,30 @@
dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1);
dw.receiveFrame();
+# ifdef PINGPONG
wait(3);
+# endif
while(1) {
- i++;
-# ifdef DEBUGSTRING // to make one node sender and one receiver
- //message[i-1] = 'O';
- //message[i] = '\0';
- sprintf((char*)message, "HELLO WORLD! %d", i);
- //if (i < 200)
- pc.printf("%d Message: \"%s\" %d\r\n", i, message, strlen(message)+1);
- //else
- //pc.printf("%d Message: %d\r\n", i, strlen(message)+1);
+# ifndef PINGPONG
+ message[i] = 48+ (i%10);
+ message[i+1] = '\0';
+
+ pc.printf("%d Message: \"%s\" %d\r\n", i, message, strlen(message)+1);
+ wait(0.1);
+ char messagecheck[1024];
dw.sendString(message);
-
- char messagecheck[1024];
+ wait(0.1);
dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1);
- //if (i < 200)
- pc.printf("%d Buffer: \"%s\" %d\r\n", i, messagecheck, strlen(messagecheck)+1);
- //else
- //pc.printf("%d Buffer: %d\r\n", i, strlen(messagecheck)+1);
+ pc.printf("%d nBuffer: \"%s\" %d\r\n\r\n", i, messagecheck, strlen(messagecheck)+1);
+ wait(0.2);
+
+ //return 0;
/*for(int i=0; i<10; i++) { // to control Voltage
pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
wait(0.2);
}*/
- //if (i<27)
- wait(1);
- //else
- //wait(3);
-#else
- pc.printf("%d Waiting... ", i);
-
+#else
if (starter) {
ping = 1;
while (starter) {
@@ -111,14 +108,16 @@
}
}
-
+ wait(1);
+# endif
+#if 0
+ pc.printf("%d Waiting... ", i);
uint64_t status;
dw.readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5);
status &= 0xFFFFFFFFFF; // only 40-Bit
pc.printf("Status: %010llX\r\n", status);
-
- wait(1);
-# endif
-
+ wait(5);
+#endif
+ i++;
}
}
\ No newline at end of file