generated from hulk/gd32e23x_template
完成收到包的分解与指令解析,并输出正确数据,待加入CRC验证机制。
This commit is contained in:
@@ -39,19 +39,15 @@ OF SUCH DAMAGE.
|
||||
#include "rs485.h"
|
||||
#include "led.h"
|
||||
|
||||
char rx_buffer[RX_BUFFER_SIZE];
|
||||
uint8_t rx_index = 0;
|
||||
|
||||
/*!
|
||||
\brief this function handles NMI exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
void NMI_Handler(void) {
|
||||
/* if NMI exception occurs, go to infinite loop */
|
||||
while(1) {
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,10 +57,9 @@ void NMI_Handler(void)
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
void HardFault_Handler(void) {
|
||||
/* if Hard Fault exception occurs, go to infinite loop */
|
||||
while(1) {
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +69,9 @@ void HardFault_Handler(void)
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
void SVC_Handler(void) {
|
||||
/* if SVC exception occurs, go to infinite loop */
|
||||
while(1) {
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,10 +81,9 @@ void SVC_Handler(void)
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
void PendSV_Handler(void) {
|
||||
/* if PendSV exception occurs, go to infinite loop */
|
||||
while(1) {
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,8 +93,7 @@ void PendSV_Handler(void)
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
void SysTick_Handler(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,12 +103,10 @@ void SysTick_Handler(void)
|
||||
* @retval None
|
||||
*/
|
||||
void TIMER16_IRQHandler(void) {
|
||||
if (timer_interrupt_flag_get(LED_TIMER, TIMER_INT_FLAG_UP) == SET)
|
||||
{
|
||||
if (timer_interrupt_flag_get(LED_TIMER, TIMER_INT_FLAG_UP) == SET) {
|
||||
timer_interrupt_flag_clear(LED_TIMER, TIMER_INT_FLAG_UP);
|
||||
static uint8_t led_status = 0;
|
||||
if (led_status)
|
||||
{
|
||||
if (led_status) {
|
||||
gpio_bit_write(LED_PORT, LED_PIN, RESET);
|
||||
timer_autoreload_value_config(LED_TIMER, 19200);
|
||||
} else {
|
||||
@@ -128,21 +118,23 @@ void TIMER16_IRQHandler(void) {
|
||||
}
|
||||
|
||||
void USART0_IRQHandler(void) {
|
||||
if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE))
|
||||
{
|
||||
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);
|
||||
uint8_t received_data = (uint8_t) usart_data_receive(USART0);
|
||||
|
||||
// 将接收到的数据存储到缓冲区
|
||||
if(rx_index < RX_BUFFER_SIZE - 1) {
|
||||
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); // 处理指令
|
||||
if (received_data == '\n') {
|
||||
// rx_buffer[rx_index] = '\0'; // 添加字符串结束符
|
||||
process_command(rx_buffer, rx_index); // 处理指令
|
||||
rx_index = 0; // 重置缓冲区索引
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user