generated from hulk/gd32e23x_template
finish tmp112a
This commit is contained in:
parent
3f961a6a3e
commit
0910a26072
@ -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
|
||||
|
@ -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; // 重置缓冲区索引
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user