generated from hulk/gd32e23x_template
已经按照例程实现基本的功能,但是为什么串口转发的是前一个包
This commit is contained in:
parent
c9e994f0c2
commit
8348652425
@ -9,6 +9,7 @@
|
||||
#include "gd32e23x.h"
|
||||
#include "systick.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "ldc1612.h"
|
||||
#include "tmp112.h"
|
||||
@ -36,6 +37,12 @@ typedef enum
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
uint8_t Command_Write(uint8_t *data, uint8_t length);
|
||||
|
||||
uint8_t Command_GetCommand(uint8_t *command);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void rs485_config(void);
|
||||
|
||||
void process_command(uint8_t* cmd, size_t length);
|
||||
|
@ -39,6 +39,8 @@ OF SUCH DAMAGE.
|
||||
#include "rs485.h"
|
||||
#include "led.h"
|
||||
|
||||
extern uint8_t readBuffer[16];
|
||||
|
||||
/*!
|
||||
\brief this function handles NMI exception
|
||||
\param[in] none
|
||||
@ -119,22 +121,21 @@ void TIMER16_IRQHandler(void) {
|
||||
|
||||
void USART0_IRQHandler(void) {
|
||||
static uint8_t rx_index = 0;
|
||||
static uint8_t rx_buffer[RX_BUFFER_SIZE];
|
||||
|
||||
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);
|
||||
// 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 (rx_index < sizeof(readBuffer) - 1) {
|
||||
readBuffer[rx_index++] = usart_data_receive(USART0);
|
||||
}
|
||||
}
|
||||
|
||||
if (RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_IDLE)) {
|
||||
usart_interrupt_flag_clear(USART0, USART_INT_FLAG_IDLE);
|
||||
|
||||
process_command(rx_buffer, rx_index); // 处理指令
|
||||
Command_Write(readBuffer, rx_index);// 处理指令
|
||||
|
||||
rx_index = 0; // 重置缓冲区索引
|
||||
return;
|
||||
|
19
src/main.c
19
src/main.c
@ -8,6 +8,8 @@
|
||||
|
||||
bool g_statusSwitch = false;
|
||||
|
||||
uint8_t readBuffer[16];
|
||||
|
||||
/*!
|
||||
\brief main function
|
||||
\param[in] none
|
||||
@ -40,12 +42,23 @@ int main(void) {
|
||||
/* Initialize watchdog */
|
||||
watchdog_init();
|
||||
|
||||
uint8_t command[10];
|
||||
uint8_t command_length = 0;
|
||||
|
||||
while (1) {
|
||||
|
||||
delay_ms(10);
|
||||
// delay_ms(10);
|
||||
fwdgt_counter_reload();
|
||||
if (g_statusSwitch)
|
||||
{eddy_current_value_report();}
|
||||
command_length = Command_GetCommand(command);
|
||||
if (command_length != 0)
|
||||
{
|
||||
for (int i = 0; i < command_length; i++)
|
||||
{
|
||||
printf("%c", command[i]);
|
||||
}
|
||||
}
|
||||
// if (g_statusSwitch)
|
||||
// {eddy_current_value_report();}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user