发帖
0 0 0

【BU03-Kit 测评】UWB 使用SDK按键唤醒

putin
论坛元老

19

主题

128

回帖

3220

积分

论坛元老

积分
3220
UWB 10 0 昨天 22:19
本帖最后由 putin 于 2025-4-7 22:19 编辑

  啊哈又是我,为了完成我们伟大园长的任务,我绞尽脑汁挠破头皮,脑袋空空的,想不到到底用来干麻,然后我就去翻SDK你还别说你还真别说,伟大的想法随之而来。
一、SDK下载
  下载方法可以看下面的链接:链接
  由于之前有M61和wb2搭建环境的经验,想必已经有很多人在电脑上面装了git了吧我们只需要在一个空的文件夹里面点击右键,然后点击这个
1.png

  再然后输入这个:git clone https://gitee.com/Ai-Thinker-Open/STM32F103-BU0x_SDK.git 回车即可
2.png

  等待大概10秒钟左右即可。
  这边建议下载完之后复制一个,因为一个要接收一个要发送这一次我们的测试。


  ps:不要使用百度云的SDK那里面的没有用。
二、激活例程
  这一步的话建议观看这个教程:教程
  由于我们需要写睡眠和读普通的读模式,观看教程的话,建议直接观看tx_simple_sleep和simple_rx。
  直接编两个工程烧录的话就是向教程一样的现象。
三、修改例程
  还记得我们标题是什么吗?没错,我们的标题是使用按键进行唤醒,因此我们需要对tx_simple_sleep程序修改
3.png


    函数路径如上图,在这里我们直接翻到最下面上面的全是初始化函数,无需修改。
  1.    /* Loop forever sending frames periodically. */
  2.     while(1)
  3.     {
  4.         /* 写入待发送数据到DW3000准备发送. (Write frame data to DW IC and prepare transmission. See NOTE 3 below.) */
  5.         dwt_writetxdata(FRAME_LENGTH-FCS_LEN, tx_msg, 0); /* Zero offset in TX buffer. */

  6.         /* 设置发送数据长度 (In this example since the length of the transmitted frame does not change,
  7.          * nor the other parameters of the dwt_writetxfctrl function, the
  8.          * dwt_writetxfctrl call could be outside the main while(1) loop.)
  9.          */
  10.         dwt_writetxfctrl(FRAME_LENGTH, 0, 0); /* Zero offset in TX buffer, no ranging. */

  11.         /* 立即发送. (Start transmission.) */
  12.         dwt_starttx(DWT_START_TX_IMMEDIATE);
  13.         /* 查询DW3000是否发送成功. (Poll DW IC until TX frame sent event set. See NOTE 4 below.
  14.          * 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

  15.          * function to access it.) */
  16.         while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS_BIT_MASK))
  17.         { };

  18.         /* 清除发送事件. (Clear TX frame sent event.) */
  19.         dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS_BIT_MASK);

  20.         _dbg_printf((unsigned char *)"发送成功\n");

  21.         /* 休眠TX_DELAY_MS. (Execute a delay between transmissions.) */
  22.         Sleep(TX_DELAY_MS);

  23.         /* 标志位Seq++处理. (Increment the blink frame sequence number (modulo 256).) */
  24.         tx_msg[BLINK_FRAME_SN_IDX]++;
  25.     }
