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.
main.cpp
- Committer:
- manumaet
- Date:
- 2014-11-21
- Revision:
- 10:d077bb12d259
- Parent:
- 9:c8839de428ac
- Child:
- 11:c87d37db2c6f
File content as of revision 10:d077bb12d259:
#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)
#define SENDER
void Interrupthandler() {
/*uint8_t frameready = 0;
dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1);
pc.printf("Interrupt status: %X\r\n", frameready);*/
uint16_t framelength = 0; // get framelength
dw.readRegister(DW1000_RX_FINFO, 0, (uint8_t*)&framelength, 2);
framelength &= 0x03FF;
framelength -= 2;
char* receive = dw.receiveString();
pc.printf("Message Received: %s %d\r\n", receive, framelength);
delete[] receive;
dw.resetRX(); // TODO: is crucial because otherwise only 1 frame is received correct
dw.receiveFrame();
}
int main() {
int i=0;
char message[1024] = "";
pc.printf("DecaWave 0.1\r\nup and running!\r\n");
dw.setEUI(0xFAEDCD01FAEDCD01);
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());
// read System Configuration
uint32_t conf = 0;
dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4);
pc.printf("%d System Configuration: %X\r\n", i, conf);
wait(1);
dw.callbackRX = &Interrupthandler;
#ifndef SENDER
uint8_t dataframereadyinterrupt = 0x40; // only good frame 0x40 all frames 0x20
dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1);
// Receive something
dw.receiveFrame();
#endif
while(1) {
i++;
# ifdef SENDER // to make one node sender and one receiver
// Send something
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));
else
pc.printf("%d Message: %d\r\n", i, strlen(message));
dw.sendString(message);
char messagecheck[1024];
dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1);
messagecheck[1] = '\0';
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);
/*for(int i=0; i<10; i++) { // to control Voltage
pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
wait(0.2);
}*/
wait(1);
#else
pc.printf("%d Waiting...\r\n", i);
wait(1);
# endif
}
}
