Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Committer:
manumaet
Date:
Tue Nov 18 14:06:48 2014 +0000
Revision:
7:e634eeafc4d2
Parent:
6:d5864a1b9e17
Child:
8:7a9c61242e2f
first interrupt handled receiving (draft with callback, receive not fully API yet)

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 7:e634eeafc4d2 6 DW1000 dw(D11, D12, D13, D10, D14); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ)
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 5:111f11c95d27 13 //#define SENDER
manumaet 5:111f11c95d27 14
manumaet 6:d5864a1b9e17 15 void Interrupthandler() {
manumaet 6:d5864a1b9e17 16 pc.printf("Interrupt!!!!!!!!!!!!!!!!!!!!!!!!\r\n");
manumaet 7:e634eeafc4d2 17 uint8_t frameready = 0;
manumaet 7:e634eeafc4d2 18 dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1);
manumaet 7:e634eeafc4d2 19 pc.printf("Status: %X\r\n", frameready);
manumaet 7:e634eeafc4d2 20 // get data from buffer
manumaet 7:e634eeafc4d2 21 uint8_t receive[20] = "NOTHING IN!!";
manumaet 7:e634eeafc4d2 22 dw.readRegister(DW1000_RX_BUFFER, 0, receive, 20);
manumaet 7:e634eeafc4d2 23 pc.printf("Message received: %s -------------------------\r\n", receive);
manumaet 7:e634eeafc4d2 24 dw.resetRX();
manumaet 7:e634eeafc4d2 25 uint8_t rxenable = 0x01; // start listening
manumaet 7:e634eeafc4d2 26 dw.writeRegister(DW1000_SYS_CTRL, 1, &rxenable, 1);
manumaet 6:d5864a1b9e17 27 }
manumaet 6:d5864a1b9e17 28
manumaet 0:f50e671ffff7 29 int main() {
manumaet 4:6240b9c7a033 30 int i=0;
manumaet 0:f50e671ffff7 31 pc.printf("DecaWave 0.1\r\nup and running!\r\n");
manumaet 0:f50e671ffff7 32
manumaet 0:f50e671ffff7 33 dw.setEUI(0xFAEDCD01FAEDCD01);
manumaet 4:6240b9c7a033 34 pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID());
manumaet 4:6240b9c7a033 35 pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI());
manumaet 4:6240b9c7a033 36 pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
manumaet 0:f50e671ffff7 37
manumaet 4:6240b9c7a033 38 // read System Configuration
manumaet 4:6240b9c7a033 39 uint32_t conf = 0;
manumaet 4:6240b9c7a033 40 dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4);
manumaet 4:6240b9c7a033 41 pc.printf("%d System Configuration: %X\r\n", i, conf);
manumaet 4:6240b9c7a033 42
manumaet 7:e634eeafc4d2 43 wait(1);
manumaet 5:111f11c95d27 44
manumaet 5:111f11c95d27 45 #ifndef SENDR
manumaet 5:111f11c95d27 46 uint8_t dataframereadyinterrupt = 0x20; // only good frame would be 0x40
manumaet 5:111f11c95d27 47 dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1);
manumaet 7:e634eeafc4d2 48 dw.callbackRX = &Interrupthandler;
manumaet 7:e634eeafc4d2 49
manumaet 7:e634eeafc4d2 50 // Receive something
manumaet 7:e634eeafc4d2 51 uint8_t rxenable = 0x01; // start listening
manumaet 7:e634eeafc4d2 52 dw.writeRegister(DW1000_SYS_CTRL, 1, &rxenable, 1);
manumaet 5:111f11c95d27 53 #endif
manumaet 5:111f11c95d27 54
manumaet 0:f50e671ffff7 55 while(1) {
manumaet 0:f50e671ffff7 56 i++;
manumaet 0:f50e671ffff7 57
manumaet 5:111f11c95d27 58 # ifdef SENDER // to make one node sender and one receiver
manumaet 0:f50e671ffff7 59 // Send something
manumaet 4:6240b9c7a033 60 char message[20] = "HELLO WORLD!";
manumaet 4:6240b9c7a033 61 sprintf((char*)message, "HELLO WORLD! %d", i);
manumaet 4:6240b9c7a033 62 dw.sendFrame(message, 20);
manumaet 0:f50e671ffff7 63
manumaet 4:6240b9c7a033 64 uint8_t messagecheck[20];
manumaet 4:6240b9c7a033 65 dw.readRegister(DW1000_TX_BUFFER, 0, messagecheck, 20);
manumaet 4:6240b9c7a033 66 pc.printf("Message in buffer: %s\r\n", messagecheck);
manumaet 7:e634eeafc4d2 67 wait(2);
manumaet 0:f50e671ffff7 68 # endif
manumaet 4:6240b9c7a033 69
manumaet 0:f50e671ffff7 70 }
manumaet 0:f50e671ffff7 71 }