/* Start with board specific hardware init. */
peripherals_init();
/* Display application name on LCD. */
lcd_display_str(APP_NAME);
/* Install the low-power listening ISR handler.
* This is an interrupt service routine part of the driver that is specific to correctly handling the low-power listening wake-up. */
port_set_deca_isr(dwt_lowpowerlistenisr);
/* Reset and initialise DW1000. See NOTE 8 and 9 below.
* For initialisation, DW1000 clocks must be temporarily set to crystal speed. After initialisation SPI rate can be increased for optimum
* performance. */
reset_DW1000(); /* Target specific drive of RSTn line into DW1000 low for a period. */
spi_set_rate_low();
if (dwt_initialise(DWT_LOADNONE) == DWT_ERROR)
{
lcd_display_str("INIT FAILED");
while (1)
{ };
}
spi_set_rate_high();
/* This is put here for testing, so that we can see the receiver ON/OFF pattern using an oscilloscope. */
dwt_setlnapamode(1, 1);
/* Configure DW1000. See NOTE 10 below. */
dwt_configure(&config);
/* Calibrate and configure sleep count. This has to be done with DW1000 clocks set to crystal speed.
* This will define the duration of the "long sleep" phase. */
spi_set_rate_low();
lp_osc_freq = (XTAL_FREQ_HZ / 2) / dwt_calibratesleepcnt();
sleep_cnt = ((LONG_SLEEP_TIME_MS * lp_osc_freq) / 1000) >> 12;
dwt_configuresleepcnt(sleep_cnt);
spi_set_rate_high();
/* Configure sleep mode to allow low-power listening to operate properly. */
dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG | DWT_RX_EN, DWT_WAKE_SLPCNT | DWT_SLP_EN);
/* Set snooze time. This will define the duration of the "short sleep" phase. */
dwt_setsnoozetime(LPL_SHORT_SLEEP_SNOOZE_TIME);
/* Set preamble detect timeout. This will define the duration of the reception phases. */
dwt_setpreambledetecttimeout(LPL_RX_SNIFF_TIME);
/* Wait for a frame to be received.
* The user should look at the "rx_ok_cb" function below to see the next piece of RX handling before reading on through the rest of the main
* line code here. */
while (!rx_frame)
{ };
/* Configure DW1000 for next sleep phases so we can go to DEEPSLEEP and wake with SPI CS wake-up. */
dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_SLP_EN);
/* Read received frame's countdown to the end of the wake-up sequence. */
wus_end_frame_nb = (rx_buffer[DATA_FRAME_WUS_CNTDWN_IDX + 1] << 8) + rx_buffer[DATA_FRAME_WUS_CNTDWN_IDX];
wus_end_time_ms = (wus_end_frame_nb * WUS_FRAME_TIME_US) / 1000;
/* Check that the wake-up sequence is destined to this application. */
if ((rx_buffer[DATA_FRAME_DEST_ADDR_IDX + 1] == 'R') && (rx_buffer[DATA_FRAME_DEST_ADDR_IDX] == 'X'))
{
/* TESTING BREAKPOINT LOCATION #1 */
/* Put the DW1000 to sleep. */
dwt_entersleep();
/* Wait for the end of the wake-up sequence. */
sleep_ms(wus_end_time_ms);
/* Wake DW1000 up. See NOTE 7 below. */
dwt_spicswakeup(dummy_buffer, DUMMY_BUFFER_LEN);
/* Write interaction message data to DW1000 and prepare transmission. See NOTE 11 below. */
dwt_writetxdata(sizeof(interaction_msg), interaction_msg, 0); /* Zero offset in TX buffer. */
dwt_writetxfctrl(sizeof(interaction_msg), 0, 0); /* Zero offset in TX buffer, no ranging. */
/* Poll DW1000 until TX frame sent event set. See NOTE 12 below.
* STATUS register is 5 bytes long but we are not interested in the high byte here, so we read a more manageable 32-bits with this API
* call. */
while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))
{ };
/* Clear TX frame sent event. */
dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS);
/* Increment the frame sequence number (modulo 256). */
interaction_msg[DATA_FRAME_SEQ_NB_IDX]++;
}
else
{
/* TESTING BREAKPOINT LOCATION #2 */
/* Compute the time until the end of the interaction period (after end of the wake-up sequence). */
uint32 sleep_time_ms = wus_end_time_ms + INTERACTION_PERIOD_MAX_TIME_MS;
/* Put the DW1000 to sleep. */
dwt_entersleep();
/* Wait for the end of the interaction period. */
sleep_ms(sleep_time_ms);
/* Wake DW1000 up. See NOTE 7 below. */
dwt_spicswakeup(dummy_buffer, DUMMY_BUFFER_LEN);
}
/* Go back to low-power listening.
* Sleep mode must be reconfigured to allow low-power listening to operate properly as it has been modified earlier. */
dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG | DWT_RX_EN, DWT_WAKE_SLPCNT | DWT_SLP_EN);
dwt_setlowpowerlistening(1);
dwt_entersleep();
rx_frame = 0;
};
} 作者: Nero.qi 时间: 2022-3-17 11:19
官方的例程如果收到正确得FCG 会进入到中断服务函数 static void rx_ok_cb(const dwt_cb_data_t *cb_data)
程序如下
/*! ------------------------------------------------------------------------------------------------------------------
* @fn rx_ok_callback()
*
* @brief Call-back to process RX good frames events
*
* @param cb_data call-back data
*
* @return none
*/
static void rx_ok_cb(const dwt_cb_data_t *cb_data)
{
if (cb_data->datalength == WUS_FRAME_LEN)
{
/* A frame of correct length to be a wake-up message has been received, copy it to our local buffer. */
dwt_readrxdata(rx_buffer, cb_data->datalength, 0);
/* Validate the frame is addressed to us from the expected sender and has the encoding of one of the wake-up sequence messages we expect.
* Then signal the arrival of the wake-up message to the background main loop by setting the rx_frame event flag. */
if ((rx_buffer[DATA_FRAME_PAN_ID_IDX + 1] == 0xDE) && (rx_buffer[DATA_FRAME_PAN_ID_IDX] == 0xCA)
&& (rx_buffer[DATA_FRAME_SRC_ADDR_IDX + 1] == 'T') && (rx_buffer[DATA_FRAME_SRC_ADDR_IDX] == 'X')
&& (rx_buffer[DATA_FRAME_APP_FCODE_IDX] == 0xE0))
{
rx_frame = 1;
}
}
/* If the frame is not from the expected wake-up sequence, go back to low-power listening. */
if (!rx_frame)
{
dwt_setlowpowerlistening(1); /* No need to reconfigure sleep mode here as it has not been modified since wake-up. */
dwt_entersleep();
non_wus_frame_rx_nb++;
}
} 作者: Nero.qi 时间: 2022-3-17 11:21
现在我的问题是 我将程序移植到我的代码里 不能进入到 rx_ok_callback()中断内作者: Nero.qi 时间: 2022-3-17 11:26
以下是我设置的相关的代码
reset_DW1000(); /* RSTn低电平一段时间 */
//if (dwt_initialise(DWT_LOADNONE) == DWT_ERROR)
if (dwt_initialise(DWT_LOADUCODE) == DWT_ERROR)
{
Display_8x16_ASCII_Str("INIT FAILED",2,0);
while (1)
;
}
/* Calibrate and configure sleep count. This has to be done with DW1000 clocks set to crystal speed.
* This will define the duration of the "long sleep" phase. */
spi_set_rate_low();
lp_osc_freq = (XTAL_FREQ_HZ / 2) / dwt_calibratesleepcnt();
sleep_cnt = ((LONG_SLEEP_TIME_MS * lp_osc_freq) / 1000) >> 12;
dwt_configuresleepcnt(sleep_cnt);
spi_set_rate_high();
/* Configure sleep mode to allow low-power listening to operate properly. */
dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG | DWT_RX_EN, DWT_WAKE_SLPCNT | DWT_SLP_EN);
/* Set snooze time. This will define the duration of the "short sleep" phase. */
dwt_setsnoozetime(LPL_SHORT_SLEEP_SNOOZE_TIME);
/* Set preamble detect timeout. This will define the duration of the reception phases. */
dwt_setpreambledetecttimeout(LPL_RX_SNIFF_TIME);