8 Commits

Author SHA1 Message Date
e5f3bf900a for debug 2025-01-20 16:32:12 +08:00
3f75e99553 发布0.1.0版本 2025-01-20 15:27:53 +08:00
f67baed8c5 Revert "test"
This reverts commit f8a41af344.
2025-01-20 15:25:56 +08:00
ac74c30923 Revert "update"
This reverts commit cc4d898114.
2025-01-20 15:25:51 +08:00
9f615ba3a3 Revert "更改协议处理部分,但是串口没反应?"
This reverts commit 705cb68764.
2025-01-20 15:25:48 +08:00
705cb68764 更改协议处理部分,但是串口没反应? 2025-01-20 01:30:18 +08:00
cc4d898114 update 2025-01-17 17:29:17 +08:00
f8a41af344 test 2025-01-16 00:31:37 +08:00
10 changed files with 91 additions and 84 deletions

View File

@@ -6,7 +6,7 @@ set(PROJECT_NAME "XLSW_3DP_US-IR")
project(${PROJECT_NAME})
set(VERSION_MAJOR 0)
set(VERSION_MINOR 2)
set(VERSION_MINOR 1)
set(VERSION_PATCH 0)
set(VERSION "V${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d")

View File

@@ -56,6 +56,24 @@
- 数据长度错误回包
- `B5 F4 03 65 72 72 40`, 有效数据为 `err`
### 2. 读取数据时间间隔
### 2. 读取液面红外温度传感器数据
- 推荐数据时间间隔至少为50ms
- 发送M2指令读取液面红外温度传感器数据。
- `D5 04 02 4D 32 85`
- 电涡流传感器模块温度补偿回复数据
- `B5 F0 02 00 BD AF`, 有效数据为 `0x00BD`,转换为`189`(单位为摄氏度*10温度为18.9℃
- `B5 F0 02 01 0C FF`, 有效数据为 `0x010C`,转换为`268`(单位为摄氏度*10温度为26.8℃
- 错误命令M3指令回包
- `B5 F0 03 65 72 72 3C`,有效数据为 `err`
- CRC错误回包
- `B5 F1 03 65 72 72 3D`, 有效数据为 `err`
- 包头错误回包
- `B5 F2 03 65 72 72 3E`, 有效数据为 `err`
- 类型错误回包
- `B5 F3 03 65 72 72 3F`, 有效数据为 `err`
- 数据长度错误回包
- `B5 F4 03 65 72 72 40`, 有效数据为 `err`
### 3. 读取数据时间间隔
- 推荐数据时间间隔至少为1s

View File

@@ -3,29 +3,7 @@
| **版本号** | **修改内容** | **日期** | **修改人** |
|:-------:|:--------:|:----------:|:-------:|
| v0.0.1 | 非稳定版本 | 2025-01-20 | Hulk |
| v0.2.0 | 硬件修改RS485接口芯片为SP3485非自动换向 | 2025-06-03 | Hulk |
## US&IR传感器模块通信协议
通信协议:[US&IR通信协议](CommunicationProtocol.md)
---
## 300K超声换能头工作流程
### **1. 超声波发送**
通过TIMER13定时器配置为输出300KHz的PWM信号驱动超声换能头发射超声波。TIMER13的输出模式为PWM1模式同时用TIMER13的更新中断触发次数进行计数。
最终使驱动引脚发送300KHz 50%占空比 5个周期的PWM信号。同时开启计时。
### **2. 超声波计时**
通过TIMER15定时器配置为us计时器并传入预先测得的超声消隐延时值例如230us。该定时器用于在发送超声波后延时一段时间确保接收通道不会受到发射信号的干扰。但是暂不开启该定时器。
同时在TIMER15的更新中断中断服务函数中开启外部输入中断用以检测超声回波并开启TIMER16定时器。
TIMER16定时器输入捕获用于计算超声回波的时间。
通过前面的消隐时间与回波时间的和值,计算出实际的距离值。
### **3. 距离值输出**
\[
\frac{\frac{(\verb|TIME_CORRECTION_US| + \verb|us_value|)\times 340\,\text{m/s}}{10^{3} \ast 10^{3}} }{2}
\]
其中,`TIME_CORRECTION_US`为超声消隐延时定时器的初始值,`us_value`为外部输入中断计数值。

View File

@@ -12,7 +12,20 @@
// #define POWER_SUPPLY_12V
#define POWER_SUPPLY_24V
// #define DEBUG_VOFA_TOOL
// #define GD32E230F4
// #define GD32E230F8
/******************************************************************************/
#ifdef GD32E230F8
#define USART_RCU RCU_USART1
#define USART_PHY USART1
#define USART_PHY_IRQ USART1_IRQn
#else
#define USART_RCU RCU_USART0
#define USART_PHY USART0
#define USART_PHY_IRQ USART0_IRQn
#endif
/******************************************************************************/
@@ -28,7 +41,6 @@
#error "Please define either POWER_SUPPLY_12V or POWER_SUPPLY_24V"
#endif
/******************************************************************************/
#define I2C_GPIO_RCU RCU_GPIOF
@@ -43,15 +55,16 @@
/******************************************************************************/
#define USART_GPIO_RCU RCU_GPIOA
#define USART_RCU RCU_USART0
// #define USART_RCU RCU_USART0
#define USART_GPIO_PORT GPIOA
#define USART_GPIO_AF GPIO_AF_1
#define USART_TX_PIN GPIO_PIN_2
#define USART_RX_PIN GPIO_PIN_3
#define USART_PHY USART0
// #define USART_PHY USART0
#define USART_PHY_BAUDRATE 115200U
// #define USART_PHY_IRQ USART0_IRQn
#define RS485_EN_PORT GPIOA
#define RS485_EN_PIN GPIO_PIN_1
#define RS485_EN_PIN GPIO_PIN_4
/******************************************************************************/

View File

@@ -8,6 +8,8 @@
#include "gd32e23x.h"
#include "board_config.h"
void usart_config(void);
void rs485_config(void);
#endif //USART_H

View File

@@ -35,5 +35,5 @@ void led_blink_config(void)
timer_enable(LED_BLINK_TIMER);
nvic_irq_enable(LED_BLINK_IRQ, 3U);
nvic_irq_enable(LED_BLINK_IRQ, 2);
}

View File

@@ -25,25 +25,26 @@ int main(void)
/* configure LED */
led_blink_config();
/* configure FWDGT */
// watchdog_init();
watchdog_init();
// #ifdef SOFTWARE_IIC
// soft_i2c_config();
// #else
// i2c_config();
// #endif
#ifdef SOFTWARE_IIC
soft_i2c_config();
#else
i2c_config();
#endif
printf("system start!\r\n");
ultrasonic_config();
while(1){
// gd60914_get_object_tempture();
gd60914_get_object_tempture();
delay_ms(50);
ultrasonic_pwm_out_cycles(ULTRASONIC_TX_CYCLES);
// watchdog_reload();
watchdog_reload();
}
}