复制代码

   在这里,可以直接看到进入休眠模式使用这个函数dwt_entersleep(DWT_DW_IDLE)。我们需要使用按键来进行控制的话只需在这里我们初始化一个I/O口即。
  1. void tx_timed_sleep_GPIO_INIT()
  2. {
  3.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  4.         GPIO_InitTypeDef GPIO_Init_structure;
  5.         GPIO_Init_structure.GPIO_Mode=GPIO_Mode_IPU;
  6.         GPIO_Init_structure.GPIO_Pin=GPIO_Pin_8;
  7.         GPIO_Init_structure.GPIO_Speed=GPIO_Speed_50MHz;
  8.         GPIO_Init(GPIOB,&GPIO_Init_structure);
  9. }


  10. /**
  11. * Application entry point.
  12. */
  13. int tx_timed_sleep(void)
  14. {
  15.     uint16_t lp_osc_freq, sleep_cnt;
  16.                 tx_timed_sleep_GPIO_INIT();
  17.     /* 串口输出应用名称. Display application name on LCD. */
  18.     _dbg_printf((unsigned char *)APP_NAME);

  19.     /* 配置SPI快速率. Configure SPI rate, DW3000 supports up to 38 MHz */
  20.     port_set_dw_ic_spi_fastrate();

  21.     /* 硬复位DW3000模块. Reset DW IC */
  22.     reset_DWIC(); /* Target specific drive of RSTn line into DW IC low for a period. */

  23.     Sleep(2); // Time needed for DW3000 to start up (transition from INIT_RC to IDLE_RC)

  24.     /* 检查DW3000模块是否处于IDLE_RC */
  25.     while (!dwt_checkidlerc()) /* Need to make sure DW IC is in IDLE_RC before proceeding */
  26.     { };

  27.     /* 初始化DW3000模块 */
  28.     if (dwt_initialise(DWT_DW_INIT) == DWT_ERROR)
  29.     {
  30.         _dbg_printf((unsigned char *)"INIT FAILED     ");
  31.         while (1)
  32.         { };
  33.     }

  34.     /* 清除SPI就绪中断. Clearing the SPI ready interrupt*/
  35.     dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RCINIT_BIT_MASK | SYS_STATUS_SPIRDY_BIT_MASK);

  36.     /* 配置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*/
  37. //    port_set_dwic_isr(dwt_isr);

  38.     /* 校准和配置UWB计数. Calibrate and configure sleep count. */
  39.     lp_osc_freq = XTAL_FREQ_HZ / dwt_calibratesleepcnt();
  40.     sleep_cnt = ((SLEEP_TIME_MS * ((uint32_t) lp_osc_freq)) / 1000) >> 12;
  41.     //sleep_cnt = 0x06; // 1 step is ~ 175ms, 6 ~= 1s
  42.     dwt_configuresleepcnt(sleep_cnt);

  43.     /* 配置DW3000信道参数. Configure DW IC. See NOTE 6 below. */
  44.     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 */
  45.     {
  46.         _dbg_printf((unsigned char *)"CONFIG FAILED     ");
  47.         while (1)
  48.         { };
  49.     }

  50.     /* 配置DW3000发送频谱参数. Configure the TX spectrum parameters (power, PG delay and PG count) */
  51.     dwt_configuretxrf(&txconfig_options);

  52.     /* 配置DW3000发送频谱参数. Configure sleep and wake-up parameters. */
  53.     dwt_configuresleep(DWT_CONFIG, DWT_PRES_SLEEP | DWT_WAKE_CSN | DWT_SLEEP | DWT_SLP_EN);

  54.     /* 注册中断回调函数. Register the call-backs (only SPI ready callback is used). */
  55.     dwt_setcallbacks(NULL, NULL, NULL, NULL, NULL, &spi_ready_cb);

  56.     port_EnableEXT_IRQ();

  57.     _dbg_printf("配置成功\n");

  58.     /* Loop forever sending frames periodically. */
  59.     while (1)
  60.     {

  61.         /* DW3000进入休眠模式,唤醒后进入IDLE. Put DW IC to sleep. Go to IDLE state after wakeup*/
  62.         dwt_entersleep(DWT_DW_IDLE);

  63.         sleeping = 1;

  64.         /* In this example, there is nothing to do to wake the DW IC up as it is handled by the sleep timer. */
  65.         while (sleeping)
  66.         {Sleep(1);}; /* Wait for device to wake up */

  67.         /* 增加延时.必要*/
  68.         Sleep(5);
  69.                                 if(KEY==0)
  70.                                 {
  71.                                        
  72.         _dbg_printf((unsigned char *)"唤醒成功:%04x\n", dwt_readdevid());

  73.         /* 唤醒时恢复所有配置. Restore the required configurations on wake */
  74.         dwt_restoreconfig();

  75.         /* Increment the blink frame sequence number (modulo 256). */
  76.         tx_msg[BLINK_FRAME_SN_IDX]++;
  77.                                        
  78.                                        
  79.                                         /* 写入待发送数据到DW3000准备发送,并设置发送长度. Write frame data to DW IC and prepare transmission. See NOTE 4 below. */
  80.         dwt_writetxdata(sizeof(tx_msg), tx_msg, 0); /* Zero offset in TX buffer. */
  81.         dwt_writetxfctrl(sizeof(tx_msg), 0, 0); /* Zero offset in TX buffer, no ranging. */

  82.         /* 立即发送. Start transmission. */
  83.         dwt_starttx(DWT_START_TX_IMMEDIATE);

  84.         /* 查询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
  85.          * frame sent, but instead simply wait sufficient time for the DW IC to wake up again before we loop back to send another frame.
  86.          * 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
  87.          * prevent the DW IC from sleeping. */

  88.         /* Poll DW IC until TX frame sent event set. See NOTE 7 below.
  89.          * 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
  90.          * function to access it.*/
  91.         while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS_BIT_MASK))
  92.         {};

  93.         /* 清除发送完成事件. Clear TX frame sent event. */
  94.         dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS_BIT_MASK);
  95.         
  96.                                 }
  97.     }
  98. }
复制代码

  代码如上。

四、实验现象

当我们将pb9直接接地时:

4.png

当我们将pb9不接地时(接收端和发送端无输出):

5.png














──── 0人觉得很赞 ────

使用道具 举报

您需要登录后才可以回帖 立即登录
高级模式
返回
统计信息
  • 会员数: 28320 个
  • 话题数: 40323 篇