diff --git a/BC3S.ATWP b/BC3S.ATWP
index 329b26c..281545c 100644
--- a/BC3S.ATWP
+++ b/BC3S.ATWP
@@ -53,7 +53,7 @@
0;0;0
0;0;0
0;0;0
- 0;0;0
+ 1;0;0
0;0;0
0;0;0
0;0;0
@@ -67,7 +67,6 @@
-
diff --git a/app/by_measure.c b/app/by_measure.c
new file mode 100644
index 0000000..14aa032
--- /dev/null
+++ b/app/by_measure.c
@@ -0,0 +1,37 @@
+#include "by_measure.h"
+
+#include "by_debug.h"
+#include "vl53l0x_wmd_api.h"
+
+void by_measure_init(void)
+{
+ VL53L0X_Init();
+}
+
+void by_measure_run(void)
+{
+ float x = VL53L0X_GetValue();
+ float distance = x;
+ static float distance_last = 0;
+
+ if (x < 270) {
+ distance = x - 80.0f;
+ } else if (x < 330) {
+ distance = 2.0755f * x - 368.85f;
+ }
+
+ // 错误值
+ if (distance <= 20 || distance > 330) {
+ distance = distance_last;
+ }
+
+ // if (distance <= 20) {
+ // distance = distance_last;
+ // } else if (distance > 330) {
+ // distance = 330;
+ // }
+
+ distance_last = distance;
+
+ LOGI("distance:%f", distance);
+}
\ No newline at end of file
diff --git a/app/by_measure.h b/app/by_measure.h
new file mode 100644
index 0000000..94470aa
--- /dev/null
+++ b/app/by_measure.h
@@ -0,0 +1,8 @@
+#ifndef _BY_MEASURE_H__
+#define _BY_MEASURE_H__
+
+
+void by_measure_init(void);
+void by_measure_run(void);
+
+#endif
\ No newline at end of file
diff --git a/project/inc/at32f415_int.h b/project/inc/at32f415_int.h
index 42b29a9..5540793 100644
--- a/project/inc/at32f415_int.h
+++ b/project/inc/at32f415_int.h
@@ -65,6 +65,7 @@ void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
+void CAN1_RX0_IRQHandler(void);
void TMR4_GLOBAL_IRQHandler(void);
/* add user code begin exported functions */
diff --git a/project/src/at32f415_int.c b/project/src/at32f415_int.c
index 7ad60ff..e20a2f3 100644
--- a/project/src/at32f415_int.c
+++ b/project/src/at32f415_int.c
@@ -204,6 +204,25 @@ void PendSV_Handler(void)
/* add user code end PendSV_IRQ 1 */
}
+/**
+ * @brief this function handles CAN1 RX0 handler.
+ * @param none
+ * @retval none
+ */
+void CAN1_RX0_IRQHandler(void)
+{
+ /* add user code begin CAN1_RX0_IRQ 0 */
+ if (SET == can_interrupt_flag_get(CAN1, CAN_RF0MN_FLAG)){
+ can_rx_message_type can_rx_message;
+ can_message_receive(CAN1, CAN_RX_FIFO0, &can_rx_message);
+ can_flag_clear(CAN1, CAN_RF0MN_FLAG);
+ }
+ /* add user code end CAN1_RX0_IRQ 0 */
+ /* add user code begin CAN1_RX0_IRQ 1 */
+
+ /* add user code end CAN1_RX0_IRQ 1 */
+}
+
/**
* @brief this function handles TMR4 handler.
* @param none
diff --git a/project/src/at32f415_wk_config.c b/project/src/at32f415_wk_config.c
index 7de44f2..0c67ea5 100644
--- a/project/src/at32f415_wk_config.c
+++ b/project/src/at32f415_wk_config.c
@@ -189,6 +189,7 @@ void wk_nvic_config(void)
{
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
+ nvic_irq_enable(CAN1_RX0_IRQn, 0, 0);
nvic_irq_enable(TMR4_GLOBAL_IRQn, 0, 0);
}
@@ -224,14 +225,7 @@ void wk_gpio_config(void)
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
- gpio_init_struct.gpio_pins = GPIO_PINS_6;
- gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- gpio_init(GPIOB, &gpio_init_struct);
-
- gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
- gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
- gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
- gpio_init_struct.gpio_pins = GPIO_PINS_7;
+ gpio_init_struct.gpio_pins = GPIO_PINS_6 | GPIO_PINS_7;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct);
@@ -457,8 +451,16 @@ void wk_can1_init(void)
can_filter_init(CAN1, &can_filter_init_struct);
- /* add user code begin can1_init 2 */
+ /**
+ * Users need to configure CAN1 interrupt functions according to the actual application.
+ * 1. Call the below function to enable the corresponding CAN1 interrupt.
+ * --can_interrupt_enable(...)
+ * 2. Add the user's interrupt handler code into the below function in the at32f415_int.c file.
+ * --void CAN1_RX0_IRQHandler(void)
+ */
+ /* add user code begin can1_init 2 */
+ can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE);
/* add user code end can1_init 2 */
}
diff --git a/project/src/main.c b/project/src/main.c
index 1ff56c0..6276c2b 100644
--- a/project/src/main.c
+++ b/project/src/main.c
@@ -29,9 +29,9 @@
/* private includes ----------------------------------------------------------*/
/* add user code begin private includes */
-#include "vl53l0x_wmd_api.h"
#include "by_debug.h"
#include "by_led.h"
+#include "by_measure.h"
/* add user code end private includes */
/* private typedef -----------------------------------------------------------*/
@@ -105,25 +105,15 @@ int main(void)
/* add user code begin 2 */
delay_init();
by_led_set(10);
- delay_ms(1000);
- VL53L0X_Init();
- delay_ms(1000);
+ by_measure_init();
by_led_set(0);
/* add user code end 2 */
while (1) {
/* add user code begin 3 */
- // gpio_bits_write(GPIOB, GPIO_PINS_8, !gpio_output_data_bit_read(GPIOB, GPIO_PINS_8));
- // gpio_bits_set(GPIOA, GPIO_PINS_4);
- // delay_ms(250);
- // gpio_bits_reset(GPIOA, GPIO_PINS_4);
- // delay_ms(250);
- by_led_set(40);
- delay_ms(10);
- LOGI("distance:%d", VL53L0X_GetValue());
- by_led_set(0);
- delay_ms(10);
+ gpio_bits_write(GPIOA, GPIO_PINS_4, !gpio_output_data_bit_read(GPIOA, GPIO_PINS_4));
+ by_measure_run();
/* add user code end 3 */
}
}