Hi @chris91 @gerhenz
I am a student and using DW3000 for research, I want to do UWB communication in interrupt mode instead of polling mode, but I am not able to implement it well!.
I want to use interrupt mode to realize simple_rx processing.
The remaining problem is that the IRQ pin does not switch between HIGH and LOW as data is received.
[Hardware Information]
・Microcontroller is XIAO ESP32 S3
・GPIO number of IRQ pin is 2
I added interrupt processing to the original program.
The program is only about 80 lines long, so could you please take a look at it a little to see if there are any problems?
I’ll show the code below.
Thank you.
#include "dw3000.h"
#define APP_NAME "INTERRUPT RX v1.2"
// connection pins
const uint8_t PIN_RST = 1; // reset pin
const uint8_t PIN_IRQ = 2; // irq pin
const uint8_t PIN_SS = 3; // spi select pin
static dwt_config_t config = {
5, /* Channel number. */
DWT_PLEN_128, /* Preamble length. Used in TX only. */
DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */
9, /* TX preamble code. Used in TX only. */
9, /* RX preamble code. Used in RX only. */
1, /* 0 to use standard 8 symbol SFD, 1 to use non-standard 8 symbol, 2 for non-standard 16 symbol SFD and 3 for 4z 8 symbol SDF type */
DWT_BR_6M8, /* Data rate. */
DWT_PHRMODE_STD, /* PHY header mode. */
DWT_PHRRATE_STD, /* PHY header rate. */
(129 + 8 - 8), /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */
DWT_STS_MODE_OFF, /* STS disabled */
DWT_STS_LEN_64, /* STS length */
DWT_PDOA_M0 /* PDOA mode off */
};
static uint8_t rx_buffer[FRAME_LEN_MAX];
uint32_t status_reg;
uint16_t frame_len;
// interrupt handler
void IRAM_ATTR dw3000_isr() {
Serial.println("Enter dw3000_isr()"); // display that you have entered an interrupt function
// processing of received data
status_reg = dwt_read32bitreg(SYS_STATUS_ID);
if (status_reg & SYS_STATUS_RXFCG_BIT_MASK) {
frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFLEN_BIT_MASK;
if (frame_len <= FRAME_LEN_MAX) {
dwt_readrxdata(rx_buffer, frame_len - FCS_LEN, 0);
}
dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG_BIT_MASK);
Serial.println("Frame Received"); // display that data was received.
} else {
dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);
}
dwt_rxenable(DWT_START_RX_IMMEDIATE);
}
void setup() {
Serial.begin(115200);
delay(500);
// SPI setting
spiBegin(PIN_IRQ, PIN_RST);
spiSelect(PIN_SS);
delay(200);
while (!dwt_checkidlerc()) {
Serial.println("IDLE FAILED");
while (1);
}
dwt_softreset();
delay(200);
if (dwt_initialise(DWT_DW_INIT) == DWT_ERROR) {
Serial.println("INIT FAILED");
while (1);
}
dwt_setleds(DWT_LEDS_ENABLE | DWT_LEDS_INIT_BLINK);
if (dwt_configure(&config)) {
Serial.println("CONFIG FAILED");
while (1);
}
// Set interrupt pin handler
attachInterrupt(PIN_IRQ, dw3000_isr, RISING);
dwt_rxenable(DWT_START_RX_IMMEDIATE);
delay(3000);
Serial.print("SetUp Finished");
}
void loop() {
/*
// Intentionally switch PIN_IRQ between HIGH and LOW at 0.1 second intervals
pinMode(PIN_IRQ, OUTPUT);
digitalWrite(PIN_IRQ, HIGH); // HIGH
pinMode(PIN_IRQ, INPUT);
delay(100);
pinMode(PIN_IRQ, OUTPUT);
digitalWrite(PIN_IRQ, LOW); // LOW
pinMode(PIN_IRQ, INPUT);
*/
}