From 997637efcff753e3c829b80d10b07747e64a364a Mon Sep 17 00:00:00 2001 From: yelvlab Date: Wed, 1 Jan 2025 02:10:03 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98=E7=89=88?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 3 +- inc/board_config.h | 56 ++++++++++++++- inc/gd32e23x_it.h | 2 +- inc/main.h | 1 + inc/rs485_protocol.h | 5 ++ inc/ultrasonic_analog.h | 43 +++++++++++ src/gd32e23x_it.c | 39 +++++++++- src/main.c | 13 +++- src/rs485_protocol.c | 44 +++++++++++- src/ultrasonic_analog.c | 154 ++++++++++++++++++++++++++++++++++++++++ 10 files changed, 350 insertions(+), 10 deletions(-) create mode 100644 inc/ultrasonic_analog.h create mode 100644 src/ultrasonic_analog.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 79bc5b4..ee44a95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ set(VERSION "V${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") string(TIMESTAMP CURRENT_DATE "%Y-%m-%d") # Options 1 -set(OPT1 "") +set(OPT1 "_[12V]") #set(OPT1 "_[SW_IIC]") # Options 2 @@ -40,6 +40,7 @@ set(TARGET_C_SRC ${CMAKE_SOURCE_DIR}/src/i2c.c ${CMAKE_SOURCE_DIR}/src/fwdgt.c ${CMAKE_SOURCE_DIR}/src/rs485_protocol.c + ${CMAKE_SOURCE_DIR}/src/ultrasonic_analog.c ) add_executable(${PROJECT_NAME} ${TARGET_C_SRC}) diff --git a/inc/board_config.h b/inc/board_config.h index c45a322..c50bd57 100644 --- a/inc/board_config.h +++ b/inc/board_config.h @@ -9,6 +9,24 @@ // #define DEBUG_VERBOES +#define POWER_SUPPLY_12V +// #define POWER_SUPPLY_24V + +/******************************************************************************/ + +#ifdef POWER_SUPPLY_12V +#define POWER_VOLTAGE "12V" +#define TIME_CORRECTION_US 250 +#define CAPTURE_VALUE_MAX 515 +#elif defined(POWER_SUPPLY_24V) +#define POWER_VOLTAGE "24V" +#define TIME_CORRECTION_US 230 +#define CAPTURE_VALUE_MAX 550 +#else + #error "Please define either POWER_SUPPLY_12V or POWER_SUPPLY_24V" +#endif + + /******************************************************************************/ #define I2C_GPIO_RCU RCU_GPIOF @@ -38,9 +56,41 @@ #define LED_PORT GPIOA #define LED_PIN GPIO_PIN_9 #define LED_RCU RCU_GPIOA -#define LED_BLINK_TIMER_RCU RCU_TIMER16 -#define LED_BLINK_TIMER TIMER16 -#define LED_BLINK_IRQ TIMER16_IRQn +#define LED_BLINK_TIMER_RCU RCU_TIMER5 +#define LED_BLINK_TIMER TIMER5 +#define LED_BLINK_IRQ TIMER5_IRQn + +/******************************************************************************/ + + +#define US_TX_GPIO_RCU RCU_GPIOB +#define US_TX_GPIO_PORT GPIOB +#define US_TX_PIN GPIO_PIN_1 +#define US_TX_GPIO_AF GPIO_AF_0 +#define US_TX_RCU RCU_TIMER13 +#define US_TX_TIMER TIMER13 +#define US_TX_CH TIMER_CH_0 + +/******************************************************************************/ + +#define US_TX_DELAY_RCU RCU_TIMER15 +#define US_TX_DELAY_TIMER TIMER15 + +/******************************************************************************/ + +#define US_RX_GPIO_RCU RCU_GPIOA +#define US_RX_EXTI_RCU RCU_CFGCMP +#define US_RX_GPIO_PORT GPIOA +#define US_RX_GPIO_PIN GPIO_PIN_0 +#define US_RX_EXTI_IRQ EXTI0_1_IRQn +#define US_RX_GPIO_EXTI EXTI_0 +#define US_RX_EXTI_LINE EXTI_SOURCE_PIN0 + +/******************************************************************************/ + +#define US_ECHO_RCU RCU_TIMER16 +#define US_ECHO_TIMER TIMER16 +#define US_ECHO_CH TIMER_CH_0 /******************************************************************************/ diff --git a/inc/gd32e23x_it.h b/inc/gd32e23x_it.h index 70a4747..6407cc5 100644 --- a/inc/gd32e23x_it.h +++ b/inc/gd32e23x_it.h @@ -55,6 +55,6 @@ void PendSV_Handler(void); /* this function handles SysTick exception */ void SysTick_Handler(void); -void TIMER16_IRQHandler(void); +void TIMER5_IRQHandler(void); #endif /* GD32E23X_IT_H */ diff --git a/inc/main.h b/inc/main.h index 22cd3d4..ebfdc0e 100644 --- a/inc/main.h +++ b/inc/main.h @@ -43,6 +43,7 @@ OF SUCH DAMAGE. #include "usart.h" #include "fwdgt.h" #include "board_config.h" +#include "ultrasonic_analog.h" #ifdef SOFTWARE_IIC #include "soft_i2c.h" diff --git a/inc/rs485_protocol.h b/inc/rs485_protocol.h index b358deb..b0d2702 100644 --- a/inc/rs485_protocol.h +++ b/inc/rs485_protocol.h @@ -14,6 +14,7 @@ #include #include #include +#include "ultrasonic_analog.h" /******************************************************************************/ @@ -48,4 +49,8 @@ validation_result_t validate_package_type(uint8_t* data); validation_result_t validate_data_length(uint8_t* data); + + +void ultrasonic_distance_report(void); + #endif //RS485_PROTOCOL_H diff --git a/inc/ultrasonic_analog.h b/inc/ultrasonic_analog.h new file mode 100644 index 0000000..d59ac3b --- /dev/null +++ b/inc/ultrasonic_analog.h @@ -0,0 +1,43 @@ +// +// Created by yelv1 on 24-12-31. +// + +#ifndef ULTRASONIC_ANALOG_H +#define ULTRASONIC_ANALOG_H + +#include "gd32e23x.h" +#include "systick.h" +#include "gd32e23x_libopt.h" +#include "board_config.h" +#include "usart.h" +#include "fwdgt.h" +#include +#include +#include +#include + +extern volatile bool ultrasonicMeasurementDone; + +/******************************************************************************/ + +#define ULTRASONIC_TX_CYCLES 0x05U +#define ULTRASONIC_TX_TIME 498 // (ms) + +/******************************************************************************/ + +void ultrasonic_gpio_config(void); + +void ultrasonic_pwm_out_cycles(const uint8_t cycles); + +void ultrasonic_transmit_delay(const uint16_t micro_second); + +void ultrasonic_rece_exti_config(void); + +void ultrasonic_echo_timer_config(void); + +void ultrasonic_config(void); + +uint32_t ultrasonic_calc_distance(void); + + +#endif //ULTRASONIC_ANALOG_H diff --git a/src/gd32e23x_it.c b/src/gd32e23x_it.c index 906adb9..a966685 100644 --- a/src/gd32e23x_it.c +++ b/src/gd32e23x_it.c @@ -34,6 +34,8 @@ OF SUCH DAMAGE. #include "gd32e23x_it.h" +__IO uint32_t g_capture_value; + /*! \brief this function handles NMI exception \param[in] none @@ -102,8 +104,7 @@ void SysTick_Handler(void) \param[out] none \retval none */ -void TIMER16_IRQHandler(void) -{ +void TIMER5_IRQHandler(void) { if (timer_interrupt_flag_get(LED_BLINK_TIMER, TIMER_INT_FLAG_UP) == SET) { timer_interrupt_flag_clear(LED_BLINK_TIMER, TIMER_INT_FLAG_UP); @@ -122,6 +123,40 @@ void TIMER16_IRQHandler(void) } } +/** + * @brief This function handles TIMER15 interrupt request. + * @param[in] none + * @param[out] none + * @retval None + */ +void TIMER15_IRQHandler(void) { + if (timer_interrupt_flag_get(US_TX_DELAY_TIMER, TIMER_INT_FLAG_UP) == SET) + { + timer_interrupt_flag_clear(US_TX_DELAY_TIMER, TIMER_INT_FLAG_UP); + exti_interrupt_enable(US_RX_GPIO_EXTI); // turn on hardware external input interrupt + timer_counter_value_config(US_ECHO_TIMER, 0); + timer_enable(US_ECHO_TIMER); // turn on timer to calculate the first ultrasonic echo time + timer_disable(US_TX_DELAY_TIMER); + } +} + +/** + * @brief This function handles external lines 0 to 1 interrupt request + * @param[in] none + * @param[out] none + * @retval None + */ +void EXTI0_1_IRQHandler(void) { + if (exti_interrupt_flag_get(US_RX_GPIO_EXTI) == SET) + { + exti_interrupt_flag_clear(US_RX_GPIO_EXTI); + g_capture_value = timer_channel_capture_value_register_read(US_ECHO_TIMER, US_ECHO_CH); + ultrasonicMeasurementDone = true; + timer_disable(US_ECHO_TIMER); + exti_interrupt_disable(US_RX_GPIO_EXTI); + } +} + void USART0_IRQHandler(void) { static uint8_t rx_index = 0; static uint8_t rx_buffer[RX_BUFFER_SIZE]; diff --git a/src/main.c b/src/main.c index bfce4af..34b0207 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,9 @@ */ #include "main.h" +extern uint32_t g_capture_value; +uint16_t g_distance_uint16; + /*! \brief main function \param[in] none @@ -26,11 +29,19 @@ int main(void) printf("system start!\r\n"); + ultrasonic_config(); + // gpio_bit_write(RS485_EN_PORT, RS485_EN_PIN, RESET); while(1){ // printf("hello world!\r\n"); - // delay_ms(500); + delay_ms(50); + ultrasonic_pwm_out_cycles(ULTRASONIC_TX_CYCLES); + // delay_ms(2); + + + // g_distance_uint16 = ultrasonic_calc_distance(); + // printf("Distance: %d cm\r\n", g_distance_uint16); watchdog_reload(); } } diff --git a/src/rs485_protocol.c b/src/rs485_protocol.c index ea8ce98..165993c 100644 --- a/src/rs485_protocol.c +++ b/src/rs485_protocol.c @@ -18,8 +18,8 @@ void process_command(uint8_t *cmd, size_t length) { // printf("%d", length); sprintf(combined_str, "%c%c", cmd[3], cmd[4]); if (strcmp(combined_str, "M1") == 0) { - printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC); - // eddy_current_value_report(); + + ultrasonic_distance_report(); } else if (strcmp(combined_str, "M2") == 0) { printf("%c%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0x6B, 0xCC); // tempture_value_report(); @@ -90,3 +90,43 @@ validation_result_t validate_data_length(uint8_t *data) { return VALIDATION_LENGTH_ERROR; } } + +// void eddy_current_value_report(void) { +// static uint32_t eddy_current_value_uint32 = 0; +// +// eddy_current_value_uint32 = ldc1612_get_raw_channel_result(CHANNEL_0); +// +// package_data[0] = (eddy_current_value_uint32 >> 24) & 0xFF; +// package_data[1] = (eddy_current_value_uint32 >> 16) & 0xFF; +// package_data[2] = (eddy_current_value_uint32 >> 8) & 0xFF; +// package_data[3] = eddy_current_value_uint32 & 0xFF; +// +// uint8_t combined_data[7]; +// memcpy(combined_data, package_header, 3); +// memcpy(combined_data + 3, package_data, 4); +// +// printf("%c%c%c", package_header[0], package_header[1], package_header[2]); +// printf("%c%c%c%c", package_data[0], package_data[1], package_data[2], package_data[3]); +// printf("%c", calculate_crc(combined_data, 8)); +// } + +void ultrasonic_distance_report(void) { + static uint32_t distance_uint32 = 0; + static uint8_t package_header[3] = {0xB5, 0xF0, 0x04}; + static uint8_t package_data[4] = {0}; + + distance_uint32 = ultrasonic_calc_distance(); + + package_data[0] = (distance_uint32 >> 24) & 0xFF; + package_data[1] = (distance_uint32 >> 16) & 0xFF; + package_data[2] = (distance_uint32 >> 8) & 0xFF; + package_data[3] = distance_uint32 & 0xFF; + + uint8_t combined_data[7]; + memcpy(combined_data, package_header, 3); + memcpy(combined_data + 3, package_data, 4); + + printf("%c%c%c", package_header[0], package_header[1], package_header[2]); + printf("%c%c%c%c", package_data[0], package_data[1], package_data[2], package_data[3]); + printf("%c", calculate_crc(combined_data, 8)); +} diff --git a/src/ultrasonic_analog.c b/src/ultrasonic_analog.c new file mode 100644 index 0000000..70bd4af --- /dev/null +++ b/src/ultrasonic_analog.c @@ -0,0 +1,154 @@ +// +// Created by yelv1 on 24-12-31. +// + +#include "ultrasonic_analog.h" + +volatile bool ultrasonicMeasurementDone = false; +extern uint32_t g_capture_value; + +/*! + \brief configure ultrasonic gpio & timer13 ch0 pwm output + \param[in] none + \param[out] none + \retval none +*/ +void ultrasonic_gpio_config(void) { + rcu_periph_clock_enable(US_TX_GPIO_RCU); + + gpio_mode_set(US_TX_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, US_TX_PIN); + gpio_output_options_set(US_TX_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, US_TX_PIN); + gpio_af_set(US_TX_GPIO_PORT, US_TX_GPIO_AF, US_TX_PIN); + + timer_oc_parameter_struct timer_ocinitpara; + timer_parameter_struct timer_initpara; + + rcu_periph_clock_enable(US_TX_RCU); + timer_deinit(US_TX_TIMER); + + timer_struct_para_init(&timer_initpara); + timer_initpara.prescaler = 0; + timer_initpara.alignedmode = TIMER_COUNTER_EDGE; + timer_initpara.counterdirection = TIMER_COUNTER_UP; + timer_initpara.period = 239; + timer_initpara.clockdivision = TIMER_CKDIV_DIV1; + timer_init(US_TX_TIMER, &timer_initpara); + + timer_channel_output_struct_para_init(&timer_ocinitpara); + timer_ocinitpara.outputstate = TIMER_CCX_ENABLE; + timer_ocinitpara.outputnstate = TIMER_CCXN_DISABLE; + timer_ocinitpara.ocpolarity = TIMER_OC_POLARITY_HIGH; + timer_ocinitpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH; + timer_ocinitpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW; + timer_ocinitpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW; + timer_channel_output_config(US_TX_TIMER, US_TX_CH, &timer_ocinitpara); + + timer_channel_output_pulse_value_config(US_TX_TIMER, US_TX_CH, 120); + timer_channel_output_mode_config(US_TX_TIMER, US_TX_CH, TIMER_OC_MODE_PWM0); + timer_auto_reload_shadow_enable(US_TX_TIMER); + + timer_interrupt_enable(US_TX_TIMER, TIMER_INT_UP); +} + +void ultrasonic_pwm_out_cycles(const uint8_t cycles) { + ultrasonicMeasurementDone = false; + uint8_t current_cycle = 0; + + timer_channel_output_pulse_value_config(US_TX_TIMER, US_TX_CH, 120); + timer_channel_output_mode_config(US_TX_TIMER, US_TX_CH, TIMER_OC_MODE_PWM1); + timer_enable(US_TX_TIMER); + + timer_enable(US_TX_DELAY_TIMER); + + while (current_cycle < cycles) + { + while (!timer_interrupt_flag_get(US_TX_TIMER, TIMER_INT_FLAG_UP)); + timer_interrupt_flag_clear(US_TX_TIMER, TIMER_INT_FLAG_UP); + current_cycle++; + } + // delay_nop(); + timer_disable(US_TX_TIMER); +} + +/*! + \brief configure ultrasonic transmit debounce delay(timer15) 72MHz/72 = 1MHz 1us. + \param[in] micro_second: delay time in micro second + \param[out] none + \retval none +*/ +void ultrasonic_transmit_debounce_delay(const uint16_t micro_second) { + rcu_periph_clock_enable(US_TX_DELAY_RCU); + timer_deinit(US_TX_DELAY_TIMER); + + timer_parameter_struct timer_initpara; + timer_struct_para_init(&timer_initpara); + timer_initpara.prescaler = 71; + timer_initpara.alignedmode = TIMER_COUNTER_EDGE; + timer_initpara.counterdirection = TIMER_COUNTER_UP; + timer_initpara.period = micro_second - 1; + timer_initpara.clockdivision = TIMER_CKDIV_DIV1; + timer_initpara.repetitioncounter = 0; + timer_init(US_TX_DELAY_TIMER, &timer_initpara); + + timer_auto_reload_shadow_enable(US_TX_DELAY_TIMER); + timer_interrupt_enable(US_TX_DELAY_TIMER, TIMER_INT_UP); + nvic_irq_enable(TIMER15_IRQn, 1U); +} + +void ultrasonic_receive_exti_config(void) { + rcu_periph_clock_enable(US_RX_GPIO_RCU); + rcu_periph_clock_enable(US_RX_EXTI_RCU); + + gpio_mode_set(US_RX_GPIO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, US_RX_GPIO_PIN); + nvic_irq_enable(US_RX_EXTI_IRQ, 0U); + syscfg_exti_line_config(EXTI_SOURCE_GPIOA, US_RX_EXTI_LINE); + + exti_init(US_RX_GPIO_EXTI, EXTI_INTERRUPT, EXTI_TRIG_FALLING); + exti_flag_clear(US_RX_GPIO_EXTI); + + // exti_interrupt_enable(EXTI_0); +} + +void ultrasonic_echo_timer_config(void) { + rcu_periph_clock_enable(US_ECHO_RCU); + timer_deinit(US_ECHO_TIMER); + + timer_parameter_struct timer_initpara; + timer_struct_para_init(&timer_initpara); + timer_initpara.prescaler = 71; + timer_initpara.alignedmode = TIMER_COUNTER_EDGE; + timer_initpara.counterdirection = TIMER_COUNTER_UP; + timer_initpara.period = 59999; + timer_initpara.clockdivision = TIMER_CKDIV_DIV1; + timer_initpara.repetitioncounter = 0; + timer_init(US_ECHO_TIMER, &timer_initpara); + + timer_ic_parameter_struct timer_icinitpara; + timer_channel_input_struct_para_init(&timer_icinitpara); + timer_icinitpara.icpolarity = TIMER_IC_POLARITY_BOTH_EDGE; + timer_icinitpara.icselection = TIMER_IC_SELECTION_INDIRECTTI; + timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1; + timer_icinitpara.icfilter = 0x03; + timer_input_capture_config(US_ECHO_TIMER, US_ECHO_CH, &timer_icinitpara); +} + +void ultrasonic_config(void) { + ultrasonic_gpio_config(); + ultrasonic_transmit_debounce_delay(TIME_CORRECTION_US); + ultrasonic_receive_exti_config(); + ultrasonic_echo_timer_config(); +} + +uint32_t ultrasonic_calc_distance(void) { + while (!ultrasonicMeasurementDone); + // uint32_t us_value = timer_channel_capture_value_register_read(US_ECHO_TIMER, US_ECHO_CH); + uint32_t distance = (TIME_CORRECTION_US + g_capture_value) * 17; + /* + * (TIME_CORRECTION_US + us_value) * 340 m/s + * ----------------------------------------- + * 1000 000 + * ---------------------------------------------- + * 2 + */ + return distance; +} \ No newline at end of file From aee082068e89851f341ed769085e4350579011ca Mon Sep 17 00:00:00 2001 From: yelvlab Date: Tue, 7 Jan 2025 15:42:56 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=A1=AC=E4=BB=B6IIC?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=9B=9E=E5=8E=BB=E6=95=B0=E6=8D=AE=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E4=B8=94=EF=BC=8C=E9=97=B4=E9=9A=94=E7=BC=A9=E5=B0=8F?= =?UTF-8?q?=E5=88=B0300ms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 3 ++- inc/gd60914.h | 34 ++++++++++++++++++++++++++++++++++ inc/i2c.h | 2 +- inc/main.h | 1 + src/fwdgt.c | 2 +- src/gd60914.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/main.c | 11 ++++++++--- src/soft_i2c.c | 2 +- 8 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 inc/gd60914.h create mode 100644 src/gd60914.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ee44a95..fcc2e3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(OPT1 "_[12V]") #set(OPT1 "_[SW_IIC]") # Options 2 -set(OPT2 "") +set(OPT2 "_[HW_IIC]") #set(OPT2 "_[NO_LED]") enable_language(C) @@ -40,6 +40,7 @@ set(TARGET_C_SRC ${CMAKE_SOURCE_DIR}/src/i2c.c ${CMAKE_SOURCE_DIR}/src/fwdgt.c ${CMAKE_SOURCE_DIR}/src/rs485_protocol.c + ${CMAKE_SOURCE_DIR}/src/gd60914.c ${CMAKE_SOURCE_DIR}/src/ultrasonic_analog.c ) diff --git a/inc/gd60914.h b/inc/gd60914.h new file mode 100644 index 0000000..16f0fcb --- /dev/null +++ b/inc/gd60914.h @@ -0,0 +1,34 @@ +// +// Created by dell on 25-1-7. +// + +#ifndef GD60914_H +#define GD60914_H + +#include "gd32e23x_it.h" +#include "gd32e23x.h" + +#include "board_config.h" + +#ifdef SOFTWARE_IIC +#include "soft_i2c.h" +#else +#include "i2c.h" +#endif + +/******************************************************************************/ + +#define GD60914_ADDR (0x18 << 1) + +/******************************************************************************/ + +#define GD60914_HUM_TEMP 0x1A +#define GD60914_OBJ_TEMP 0x1F +#define GD60914_AMB_TEMP 0x1E +#define GD60914_TEMP_REG 0x1C + +void gd60914_get_object_tempture(void); + +void gd60914_read_temp(void); + +#endif //GD60914_H diff --git a/inc/i2c.h b/inc/i2c.h index ea09aa7..6b379f4 100644 --- a/inc/i2c.h +++ b/inc/i2c.h @@ -19,7 +19,7 @@ /******************************************************************************/ -#define I2C_SPEED 20000 +#define I2C_SPEED 100000 #define I2C_TIME_OUT (uint16_t)(5000) #define I2C_OK 1 diff --git a/inc/main.h b/inc/main.h index ebfdc0e..5e00524 100644 --- a/inc/main.h +++ b/inc/main.h @@ -43,6 +43,7 @@ OF SUCH DAMAGE. #include "usart.h" #include "fwdgt.h" #include "board_config.h" +#include "gd60914.h" #include "ultrasonic_analog.h" #ifdef SOFTWARE_IIC diff --git a/src/fwdgt.c b/src/fwdgt.c index 4beebce..688572f 100644 --- a/src/fwdgt.c +++ b/src/fwdgt.c @@ -15,7 +15,7 @@ void watchdog_init(void) { rcu_osci_stab_wait(RCU_IRC40K); /* Configure FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */ - fwdgt_config(625, FWDGT_PSC_DIV64); // Set timeout to 1 seconds (625 / 0.625 KHz) + fwdgt_config(625, FWDGT_PSC_DIV256); // Set timeout to 1 seconds (625 / 0.625 KHz) /* Enable FWDGT */ fwdgt_enable(); diff --git a/src/gd60914.c b/src/gd60914.c new file mode 100644 index 0000000..ccdeb21 --- /dev/null +++ b/src/gd60914.c @@ -0,0 +1,43 @@ +// +// Created by dell on 25-1-7. +// + +#include "gd60914.h" + +void gd60914_get_object_tempture(void) { + #ifdef SOFTWARE_IIC + soft_i2c_config(); + #else + i2c_config(); + #endif + + uint8_t data[2] = {0}; + +#ifdef SOFTWARE_IIC + soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data); +#else + i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data); +#endif + + delay_ms(300); + +#ifdef SOFTWARE_IIC + soft_i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, data); +#else + i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, data); +#endif + + printf("%d\r\n", data[1] << 8 | data[0]); +} + +void gd60914_read_temp(void) { + + uint8_t value[2] = {0}; + #ifdef SOFTWARE_IIC + soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, value); + #else + i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, value); + #endif + + printf("%x %x\r\n", value[1], value[0]); +} \ No newline at end of file diff --git a/src/main.c b/src/main.c index 34b0207..eb6e21c 100644 --- a/src/main.c +++ b/src/main.c @@ -27,6 +27,12 @@ int main(void) /* configure FWDGT */ watchdog_init(); +#ifdef SOFTWARE_IIC + soft_i2c_config(); +#else + i2c_config(); +#endif + printf("system start!\r\n"); ultrasonic_config(); @@ -34,14 +40,13 @@ int main(void) // gpio_bit_write(RS485_EN_PORT, RS485_EN_PIN, RESET); while(1){ // printf("hello world!\r\n"); + delay_ms(500); + gd60914_get_object_tempture(); delay_ms(50); ultrasonic_pwm_out_cycles(ULTRASONIC_TX_CYCLES); // delay_ms(2); - - // g_distance_uint16 = ultrasonic_calc_distance(); - // printf("Distance: %d cm\r\n", g_distance_uint16); watchdog_reload(); } } diff --git a/src/soft_i2c.c b/src/soft_i2c.c index 843cfd0..79883ae 100644 --- a/src/soft_i2c.c +++ b/src/soft_i2c.c @@ -11,7 +11,7 @@ \retval none */ void soft_i2c_delay(void) { - delay_us(20); // Adjust delay as needed + delay_us(1); // Adjust delay as needed /* delay to freq * 15KHz: delay_us(20); * 65KHz: delay_us(1); From 1af7a98a5ff72461f117789b66fa1322c3bb8116 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Wed, 8 Jan 2025 00:35:20 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E4=B8=BB=E5=87=BD=E6=95=B0=E4=B8=AD?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=89=A7=E8=A1=8C=EF=BC=8C500ms=E9=97=B4?= =?UTF-8?q?=E9=9A=94=E8=8E=B7=E5=8F=96=E6=B8=A9=E5=BA=A6=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/rs485_protocol.h | 2 +- src/fwdgt.c | 2 +- src/gd60914.c | 20 ++++++++++++++------ src/main.c | 4 +++- src/rs485_protocol.c | 18 +++++++++++++++--- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/inc/rs485_protocol.h b/inc/rs485_protocol.h index b0d2702..baf471e 100644 --- a/inc/rs485_protocol.h +++ b/inc/rs485_protocol.h @@ -49,7 +49,7 @@ validation_result_t validate_package_type(uint8_t* data); validation_result_t validate_data_length(uint8_t* data); - +void gd60914_tempture(void); void ultrasonic_distance_report(void); diff --git a/src/fwdgt.c b/src/fwdgt.c index 688572f..4beebce 100644 --- a/src/fwdgt.c +++ b/src/fwdgt.c @@ -15,7 +15,7 @@ void watchdog_init(void) { rcu_osci_stab_wait(RCU_IRC40K); /* Configure FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */ - fwdgt_config(625, FWDGT_PSC_DIV256); // Set timeout to 1 seconds (625 / 0.625 KHz) + fwdgt_config(625, FWDGT_PSC_DIV64); // Set timeout to 1 seconds (625 / 0.625 KHz) /* Enable FWDGT */ fwdgt_enable(); diff --git a/src/gd60914.c b/src/gd60914.c index ccdeb21..b9662dc 100644 --- a/src/gd60914.c +++ b/src/gd60914.c @@ -11,23 +11,31 @@ void gd60914_get_object_tempture(void) { i2c_config(); #endif - uint8_t data[2] = {0}; + static uint8_t sensor_validation_data[2]; + extern uint8_t g_temperature_uint8[2]; #ifdef SOFTWARE_IIC soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data); #else - i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data); + i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, sensor_validation_data); #endif - delay_ms(300); + if (sensor_validation_data[0] != 0xAA || sensor_validation_data[1] != 0x55) { +#ifdef DEBUG_VERBOES + printf("sensor error\r\n"); +#endif + return; + } + + delay_ms(350); #ifdef SOFTWARE_IIC - soft_i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, data); + soft_i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, g_temperature_uint8); #else - i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, data); + i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, g_temperature_uint8); #endif - printf("%d\r\n", data[1] << 8 | data[0]); + // printf("%d\r\n", g_temperature_uint8[1] << 8 | g_temperature_uint8[0]); } void gd60914_read_temp(void) { diff --git a/src/main.c b/src/main.c index eb6e21c..7bd8ed8 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,8 @@ */ #include "main.h" +volatile uint8_t g_temperature_uint8[2] = {0}; + extern uint32_t g_capture_value; uint16_t g_distance_uint16; @@ -40,7 +42,7 @@ int main(void) // gpio_bit_write(RS485_EN_PORT, RS485_EN_PIN, RESET); while(1){ // printf("hello world!\r\n"); - delay_ms(500); + // delay_ms(500); gd60914_get_object_tempture(); delay_ms(50); diff --git a/src/rs485_protocol.c b/src/rs485_protocol.c index 165993c..4ffed9e 100644 --- a/src/rs485_protocol.c +++ b/src/rs485_protocol.c @@ -4,6 +4,8 @@ #include "rs485_protocol.h" +extern uint8_t g_temperature_uint8[2]; + void process_command(uint8_t *cmd, size_t length) { char combined_str[3]; validation_result_t validate = VALIDATION_SUCCESS; @@ -18,11 +20,9 @@ void process_command(uint8_t *cmd, size_t length) { // printf("%d", 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) { - printf("%c%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0x6B, 0xCC); - // tempture_value_report(); + gd60914_tempture(); } else if (strcmp(combined_str, "M3") == 0) { printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC); @@ -130,3 +130,15 @@ void ultrasonic_distance_report(void) { printf("%c%c%c%c", package_data[0], package_data[1], package_data[2], package_data[3]); printf("%c", calculate_crc(combined_data, 8)); } + +void gd60914_tempture(void) { + static uint8_t package_header[3] = {0xB5, 0xF0, 0x02}; + + uint8_t combined_data[5]; + memcpy(combined_data, package_header, 3); + memcpy(combined_data + 3, g_temperature_uint8, 2); + + printf("%c%c%c", package_header[0], package_header[1], package_header[2]); + printf("%c%c", g_temperature_uint8[1], g_temperature_uint8[0]); + printf("%c", calculate_crc(combined_data, 6)); +} \ No newline at end of file From 8a7baaf87aad04fea7963a8af0d6f5111a9a629f Mon Sep 17 00:00:00 2001 From: yelvlab Date: Wed, 8 Jan 2025 09:14:18 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=9A=E4=BF=A1?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E9=83=A8=E5=88=86=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=89=88=E5=9E=8B=E4=B8=BA0x04?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/rs485_protocol.h | 4 ++-- src/rs485_protocol.c | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/inc/rs485_protocol.h b/inc/rs485_protocol.h index baf471e..d046836 100644 --- a/inc/rs485_protocol.h +++ b/inc/rs485_protocol.h @@ -21,7 +21,7 @@ #define RX_BUFFER_SIZE 32 #define PROTOCOL_PACKAGE_HEADER 0xD5 -#define PROTOCOL_BOARD_TYPE 0x03 +#define PROTOCOL_BOARD_TYPE 0x04 #define PROTOCOL_PACKAGE_LENGTH 0x02 /******************************************************************************/ @@ -49,7 +49,7 @@ validation_result_t validate_package_type(uint8_t* data); validation_result_t validate_data_length(uint8_t* data); -void gd60914_tempture(void); +void gd60914_tempture_report(void); void ultrasonic_distance_report(void); diff --git a/src/rs485_protocol.c b/src/rs485_protocol.c index 4ffed9e..06bf928 100644 --- a/src/rs485_protocol.c +++ b/src/rs485_protocol.c @@ -21,8 +21,9 @@ 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(); + } 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); @@ -131,7 +132,7 @@ void ultrasonic_distance_report(void) { printf("%c", calculate_crc(combined_data, 8)); } -void gd60914_tempture(void) { +void gd60914_tempture_report(void) { static uint8_t package_header[3] = {0xB5, 0xF0, 0x02}; uint8_t combined_data[5]; From 6dd053e217a4f9c61f80b3ff124f8c418c6672b5 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Wed, 8 Jan 2025 09:17:30 +0800 Subject: [PATCH 5/8] update version IR development version --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fcc2e3a..985cac9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,8 @@ set(PROJECT_NAME "XLSW_3DP_US-IR") project(${PROJECT_NAME}) set(VERSION_MAJOR 0) -set(VERSION_MINOR 0) -set(VERSION_PATCH 1) +set(VERSION_MINOR 1) +set(VERSION_PATCH 0) set(VERSION "V${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") string(TIMESTAMP CURRENT_DATE "%Y-%m-%d") From c9c1e00d6a977fd7e24181317a19adb853cf8876 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Wed, 1 Jan 2025 02:10:03 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98=E7=89=88?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + inc/main.h | 1 + src/main.c | 4 +--- src/rs485_protocol.c | 26 ++++++++++++-------------- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 985cac9..09bfcfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ set(TARGET_C_SRC ${CMAKE_SOURCE_DIR}/src/i2c.c ${CMAKE_SOURCE_DIR}/src/fwdgt.c ${CMAKE_SOURCE_DIR}/src/rs485_protocol.c + ${CMAKE_SOURCE_DIR}/src/ultrasonic_analog.c ${CMAKE_SOURCE_DIR}/src/gd60914.c ${CMAKE_SOURCE_DIR}/src/ultrasonic_analog.c ) diff --git a/inc/main.h b/inc/main.h index 5e00524..9460a1f 100644 --- a/inc/main.h +++ b/inc/main.h @@ -43,6 +43,7 @@ OF SUCH DAMAGE. #include "usart.h" #include "fwdgt.h" #include "board_config.h" +#include "ultrasonic_analog.h" #include "gd60914.h" #include "ultrasonic_analog.h" diff --git a/src/main.c b/src/main.c index 7bd8ed8..14e97f2 100644 --- a/src/main.c +++ b/src/main.c @@ -41,13 +41,11 @@ int main(void) // gpio_bit_write(RS485_EN_PORT, RS485_EN_PIN, RESET); while(1){ - // printf("hello world!\r\n"); - // delay_ms(500); gd60914_get_object_tempture(); + delay_ms(50); ultrasonic_pwm_out_cycles(ULTRASONIC_TX_CYCLES); - // delay_ms(2); watchdog_reload(); } diff --git a/src/rs485_protocol.c b/src/rs485_protocol.c index 06bf928..b94265d 100644 --- a/src/rs485_protocol.c +++ b/src/rs485_protocol.c @@ -21,8 +21,7 @@ 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) - { + } else if (strcmp(combined_str, "M2") == 0) { gd60914_tempture_report(); } else if (strcmp(combined_str, "M3") == 0) { @@ -92,6 +91,17 @@ validation_result_t validate_data_length(uint8_t *data) { } } +void gd60914_tempture_report(void) { + static uint8_t package_header[3] = {0xB5, 0xF0, 0x02}; + + uint8_t combined_data[5]; + memcpy(combined_data, package_header, 3); + memcpy(combined_data + 3, g_temperature_uint8, 2); + + printf("%c%c%c", package_header[0], package_header[1], package_header[2]); + printf("%c%c", g_temperature_uint8[1], g_temperature_uint8[0]); + printf("%c", calculate_crc(combined_data, 6)); +} // void eddy_current_value_report(void) { // static uint32_t eddy_current_value_uint32 = 0; // @@ -131,15 +141,3 @@ void ultrasonic_distance_report(void) { printf("%c%c%c%c", package_data[0], package_data[1], package_data[2], package_data[3]); printf("%c", calculate_crc(combined_data, 8)); } - -void gd60914_tempture_report(void) { - static uint8_t package_header[3] = {0xB5, 0xF0, 0x02}; - - uint8_t combined_data[5]; - memcpy(combined_data, package_header, 3); - memcpy(combined_data + 3, g_temperature_uint8, 2); - - printf("%c%c%c", package_header[0], package_header[1], package_header[2]); - printf("%c%c", g_temperature_uint8[1], g_temperature_uint8[0]); - printf("%c", calculate_crc(combined_data, 6)); -} \ No newline at end of file From b4901f5f372cbc6e0bf39cd16f52c06fe0f5ab85 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Wed, 8 Jan 2025 13:47:24 +0800 Subject: [PATCH 7/8] alpha version --- cmake/toolchain.cmake | 12 ++++++------ inc/ultrasonic_analog.h | 2 +- src/gd32e23x_it.c | 2 +- src/main.c | 2 +- src/rs485_protocol.c | 18 ++++++++---------- src/ultrasonic_analog.c | 4 ++-- 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake index 48937ea..24ac005 100644 --- a/cmake/toolchain.cmake +++ b/cmake/toolchain.cmake @@ -94,12 +94,12 @@ set(TARGET_CFLAGS_HARDWARE "-mcpu=cortex-m23 -mfloat-abi=soft -mthumb -mthumb-in #set(CMAKE_C_FLAGS_DEBUG "-DDEBUG=0 -O0 -g") #set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG=0 -O0 -g") #set(CMAKE_ASM_FLAGS_DEBUG "-DDEBUG=0 -O0 -g") -set(CMAKE_C_FLAGS_DEBUG "-DDEBUG=0 -O2 -g") -set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG=0 -O2 -g") -set(CMAKE_ASM_FLAGS_DEBUG "-DDEBUG=0 -O2 -g") -#set(CMAKE_C_FLAGS_DEBUG "-DDEBUG=0 -Os -g") -#set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG=0 -Os -g") -#set(CMAKE_ASM_FLAGS_DEBUG "-DDEBUG=0 -Os -g") +#set(CMAKE_C_FLAGS_DEBUG "-DDEBUG=0 -O2 -g") +#set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG=0 -O2 -g") +#set(CMAKE_ASM_FLAGS_DEBUG "-DDEBUG=0 -O2 -g") +set(CMAKE_C_FLAGS_DEBUG "-DDEBUG=0 -Os -g") +set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG=0 -Os -g") +set(CMAKE_ASM_FLAGS_DEBUG "-DDEBUG=0 -Os -g") # RELEASE set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O3") # -flto diff --git a/inc/ultrasonic_analog.h b/inc/ultrasonic_analog.h index d59ac3b..8696a9b 100644 --- a/inc/ultrasonic_analog.h +++ b/inc/ultrasonic_analog.h @@ -37,7 +37,7 @@ void ultrasonic_echo_timer_config(void); void ultrasonic_config(void); -uint32_t ultrasonic_calc_distance(void); +uint16_t ultrasonic_calc_distance(void); #endif //ULTRASONIC_ANALOG_H diff --git a/src/gd32e23x_it.c b/src/gd32e23x_it.c index a966685..acc74b7 100644 --- a/src/gd32e23x_it.c +++ b/src/gd32e23x_it.c @@ -34,7 +34,7 @@ OF SUCH DAMAGE. #include "gd32e23x_it.h" -__IO uint32_t g_capture_value; +__IO uint16_t g_capture_value; /*! \brief this function handles NMI exception diff --git a/src/main.c b/src/main.c index 14e97f2..9a2fb7f 100644 --- a/src/main.c +++ b/src/main.c @@ -8,7 +8,7 @@ volatile uint8_t g_temperature_uint8[2] = {0}; -extern uint32_t g_capture_value; +extern uint16_t g_capture_value; uint16_t g_distance_uint16; /*! diff --git a/src/rs485_protocol.c b/src/rs485_protocol.c index b94265d..1a7d70a 100644 --- a/src/rs485_protocol.c +++ b/src/rs485_protocol.c @@ -122,22 +122,20 @@ void gd60914_tempture_report(void) { // } void ultrasonic_distance_report(void) { - static uint32_t distance_uint32 = 0; - static uint8_t package_header[3] = {0xB5, 0xF0, 0x04}; + static uint16_t distance_uint16 = 0; + static uint8_t package_header[3] = {0xB5, 0xF0, 0x02}; static uint8_t package_data[4] = {0}; - distance_uint32 = ultrasonic_calc_distance(); + distance_uint16 = ultrasonic_calc_distance(); - package_data[0] = (distance_uint32 >> 24) & 0xFF; - package_data[1] = (distance_uint32 >> 16) & 0xFF; - package_data[2] = (distance_uint32 >> 8) & 0xFF; - package_data[3] = distance_uint32 & 0xFF; + package_data[0] = (distance_uint16 >> 8) & 0xFF; + package_data[1] = distance_uint16 & 0xFF; uint8_t combined_data[7]; memcpy(combined_data, package_header, 3); - memcpy(combined_data + 3, package_data, 4); + memcpy(combined_data + 3, package_data, 2); printf("%c%c%c", package_header[0], package_header[1], package_header[2]); - printf("%c%c%c%c", package_data[0], package_data[1], package_data[2], package_data[3]); - printf("%c", calculate_crc(combined_data, 8)); + printf("%c%c", package_data[0], package_data[1]); + printf("%c", calculate_crc(combined_data, 6)); } diff --git a/src/ultrasonic_analog.c b/src/ultrasonic_analog.c index 70bd4af..10ef5b5 100644 --- a/src/ultrasonic_analog.c +++ b/src/ultrasonic_analog.c @@ -139,10 +139,10 @@ void ultrasonic_config(void) { ultrasonic_echo_timer_config(); } -uint32_t ultrasonic_calc_distance(void) { +uint16_t ultrasonic_calc_distance(void) { while (!ultrasonicMeasurementDone); // uint32_t us_value = timer_channel_capture_value_register_read(US_ECHO_TIMER, US_ECHO_CH); - uint32_t distance = (TIME_CORRECTION_US + g_capture_value) * 17; + uint16_t distance = (TIME_CORRECTION_US + g_capture_value) * 17; /* * (TIME_CORRECTION_US + us_value) * 340 m/s * ----------------------------------------- From e940c69d49c2f7e92b527b0bf109a7b31e38fbd4 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Wed, 8 Jan 2025 13:57:25 +0800 Subject: [PATCH 8/8] clean --- src/rs485_protocol.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/rs485_protocol.c b/src/rs485_protocol.c index 1a7d70a..787cbc4 100644 --- a/src/rs485_protocol.c +++ b/src/rs485_protocol.c @@ -102,24 +102,6 @@ void gd60914_tempture_report(void) { printf("%c%c", g_temperature_uint8[1], g_temperature_uint8[0]); printf("%c", calculate_crc(combined_data, 6)); } -// void eddy_current_value_report(void) { -// static uint32_t eddy_current_value_uint32 = 0; -// -// eddy_current_value_uint32 = ldc1612_get_raw_channel_result(CHANNEL_0); -// -// package_data[0] = (eddy_current_value_uint32 >> 24) & 0xFF; -// package_data[1] = (eddy_current_value_uint32 >> 16) & 0xFF; -// package_data[2] = (eddy_current_value_uint32 >> 8) & 0xFF; -// package_data[3] = eddy_current_value_uint32 & 0xFF; -// -// uint8_t combined_data[7]; -// memcpy(combined_data, package_header, 3); -// memcpy(combined_data + 3, package_data, 4); -// -// printf("%c%c%c", package_header[0], package_header[1], package_header[2]); -// printf("%c%c%c%c", package_data[0], package_data[1], package_data[2], package_data[3]); -// printf("%c", calculate_crc(combined_data, 8)); -// } void ultrasonic_distance_report(void) { static uint16_t distance_uint16 = 0;