Hello all,
I have two arduino nano's, each attached to a dwm1000. This is on a custom breakout board and a breadboard. There is an arduino dwm1000 library here that I use to test with the boards. The basic tx/rx sketches work perfect and can ping-pong messages.
This library is not complete, and I need more advanced features for a project I am working on. So decawave(maker of the dwm) has a fully written driver for it: (DW1000 Application Programming Interface with STM32F10x Application examples) I ported the necessary functions to use the atmega chip.
Using the decawave driver, I can read/write all registers but am having issues with the basic tx/rx examples. It seems the transmission is not being properly sent. I am able to send code from my one board using the arduino library example, and receive it with the decawave basic rx example with no errors at all.
If I send from the decawave basic tx example, and receive it from the decawave basic rx example I receive it, but with errors.
Sometimes these bits get set:
CPLOCK, RXPRD, RXSFDD, RXPHE, SLP2INIT, CLKPLL_LL
Other times, these are set:
CPLOCK, RXPRD, RXSFDD, RXPHD, RXRFSL, SLP2INIT, CLKPLL_LL
From the sending code, the proper bits are getting set (TXFRB, TXPRS, TXPHS, TXFRS)
I have spent more time on this than I would like to admit, and hope someone has used this chip before and can help!
Thanks so much
My decawave driver tx code:
My decawave driver rx code:
I have two arduino nano's, each attached to a dwm1000. This is on a custom breakout board and a breadboard. There is an arduino dwm1000 library here that I use to test with the boards. The basic tx/rx sketches work perfect and can ping-pong messages.
This library is not complete, and I need more advanced features for a project I am working on. So decawave(maker of the dwm) has a fully written driver for it: (DW1000 Application Programming Interface with STM32F10x Application examples) I ported the necessary functions to use the atmega chip.
Using the decawave driver, I can read/write all registers but am having issues with the basic tx/rx examples. It seems the transmission is not being properly sent. I am able to send code from my one board using the arduino library example, and receive it with the decawave basic rx example with no errors at all.
If I send from the decawave basic tx example, and receive it from the decawave basic rx example I receive it, but with errors.
Sometimes these bits get set:
CPLOCK, RXPRD, RXSFDD, RXPHE, SLP2INIT, CLKPLL_LL
Other times, these are set:
CPLOCK, RXPRD, RXSFDD, RXPHD, RXRFSL, SLP2INIT, CLKPLL_LL
From the sending code, the proper bits are getting set (TXFRB, TXPRS, TXPHS, TXFRS)
I have spent more time on this than I would like to admit, and hope someone has used this chip before and can help!
Thanks so much
My decawave driver tx code:
Code:
#include <Arduino.h>
#include <SPI.h>
#include <prescaler.h>
#include <deca_device_api.h>
#include <deca_regs.h>
//#include "DW1000.h"
//#include "usart.h"
static dwt_config_t config = {
5, /* Channel number. */
DWT_PRF_16M, /* Pulse repetition frequency. */
DWT_PLEN_1024, /* Preamble length. Used in TX only. */
DWT_PAC32, /* Preamble acquisition chunk size. Used in RX only. */
4, /* TX preamble code. Used in TX only. */
4, /* RX preamble code. Used in RX only. */
0, /* 0 to use standard SFD, 1 to use non-standard SFD. */
DWT_BR_110K, /* Data rate. */
DWT_PHRMODE_STD, /* PHY header mode. */
(1025 + 64 - 32) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */
};
static uint8 tx_msg[] = {0xC5, 0, 'D', 'E', 'C', 'A', 'W', 'A', 'V', 'E', 0, 0};
/* Index to access to sequence number of the blink frame in the tx_msg array. */
#define BLINK_FRAME_SN_IDX 1
/* Inter-frame delay period, in milliseconds. */
#define TX_DELAY_MS 1000
void reset_DW1000()
{
digitalWrite(5, LOW);
pinMode(5, OUTPUT);
delay(10);
pinMode(5, INPUT);
delay(10);
}
void setup()
{
SPI.begin();
Serial.begin(9600);
while (!Serial) { ; };
delay(50);
reset_DW1000();
setClockPrescaler(CLOCK_PRESCALER_8);
if (dwt_initialise(DWT_LOADNONE) == DWT_ERROR)
{
setClockPrescaler(CLOCK_PRESCALER_1);
Serial.println("INIT FAILED");
while (1)
{ };
}
setClockPrescaler(CLOCK_PRESCALER_1);
dwt_configure(&config);
}
void loop()
{
/* Write frame data to DW1000 and prepare transmission. See NOTE 4 below.*/
dwt_writetxdata(sizeof(tx_msg), tx_msg, 0); /* Zero offset in TX buffer. */
dwt_writetxfctrl(sizeof(tx_msg), 0, 0); /* Zero offset in TX buffer, no ranging. */
/* Start transmission. */
dwt_starttx(DWT_START_TX_IMMEDIATE);
while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))
{ };
/* Clear TX frame sent event. */
dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS);
/* Execute a delay between transmissions. */
delay(TX_DELAY_MS);
/* Increment the blink frame sequence number (modulo 256). */
tx_msg[BLINK_FRAME_SN_IDX]++;
}
My decawave driver rx code:
Code:
#include <Arduino.h>
#include <SPI.h>
#include <prescaler.h>
#include <deca_device_api.h>
#include <deca_regs.h>
//#include "USART.h"
/*! ----------------------------------------------------------------------------
* @file main.c
* @brief Simple RX example code
*
* @attention
*
* Copyright 2015 (c) Decawave Ltd, Dublin, Ireland.
*
* All rights reserved.
*
* @author Decawave
*/
static dwt_config_t config = {
5, /* Channel number. */
DWT_PRF_16M, /* Pulse repetition frequency. */
DWT_PLEN_1024, /* Preamble length. Used in TX only. */
DWT_PAC32, /* Preamble acquisition chunk size. Used in RX only. */
4, /* TX preamble code. Used in TX only. */
4, /* RX preamble code. Used in RX only. */
0, /* 0 to use standard SFD, 1 to use non-standard SFD. */
DWT_BR_110K, /* Data rate. */
DWT_PHRMODE_STD, /* PHY header mode. */
(1025 + 64 - 32) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */
};
#define FRAME_LEN_MAX 127
static uint8 rx_buffer[FRAME_LEN_MAX];
static uint32 status_reg = 0;
static uint16 frame_len = 0;
void reset_DW1000()
{
digitalWrite(5, LOW);
pinMode(5, OUTPUT);
delay(10);
pinMode(5, INPUT);
delay(10);
}
void debug_register(uint16_t reg, uint8_t len)
{
uint8_t ar[len];
dwt_readfromdevice (reg, 0, len, ar) ;
for (int i=0; i<len; i++)
{
Serial.print(i); Serial.print(" = "); Serial.println(ar[i]);
}
}
void setup()
{
SPI.begin();
Serial.begin(9600);
//initUSART();
while (!Serial) { ; };
delay(50);
Serial.println("Hi hello hi hello fdaffasd?");
reset_DW1000();
setClockPrescaler(CLOCK_PRESCALER_8);
if (dwt_initialise(DWT_LOADNONE) == DWT_ERROR)
{
setClockPrescaler(CLOCK_PRESCALER_1);
Serial.println("INIT FAILED");
while (1)
{ };
}
setClockPrescaler(CLOCK_PRESCALER_1);
delay(50);
dwt_configure(&config);
}
void loop()
{
int i;
for (i = 0 ; i < FRAME_LEN_MAX; i++ )
{
rx_buffer[i] = 0;
}
dwt_rxenable(DWT_START_RX_IMMEDIATE);
while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR))) { ; }
if (status_reg & SYS_STATUS_RXFCG)
{
frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFL_MASK_1023;
if (frame_len <= FRAME_LEN_MAX)
{
dwt_readrxdata(rx_buffer, frame_len, 0);
}
dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG);
}
else
{
dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);
}
}