View File

@@ -21,12 +21,12 @@ void process_command(uint8_t *cmd, size_t length) {
sprintf(combined_str, "%c%c", cmd[3], cmd[4]);
if (strcmp(combined_str, "M1") == 0) {
ultrasonic_distance_report();
// } else if (strcmp(combined_str, "M2") == 0) {
// gd60914_tempture_report();
// } else if (strcmp(combined_str, "M3") == 0)
// {
// printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
// fwdgt_reset_mcu();
} else if (strcmp(combined_str, "M2") == 0) {
gd60914_tempture_report();
} else if (strcmp(combined_str, "M3") == 0)
{
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
fwdgt_reset_mcu();
} else {
printf("%c%c%c%c%c%c%c", 0xB5, 0xF0, 0x03, 0x65, 0x72, 0x72, 0x3C);
return;
@@ -110,9 +110,6 @@ void ultrasonic_distance_report(void) {
distance_uint16 = ultrasonic_calc_distance();
#ifdef DEBUG_VOFA_TOOL
printf("%d\n", distance_uint16);
#else
package_data[0] = (distance_uint16 >> 8) & 0xFF;
package_data[1] = distance_uint16 & 0xFF;
@@ -123,5 +120,4 @@ void ultrasonic_distance_report(void) {
printf("%c%c%c", package_header[0], package_header[1], package_header[2]);
printf("%c%c", package_data[0], package_data[1]);
printf("%c", calculate_crc(combined_data, 6));
#endif
}

View File

@@ -140,7 +140,7 @@ void ultrasonic_config(void) {
}
uint16_t ultrasonic_calc_distance(void) {
// while (!ultrasonicMeasurementDone);
while (!ultrasonicMeasurementDone);
// uint32_t us_value = timer_channel_capture_value_register_read(US_ECHO_TIMER, US_ECHO_CH);
uint16_t distance = (TIME_CORRECTION_US + g_capture_value) * 17;
/*

View File

@@ -4,6 +4,34 @@
#include "usart.h"
/**
* @brief configure the USART
* @param none
* @retval none
*/
void usart_config(void)
{
rcu_periph_clock_enable(USART_GPIO_RCU);
rcu_periph_clock_enable(USART_RCU);
gpio_af_set(USART_GPIO_PORT, USART_GPIO_AF, USART_RX_PIN);
gpio_af_set(USART_GPIO_PORT, USART_GPIO_AF, USART_TX_PIN);
gpio_mode_set(USART_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART_RX_PIN);
gpio_output_options_set(USART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, USART_RX_PIN);
gpio_mode_set(USART_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART_TX_PIN);
gpio_output_options_set(USART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, USART_TX_PIN);
usart_deinit(USART_PHY);
usart_baudrate_set(USART_PHY, USART_PHY_BAUDRATE);
usart_receive_config(USART_PHY, USART_RECEIVE_ENABLE);
usart_transmit_config(USART_PHY, USART_TRANSMIT_ENABLE);
nvic_irq_enable(USART_PHY_IRQ, 0);
usart_interrupt_enable(USART_PHY, USART_INT_RBNE);
usart_interrupt_enable(USART_PHY, USART_INT_IDLE);
usart_enable(USART_PHY);
}
/**
* @brief configure the RS485(MAX13487) driver
* @param none
@@ -11,39 +39,10 @@
*/
void rs485_config(void)
{
rcu_periph_clock_enable(USART_GPIO_RCU);
rcu_periph_clock_enable(USART_RCU);
usart_config();
gpio_af_set(USART_GPIO_PORT, GPIO_AF_1, USART_TX_PIN | USART_RX_PIN | RS485_EN_PIN);
gpio_mode_set(RS485_EN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, RS485_EN_PIN);
gpio_output_options_set(RS485_EN_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RS485_EN_PIN);
/* configure USART Tx&Rx as alternate function push-pull */
gpio_mode_set(USART_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART_TX_PIN | USART_RX_PIN);
gpio_output_options_set(USART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, USART_TX_PIN | USART_RX_PIN);
/* configure RS485 EN Pin */
gpio_mode_set(USART_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, RS485_EN_PIN);
gpio_output_options_set(USART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RS485_EN_PIN);
// gpio_bit_write(RS485_GPIO_PORT, RS485_EN_PIN, SET);
/* USART configure */
usart_deinit(USART_PHY);
usart_baudrate_set(USART_PHY, USART_PHY_BAUDRATE);
// usart_parity_config(RS485_PHY, USART_PM_NONE);
// usart_word_length_set(RS485_PHY, USART_WL_8BIT);
// usart_stop_bit_set(RS485_PHY, USART_STB_1BIT);
usart_receive_config(USART_PHY, USART_RECEIVE_ENABLE);
usart_transmit_config(USART_PHY, USART_TRANSMIT_ENABLE);
usart_driver_assertime_config(USART_PHY, 0x01);
usart_driver_deassertime_config(USART_PHY, 0x01);
// usart_depolarity_config(USART0, USART_DEP_HIGH);
// usart_depolarity_config(USART0, USART_DEP_LOW);
usart_rs485_driver_enable(USART_PHY);
usart_enable(USART_PHY);
nvic_irq_enable(USART0_IRQn, 0);
usart_interrupt_enable(USART_PHY, USART_INT_RBNE);
usart_interrupt_enable(USART_PHY, USART_INT_IDLE);
gpio_bit_write(RS485_EN_PORT, RS485_EN_PIN, SET); //auto dircetion control
}