| | |
| | | * @file main.c |
| | | * @brief Double-sided two-way ranging (DS TWR) initiator example code |
| | | * |
| | | * |
| | | * |
| | | * |
| | | * @attention |
| | | * |
| | |
| | | |
| | | static dwt_config_t config = { |
| | | #ifdef _UWB_4G |
| | | 2, /* Channel number. */ |
| | | 2, /* Channel number. */ |
| | | #else |
| | | 5, |
| | | #endif |
| | | DWT_PRF_64M, /* Pulse repetition frequency. */ |
| | | DWT_PLEN_128, /* Preamble length. */ |
| | | 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, /* Use non-standard SFD (Boolean) */ |
| | | DWT_BR_6M8, /* Data rate. */ |
| | | DWT_PHRMODE_STD, /* PHY header mode. */ |
| | | (129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ |
| | | DWT_PRF_64M, /* Pulse repetition frequency. */ |
| | | DWT_PLEN_128, /* Preamble length. */ |
| | | 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, /* Use non-standard SFD (Boolean) */ |
| | | DWT_BR_6M8, /* Data rate. */ |
| | | DWT_PHRMODE_STD, /* PHY header mode. */ |
| | | (129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ |
| | | }; |
| | | |
| | | uint32_t uwbid=0; |
| | | void Dw1000_Init(void) |
| | | { |
| | | /* Reset and initialise DW1000. |
| | | /* Reset and initialise DW1000. |
| | | * For initialisation, DW1000 clocks must be temporarily set to crystal speed. After initialisation SPI rate can be increased for optimum |
| | | * performance. */ |
| | | Reset_DW1000();//重启DW1000 /* Target specific drive of RSTn line into DW1000 low for a period. */ |
| | | Spi_ChangePrescaler(SPIx_PRESCALER_SLOW); //设置为快速模式 |
| | | Spi_ChangePrescaler(SPIx_PRESCALER_SLOW); //设置为快速模式 |
| | | dwt_initialise(DWT_LOADUCODE);//初始化DW1000 |
| | | Spi_ChangePrescaler(SPIx_PRESCALER_FAST); //设置为快速模式 |
| | | Spi_ChangePrescaler(SPIx_PRESCALER_FAST); //设置为快速模式 |
| | | |
| | | /* Configure DW1000. See NOTE 6 below. */ |
| | | dwt_configure(&config);//配置DW1000 |
| | | |
| | | |
| | | // dwt_setinterrupt( DWT_INT_RFCG | (DWT_INT_ARFE | DWT_INT_RFSL | DWT_INT_SFDT | DWT_INT_RPHE | DWT_INT_RFCE | DWT_INT_RFTO | DWT_INT_RXPTO), 1); |
| | | |
| | | |
| | | |
| | | /* Apply default antenna delay value. See NOTE 1 below. */ |
| | | dwt_setrxantennadelay(RX_ANT_DLY); //设置接收天线延迟 |
| | | dwt_settxantennadelay(TX_ANT_DLY); //设置发射天线延迟 |
| | | |
| | | |
| | | // dwt_setrxtimeout(1000);//设定接收超时时间,0位没有超时时间 |
| | | // dwt_rxenable(0);//打开接收 |
| | | // uwbid=dwt_readdevid(); |
| | | /* Set expected response's delay and timeout. See NOTE 4 and 5 below. |
| | | * As this example only handles one incoming frame with always the same delay and timeout, those values can be set here once for all. */ |
| | | //设置接收超时时间 |
| | | //设置接收超时时间 |
| | | } |
| | | uint16_t Checksum_u16(uint8_t* pdata, uint32_t len) |
| | | uint16_t Checksum_u16(uint8_t* pdata, uint32_t len) |
| | | { |
| | | uint16_t sum = 0; |
| | | uint32_t i; |
| | |
| | | extern uint8_t g_pairstart; |
| | | void tag_sleep_configuraion(void) |
| | | { |
| | | dwt_configuresleep(0x940, 0x7); |
| | | dwt_entersleep(); |
| | | dwt_configuresleep(0x940, 0x7); |
| | | dwt_entersleep(); |
| | | } |
| | | u32 id; |
| | | void UWB_Wkup(void) |
| | | { |
| | | |
| | | |
| | | SPIx_CS_GPIO->BRR = SPIx_CS; |
| | | delay_us(600); |
| | | SPIx_CS_GPIO->BSRR = SPIx_CS; |
| | | id = dwt_readdevid() ; |
| | | while (0xDECA0130!=id) |
| | | while (0xDECA0130!=id) |
| | | { |
| | | u8 iderror_count = 0; |
| | | id = dwt_readdevid() ; |
| | | if(iderror_count++>100) |
| | | { |
| | | printf("UWB芯片ID错误\r\n"); |
| | | printf("UWB芯片ID错误\r\n"); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |