| | |
| | | #include <stdio.h> |
| | | #include "deca_device_api.h" |
| | | #include "deca_regs.h" |
| | | #include "deca_sleep.h" |
| | | #include "lcd.h" |
| | | #include "port.h" |
| | | #include "Rcc_Nvic_Systick.h" |
| | | #include "Usart.h" |
| | | #include "Spi.h" |
| | | #include "dw_driver.h" |
| | | #include "led.h" |
| | | #include "beep.h" |
| | | |
| | | /* Example application name and version to display on LCD screen. */ |
| | | #define APP_NAME "DS TWR INIT v1.1" |
| | |
| | | *ts += ts_field[i] << (i * 8); |
| | | } |
| | | } |
| | | void GPIO_Toggle(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) |
| | | { |
| | | GPIO_WriteBit(GPIOx, GPIO_Pin, (BitAction)!GPIO_ReadOutputDataBit(GPIOx, GPIO_Pin)); |
| | | } |
| | | //void GPIO_Toggle(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) |
| | | //{ |
| | | // GPIO_WriteBit(GPIOx, GPIO_Pin, (BitAction)!GPIO_ReadOutputDataBit(GPIOx, GPIO_Pin)); |
| | | //} |
| | | int fputc(int ch, FILE *f) |
| | | |
| | | { |
| | |
| | | sum = ~sum; |
| | | return sum; |
| | | } |
| | | void LED_blink(void) |
| | | { |
| | | uint8_t ii; |
| | | for (ii = 0; ii < 10; ii++) |
| | | { |
| | | GPIO_Toggle(GPIOA, LED_PIN); |
| | | deca_sleep(100); |
| | | } |
| | | } |
| | | extern volatile unsigned long time32_reset; |
| | | extern uint8_t Work_Mode; |
| | | //void LED_blink(void) |
| | | //{ |
| | | // uint8_t ii; |
| | | // for (ii = 0; ii < 10; ii++) |
| | | // { |
| | | // GPIO_Toggle(GPIOA, LED_PIN); |
| | | // deca_sleep(100); |
| | | // } |
| | | //} |
| | | //extern volatile unsigned long time32_reset; |
| | | uint8_t Work_Mode = 1; |
| | | uint32 frame_len; |
| | | uint8_t send[9]; |
| | | char dist_str[16] = {0}; |
| | |
| | | uint8_t TAG_ID, ANCHOR_ID, jumptime = 0; |
| | | uint32_t rec_dist, hex_dist; |
| | | uint16_t check; |
| | | |
| | | uint8_t tempaaaa[5] = {0}; |
| | | |
| | | void Device_Init(void) |
| | | { |
| | | Rcc_Init(); |
| | | Nvic_Init(); |
| | | Systick_Init(); |
| | | Led_Init(); |
| | | Beep_Init(); |
| | | DW_GPIO_Init(); |
| | | Usart_Init(); |
| | | Spi_Init(); |
| | | |
| | | GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); |
| | | while(1) |
| | | { |
| | | dwt_readsystime(tempaaaa); |
| | | delay_ms(500); |
| | | // dwt_readsystime(&tempb); |
| | | // delay_ms(500); |
| | | } |
| | | } |
| | | |
| | | int main(void) |
| | | { |
| | | RCC_ClocksTypeDef RCC_Clocks; /* Start with board specific hardware init. */ |
| | | peripherals_init();//åå§åå¤è®¾ |
| | | RCC_GetClocksFreq(&RCC_Clocks); |
| | | |
| | | Device_Init(); |
| | | // RCC_ClocksTypeDef RCC_Clocks; /* Start with board specific hardware init. */ |
| | | // peripherals_init();//åå§åå¤è®¾ |
| | | // RCC_GetClocksFreq(&RCC_Clocks); |
| | | /* Display application name on LCD. */ |
| | | // lcd_display_str(APP_NAME); |
| | | |
| | | /* 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_set_rate_low();//éä½SPIé¢ç |
| | | Reset_DW1000();//éå¯DW1000 /* Target specific drive of RSTn line into DW1000 low for a period. */ |
| | | // spi_set_rate_low();//éä½SPIé¢ç |
| | | dwt_initialise(DWT_LOADUCODE);//åå§åDW1000 |
| | | spi_set_rate_high();//åå¤SPIé¢ç |
| | | // spi_set_rate_high();//åå¤SPIé¢ç |
| | | Spi_ChangePrescaler(SPIx_PRESCALER_FAST); //è®¾ç½®ä¸ºå¿«éæ¨¡å¼ |
| | | |
| | | /* Configure DW1000. See NOTE 6 below. */ |
| | | dwt_configure(&config);//é
ç½®DW1000 |
| | |
| | | rx_resp_msg[5] = TAG_ID;//UWB RESPONSE å
æ°æ® |
| | | tx_final_msg[5] = TAG_ID;//UWB Fianl å
æ°æ® |
| | | /* Loop forever initiating ranging exchanges. */ |
| | | LED_blink(); |
| | | //LED_blink(); |
| | | if(!Work_Mode) //éæ©å鿍¡å¼ï¼TAGæ ç¾ï¼è¿æ¯æ¥æ¶æ¨¡å¼(ANCHORåºç«) |
| | | { |
| | | while (1) //å鿍¡å¼(TAGæ ç¾) |
| | |
| | | dwt_writetxfctrl(sizeof(tx_final_msg), 0);//设å®åéæ°æ®é¿åº¦ |
| | | dwt_starttx(DWT_START_TX_DELAYED);//设å®ä¸ºå»¶è¿åé |
| | | |
| | | if (GPIO_ReadInputDataBit(GPIOA, SW2) != RESET) //éè¿æ¨ç å¼å
³å¤ææ°æ®è¾åºæ ¼å¼ |
| | | { |
| | | dID = TAG_ID; |
| | | printf("TAG_ID: %2.0f ", dID); |
| | | dID = ANCHOR_ID; |
| | | printf("ANCHOR_ID: %2.0f ", dID); |
| | | printf("Distance: %5.0f cm\n", (double)dist[TAG_ID]); |
| | | } |
| | | else |
| | | // if (GPIO_ReadInputDataBit(GPIOA, SW2) != RESET) //éè¿æ¨ç å¼å
³å¤ææ°æ®è¾åºæ ¼å¼ |
| | | // { |
| | | // dID = TAG_ID; |
| | | // printf("TAG_ID: %2.0f ", dID); |
| | | // dID = ANCHOR_ID; |
| | | // printf("ANCHOR_ID: %2.0f ", dID); |
| | | // printf("Distance: %5.0f cm\n", (double)dist[TAG_ID]); |
| | | // } |
| | | // else |
| | | { |
| | | send[2] = ANCHOR_ID; |
| | | send[3] = TAG_ID; |
| | |
| | | |
| | | /* Increment frame sequence number after transmission of the final message (modulo 256). */ |
| | | frame_seq_nb++; |
| | | time32_reset = 0; |
| | | GPIO_Toggle(GPIOA, LED_PIN); //LEDéªç |
| | | // time32_reset = 0; |
| | | // GPIO_Toggle(GPIOA, LED_PIN); //LEDéªç |
| | | LED0_BLINK; |
| | | jumptime = 0; |
| | | } |
| | | else |
| | |
| | | |
| | | dis = dist2 * 100; //dis 为åä½ä¸ºcmçè·ç¦» |
| | | dist[TAG_ID] = LP(dis, TAG_ID); //LP 为ä½é滤波å¨ï¼è®©æ°æ®æ´ç¨³å® |
| | | time32_reset = 0; |
| | | GPIO_Toggle(GPIOA, LED_PIN); |
| | | if (GPIO_ReadInputDataBit(GPIOA, SW2) != RESET) //éè¿æ¨ç å¼å
³å¤ææ°æ®è¾åºæ ¼å¼ |
| | | { |
| | | dID = TAG_ID; |
| | | printf("TAG_ID: %2.0f ", dID); |
| | | dID = ANCHOR_ID; |
| | | printf("ANCHOR_ID: %2.0f ", dID); |
| | | printf("Distance: %5.0f cm\n", (double)dist[TAG_ID]); |
| | | } |
| | | else |
| | | // time32_reset = 0; |
| | | LED0_BLINK; |
| | | // if (GPIO_ReadInputDataBit(GPIOA, SW2) != RESET) //éè¿æ¨ç å¼å
³å¤ææ°æ®è¾åºæ ¼å¼ |
| | | // { |
| | | // dID = TAG_ID; |
| | | // printf("TAG_ID: %2.0f ", dID); |
| | | // dID = ANCHOR_ID; |
| | | // printf("ANCHOR_ID: %2.0f ", dID); |
| | | // printf("Distance: %5.0f cm\n", (double)dist[TAG_ID]); |
| | | // } |
| | | // else |
| | | { |
| | | send[2] = ANCHOR_ID; |
| | | send[3] = TAG_ID; |