Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
Diff: main.cpp
- Revision:
- 7:e634eeafc4d2
- Parent:
- 6:d5864a1b9e17
- Child:
- 8:7a9c61242e2f
diff -r d5864a1b9e17 -r e634eeafc4d2 main.cpp --- a/main.cpp Tue Nov 18 13:39:50 2014 +0000 +++ b/main.cpp Tue Nov 18 14:06:48 2014 +0000 @@ -3,7 +3,7 @@ #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) +DW1000 dw(D11, D12, D13, D10, D14); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ) /*uint32_t read32Bit(uint8_t reg, uint16_t subaddress) { uint32_t result = 0; @@ -14,6 +14,16 @@ void Interrupthandler() { pc.printf("Interrupt!!!!!!!!!!!!!!!!!!!!!!!!\r\n"); + uint8_t frameready = 0; + dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1); + pc.printf("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(); + uint8_t rxenable = 0x01; // start listening + dw.writeRegister(DW1000_SYS_CTRL, 1, &rxenable, 1); } int main() { @@ -30,13 +40,16 @@ dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4); pc.printf("%d System Configuration: %X\r\n", i, conf); - wait(5); + wait(1); #ifndef SENDR uint8_t dataframereadyinterrupt = 0x20; // only good frame would be 0x40 dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1); - InterruptIn button(USER_BUTTON); - button.rise(&Interrupthandler); + dw.callbackRX = &Interrupthandler; + + // Receive something + uint8_t rxenable = 0x01; // start listening + dw.writeRegister(DW1000_SYS_CTRL, 1, &rxenable, 1); #endif while(1) { @@ -51,38 +64,7 @@ uint8_t messagecheck[20]; dw.readRegister(DW1000_TX_BUFFER, 0, messagecheck, 20); pc.printf("Message in buffer: %s\r\n", messagecheck); - wait(2); -# 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 == 0 /*& 0x20) != 0x20*/) { // while no frame ready - i++; - - pc.printf("%d Waiting for frame... ", i); - dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1); - pc.printf("Status: %X ", frameready); - uint8_t receive[20] = "NOTHING IN!!"; // get data from buffer - dw.readRegister(DW1000_RX_BUFFER, 0, receive, 20); - pc.printf("Message would be: %s\r\n", receive); - wait(0.3); - } - - // 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.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1); - pc.printf("Status: %X\r\n", frameready); - - dw.resetRX(); - wait(0.5); - continue; - + wait(2); # endif }