Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

main.cpp

Committer:
manumaet
Date:
2014-11-16
Revision:
1:1311e7af0a5c
Parent:
0:f50e671ffff7
Child:
2:16e45ff70baf

File content as of revision 1:1311e7af0a5c:

#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);     // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS)

/*uint32_t read32Bit(uint8_t reg, uint16_t subaddress) {
    uint32_t result = 0;
    
}*/

int main() {
    pc.printf("DecaWave 0.1\r\nup and running!\r\n");
    
    dw.setEUI(0xFAEDCD01FAEDCD01);
    
    int i=0;
    while(1) {
        i++;
        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);
        
# if 0                      // to make one node sender and one receiver
        // Send something
        uint8_t message[13] = "HELLO WORLD!";   // fill buffer
        //sprintf((char*)message, "%d World!!", i);
        dw.writeRegister(DW1000_TX_BUFFER, 0, message, 13);
        uint8_t messagecheck[13];
        dw.readRegister(DW1000_TX_BUFFER, 0, messagecheck, 13);
        pc.printf("Message in buffer: %s\r\n", messagecheck);
        
        uint16_t framelength = 13;              // put length of frame
        dw.writeRegister(DW1000_TX_FCTRL, 0, (uint8_t*)&framelength, 1);
        
        if ((i % 2) == 0) {
            uint8_t txstart = 0x02;             // trigger sending process
            dw.writeRegister(DW1000_SYS_CTRL, 0, &txstart, 1);
        }
# else
        // Receive something
        uint8_t rxenable = 0x01;                // start listening
        dw.writeRegister(DW1000_SYS_CTRL, 1, &rxenable, 1);
        
        //uint8_t frameready = 0;                 // check if frame received
        //while (frameready != 0x20) {
        //    i++;
        //    pc.printf("%d Waiting for frame... \r\n", i);
        //    dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 13);
        //    wait(0.5);
        //}
        
        uint8_t receive[13] = "NOTHING IN!!";   // get data from buffer
        dw.readRegister(DW1000_RX_BUFFER, 0, receive, 13);
        pc.printf("Message received: %s\r\n", receive);
# endif
        
        wait(0.5);
    }
}