mbedgroup
/
DecaWave
k
Fork of DecaWave by
main.cpp
- Committer:
- manumaet
- Date:
- 2014-11-24
- Revision:
- 18:bbc7ca7d3a95
- Parent:
- 17:8afa5f9122da
- Child:
- 19:e94bc88c1eb0
File content as of revision 18:bbc7ca7d3a95:
#include "mbed.h" #include "PC.h" // Serial Port via USB for debugging with Terminal #include "DW1000.h" 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; char message[1200] = ""; uint64_t timestamp_old = 0; void callbackRX(int framelength) { if(framelength<200) { char* receive = dw.receiveString(); // receive a string pc.printf("Received: \"%s\" %d ", receive, framelength); delete[] receive; } else pc.printf("Received! %d ", framelength); pc.printf("Status: %010llX ", dw.getStatus()); uint64_t timestamp = dw.readRegister40(DW1000_RX_TIME, 0); uint64_t difference = timestamp - timestamp_old; timestamp_old = timestamp; //pc.printf("Timestamp: %lld\r\n", difference); pc.printf("Timestamp: %fs", difference*timeunit); // TODO: gives some wrong values because of timer overflow pc.printf("\r\n"); dw.startRX(); } void callbackTX() { char messagecheck[1200]; dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1); if (i < 200) pc.printf("%d Sent: \"%s\" %d ", i, messagecheck, strlen(message)+1); else pc.printf("%d Sent! %d ", i, strlen(message)+1); pc.printf("Status: %010llX\r\n", dw.getStatus()); } int main() { pc.printf("DecaWave 0.1\r\nup and running!\r\n"); dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a slave pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID()); pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI()); pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage()); uint32_t conf = 0; // read System Configuration dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4); pc.printf("%d System Configuration: %X\r\n", i, conf); dw.callbackRX = &callbackRX; // TODO: must not jump to NULL & setter dw.callbackTX = &callbackTX; // Receiver initialisation dw.writeRegister16(DW1000_SYS_MASK, 0, 0x4080); // RX only good frame 0x4000, RX all frames 0x2000, TX done 0x0080 dw.startRX(); while(1) { #if 0 if(i < 1200) { message[i] = 48+ (i%10); message[i+1] = '\0'; } //wait(0.1); dw.sendString(message); #endif #if 0 pc.printf("%d Waiting... ", i); pc.printf("Status: %010llX ", dw.getStatus()); wait(5); #endif i++; } }