From e8e11e82bd02e63ebc167b69fc3e585a99d78276 Mon Sep 17 00:00:00 2001 From: guanjiao ren <guanjiao.ren@ninebot.com> Date: 星期五, 18 五月 2018 23:10:57 +0800 Subject: [PATCH] 蜂鸣器、led、spi、systick调试完成 --- 源码/核心板/Src/main.c | 125 ++++++++++++++++++++++++++--------------- 1 files changed, 78 insertions(+), 47 deletions(-) diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" index 20697f8..8d90fc3 100644 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" +++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" @@ -21,9 +21,12 @@ #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" @@ -135,10 +138,10 @@ *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) { @@ -188,17 +191,17 @@ 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}; @@ -207,21 +210,48 @@ 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 @@ -250,7 +280,7 @@ 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标签) @@ -316,15 +346,15 @@ 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; @@ -343,8 +373,9 @@ /* 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 @@ -473,17 +504,17 @@ 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; -- Gitblit v1.9.3