本帖最后由 putin 于 2025-4-7 22:19 编辑
啊哈又是我,为了完成我们伟大园长的任务,我绞尽脑汁挠破头皮,脑袋空空的,想不到到底用来干麻,然后我就去翻SDK你还别说你还真别说,伟大的想法随之而来。
一、SDK下载
下载方法可以看下面的链接:链接
由于之前有M61和wb2搭建环境的经验,想必已经有很多人在电脑上面装了git了吧我们只需要在一个空的文件夹里面点击右键,然后点击这个
再然后输入这个:git clone https://gitee.com/Ai-Thinker-Open/STM32F103-BU0x_SDK.git 回车即可
等待大概10秒钟左右即可。
这边建议下载完之后复制一个,因为一个要接收一个要发送这一次我们的测试。
ps:不要使用百度云的SDK那里面的没有用。
二、激活例程
这一步的话建议观看这个教程:教程
由于我们需要写睡眠和读普通的读模式,观看教程的话,建议直接观看tx_simple_sleep和simple_rx。
直接编两个工程烧录的话就是向教程一样的现象。
三、修改例程
还记得我们标题是什么吗?没错,我们的标题是使用按键进行唤醒,因此我们需要对tx_simple_sleep程序修改
函数路径如上图,在这里我们直接翻到最下面上面的全是初始化函数,无需修改。 - /* Loop forever sending frames periodically. */
- while(1)
- {
- /* 写入待发送数据到DW3000准备发送. (Write frame data to DW IC and prepare transmission. See NOTE 3 below.) */
- dwt_writetxdata(FRAME_LENGTH-FCS_LEN, tx_msg, 0); /* Zero offset in TX buffer. */
- /* 设置发送数据长度 (In this example since the length of the transmitted frame does not change,
- * nor the other parameters of the dwt_writetxfctrl function, the
- * dwt_writetxfctrl call could be outside the main while(1) loop.)
- */
- dwt_writetxfctrl(FRAME_LENGTH, 0, 0); /* Zero offset in TX buffer, no ranging. */
- /* 立即发送. (Start transmission.) */
- dwt_starttx(DWT_START_TX_IMMEDIATE);
- /* 查询DW3000是否发送成功. (Poll DW IC until TX frame sent event set. See NOTE 4 below.
- * STATUS register is 4 bytes long but, as the event we are looking at is in the first byte of the register, we can use this simplest API
- * function to access it.) */
- while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS_BIT_MASK))
- { };
- /* 清除发送事件. (Clear TX frame sent event.) */
- dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS_BIT_MASK);
- _dbg_printf((unsigned char *)"发送成功\n");
- /* 休眠TX_DELAY_MS. (Execute a delay between transmissions.) */
- Sleep(TX_DELAY_MS);
- /* 标志位Seq++处理. (Increment the blink frame sequence number (modulo 256).) */
- tx_msg[BLINK_FRAME_SN_IDX]++;
- }
复制代码
在这里,可以直接看到进入休眠模式使用这个函数dwt_entersleep(DWT_DW_IDLE)。我们需要使用按键来进行控制的话只需在这里我们初始化一个I/O口即。 - void tx_timed_sleep_GPIO_INIT()
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
- GPIO_InitTypeDef GPIO_Init_structure;
- GPIO_Init_structure.GPIO_Mode=GPIO_Mode_IPU;
- GPIO_Init_structure.GPIO_Pin=GPIO_Pin_8;
- GPIO_Init_structure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOB,&GPIO_Init_structure);
- }
- /**
- * Application entry point.
- */
- int tx_timed_sleep(void)
- {
- uint16_t lp_osc_freq, sleep_cnt;
- tx_timed_sleep_GPIO_INIT();
- /* 串口输出应用名称. Display application name on LCD. */
- _dbg_printf((unsigned char *)APP_NAME);
- /* 配置SPI快速率. Configure SPI rate, DW3000 supports up to 38 MHz */
- port_set_dw_ic_spi_fastrate();
- /* 硬复位DW3000模块. Reset DW IC */
- reset_DWIC(); /* Target specific drive of RSTn line into DW IC low for a period. */
- Sleep(2); // Time needed for DW3000 to start up (transition from INIT_RC to IDLE_RC)
- /* 检查DW3000模块是否处于IDLE_RC */
- while (!dwt_checkidlerc()) /* Need to make sure DW IC is in IDLE_RC before proceeding */
- { };
- /* 初始化DW3000模块 */
- if (dwt_initialise(DWT_DW_INIT) == DWT_ERROR)
- {
- _dbg_printf((unsigned char *)"INIT FAILED ");
- while (1)
- { };
- }
- /* 清除SPI就绪中断. Clearing the SPI ready interrupt*/
- dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RCINIT_BIT_MASK | SYS_STATUS_SPIRDY_BIT_MASK);
- /* 配置DW3000中断函数. Install DW IC IRQ handler. NOTE: the IRQ line must have a PULLDOWN or else it may trigger incorrectly when the device is sleeping*/
- // port_set_dwic_isr(dwt_isr);
- /* 校准和配置UWB计数. Calibrate and configure sleep count. */
- lp_osc_freq = XTAL_FREQ_HZ / dwt_calibratesleepcnt();
- sleep_cnt = ((SLEEP_TIME_MS * ((uint32_t) lp_osc_freq)) / 1000) >> 12;
- //sleep_cnt = 0x06; // 1 step is ~ 175ms, 6 ~= 1s
- dwt_configuresleepcnt(sleep_cnt);
- /* 配置DW3000信道参数. Configure DW IC. See NOTE 6 below. */
- if(dwt_configure(&config)) /* if the dwt_configure returns DWT_ERROR either the PLL or RX calibration has failed the host should reset the device */
- {
- _dbg_printf((unsigned char *)"CONFIG FAILED ");
- while (1)
- { };
- }
- /* 配置DW3000发送频谱参数. Configure the TX spectrum parameters (power, PG delay and PG count) */
- dwt_configuretxrf(&txconfig_options);
- /* 配置DW3000发送频谱参数. Configure sleep and wake-up parameters. */
- dwt_configuresleep(DWT_CONFIG, DWT_PRES_SLEEP | DWT_WAKE_CSN | DWT_SLEEP | DWT_SLP_EN);
- /* 注册中断回调函数. Register the call-backs (only SPI ready callback is used). */
- dwt_setcallbacks(NULL, NULL, NULL, NULL, NULL, &spi_ready_cb);
- port_EnableEXT_IRQ();
- _dbg_printf("配置成功\n");
- /* Loop forever sending frames periodically. */
- while (1)
- {
- /* DW3000进入休眠模式,唤醒后进入IDLE. Put DW IC to sleep. Go to IDLE state after wakeup*/
- dwt_entersleep(DWT_DW_IDLE);
- sleeping = 1;
- /* In this example, there is nothing to do to wake the DW IC up as it is handled by the sleep timer. */
- while (sleeping)
- {Sleep(1);}; /* Wait for device to wake up */
- /* 增加延时.必要*/
- Sleep(5);
- if(KEY==0)
- {
-
- _dbg_printf((unsigned char *)"唤醒成功:%04x\n", dwt_readdevid());
- /* 唤醒时恢复所有配置. Restore the required configurations on wake */
- dwt_restoreconfig();
- /* Increment the blink frame sequence number (modulo 256). */
- tx_msg[BLINK_FRAME_SN_IDX]++;
-
-
- /* 写入待发送数据到DW3000准备发送,并设置发送长度. Write frame data to DW IC 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);
- /* 查询DW3000是否发送成功. It is not possible to access DW IC registers once it has sent the frame and gone to sleep, and therefore we do not try to poll for TX
- * frame sent, but instead simply wait sufficient time for the DW IC to wake up again before we loop back to send another frame.
- * If interrupts are enabled, (e.g. if MTXFRS bit is set in the SYS_MASK register) then the TXFRS event will cause an active interrupt and
- * prevent the DW IC from sleeping. */
- /* Poll DW IC until TX frame sent event set. See NOTE 7 below.
- * STATUS register is 4 bytes long but, as the event we are looking at is in the first byte of the register, we can use this simplest API
- * function to access it.*/
- while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS_BIT_MASK))
- {};
- /* 清除发送完成事件. Clear TX frame sent event. */
- dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS_BIT_MASK);
-
- }
- }
- }
复制代码
代码如上。
四、实验现象
当我们将pb9直接接地时:
当我们将pb9不接地时(接收端和发送端无输出):
|