Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

main.cpp

Committer:
manumaet
Date:
2014-11-18
Revision:
8:7a9c61242e2f
Parent:
7:e634eeafc4d2
Child:
9:c8839de428ac

File content as of revision 8:7a9c61242e2f:

#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);
    // get data from buffer
    uint8_t receive[20] = "NOTHING IN!!";
    dw.readRegister(DW1000_RX_BUFFER, 0, receive, 20);
    pc.printf("Message received: %s\r\n", receive);
    dw.resetRX();
    dw.receiveFrame();
}

int main() {
    int i=0;
    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 SENDR
    uint8_t dataframereadyinterrupt = 0x20; // only good frame would be 0x40
    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
        char message[20];
        sprintf((char*)message, "HELLO WORLD! %d", i);
        dw.sendFrame(message, 20);
        
        uint8_t messagecheck[20] = "HELLO WORLD!";
        dw.readRegister(DW1000_TX_BUFFER, 0, messagecheck, 20);
        pc.printf("Message in buffer: %s\r\n", messagecheck);
        wait(2);
#else
        pc.printf("%d Waiting...\r\n", i);
        wait(5);
# endif
        
    }
}