From 0910a260729fd4ace0a5a15fddef52b1024e134a Mon Sep 17 00:00:00 2001 From: yelvlab Date: Mon, 16 Dec 2024 14:19:10 +0800 Subject: [PATCH] finish tmp112a --- src/RS485.c | 5 ++++- src/gd32e23x_it.c | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/RS485.c b/src/RS485.c index 2db76b7..557f9c9 100644 --- a/src/RS485.c +++ b/src/RS485.c @@ -4,6 +4,8 @@ #include "RS485.h" +extern uint32_t g_temperature_uint32; + void RS485_config(void) { rcu_periph_clock_enable(RS485_GPIO_RCU); rcu_periph_clock_enable(RS485_RCU); @@ -35,7 +37,8 @@ void process_command(char *cmd) { if (strncmp(cmd, "M1", 2) == 0) { printf("M1 -=-=- OK!\r\n"); } else if (strncmp(cmd, "M2", 2) == 0) { - printf("M2 -=-=- OK!\r\n"); + // printf("M2 -=-=- OK!\r\n"); + printf("Temperature: %lu\r\n", g_temperature_uint32); // } else if (strncmp(cmd, "M3", 2) == 0) { // char *param_str = cmd + 2; // Skip "M3" // int param = atoi(param_str + 1); // Skip "S" and convert to integer diff --git a/src/gd32e23x_it.c b/src/gd32e23x_it.c index fd03276..604c5cf 100644 --- a/src/gd32e23x_it.c +++ b/src/gd32e23x_it.c @@ -36,6 +36,10 @@ OF SUCH DAMAGE. #include "main.h" #include "systick.h" #include "LDC1612.h" +#include "RS485.h" + +char rx_buffer[RX_BUFFER_SIZE]; +uint8_t rx_index = 0; /*! \brief this function handles NMI exception @@ -120,4 +124,24 @@ void TIMER16_IRQHandler(void) { } led_status = !led_status; } +} + +void USART0_IRQHandler(void) { + if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE)) + { + usart_interrupt_flag_clear(USART0, USART_INT_FLAG_RBNE); + uint8_t received_data = (uint8_t)usart_data_receive(USART0); + + // 将接收到的数据存储到缓冲区 + if(rx_index < RX_BUFFER_SIZE - 1) { + rx_buffer[rx_index++] = received_data; + } + + // 检查是否接收到换行符,表示指令结束 + if(received_data == '\n') { + rx_buffer[rx_index] = '\0'; // 添加字符串结束符 + process_command(rx_buffer); // 处理指令 + rx_index = 0; // 重置缓冲区索引 + } + } } \ No newline at end of file