generated from hulk/gd32e23x_template
Compare commits
6 Commits
1752e3824c
...
feature_ri
Author | SHA1 | Date | |
---|---|---|---|
8348652425 | |||
c9e994f0c2 | |||
1b65f75da7 | |||
742ede30d4 | |||
b3dea747d0 | |||
6c51f0203a |
@@ -5,11 +5,11 @@
|
||||
#ifndef BOARD_CONFIG_H
|
||||
#define BOARD_CONFIG_H
|
||||
|
||||
#define SOFTWARE_IIC
|
||||
// #define SOFTWARE_IIC
|
||||
|
||||
// #define DEBUG_VERBOES
|
||||
|
||||
#define RS485_MAX13487
|
||||
// #define RS485_MAX13487
|
||||
|
||||
// #define DEBUG_VOFA_TOOL
|
||||
|
||||
|
@@ -19,7 +19,7 @@
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#define I2C_SPEED 20000
|
||||
#define I2C_SPEED 100*(1000)
|
||||
|
||||
#define I2C_TIME_OUT (uint16_t)(5000)
|
||||
#define I2C_OK 1
|
||||
|
@@ -36,6 +36,7 @@ OF SUCH DAMAGE.
|
||||
#define MAIN_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "gd32e23x.h"
|
||||
#include "systick.h"
|
||||
#include "gd32e23x_libopt.h"
|
||||
|
@@ -9,6 +9,8 @@
|
||||
#include "gd32e23x.h"
|
||||
#include "systick.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "ldc1612.h"
|
||||
#include "tmp112.h"
|
||||
#include "fwdgt.h"
|
||||
@@ -35,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;
|
||||
|
17
src/main.c
17
src/main.c
@@ -6,6 +6,10 @@
|
||||
*/
|
||||
#include "main.h"
|
||||
|
||||
bool g_statusSwitch = false;
|
||||
|
||||
uint8_t readBuffer[16];
|
||||
|
||||
/*!
|
||||
\brief main function
|
||||
\param[in] none
|
||||
@@ -38,10 +42,23 @@ int main(void) {
|
||||
/* Initialize watchdog */
|
||||
watchdog_init();
|
||||
|
||||
uint8_t command[10];
|
||||
uint8_t command_length = 0;
|
||||
|
||||
while (1) {
|
||||
|
||||
// delay_ms(10);
|
||||
fwdgt_counter_reload();
|
||||
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();}
|
||||
}
|
||||
}
|
||||
|
||||
|
14
src/rs485.c
14
src/rs485.c
@@ -7,6 +7,8 @@
|
||||
uint8_t package_header[3] = {0xB5, 0xF0, 0x04};
|
||||
uint8_t package_data[4] = {0};
|
||||
|
||||
extern bool g_statusSwitch;
|
||||
|
||||
void rs485_config(void) {
|
||||
#ifndef RS485_MAX13487
|
||||
rcu_periph_clock_enable(RS485_GPIO_RCU);
|
||||
@@ -87,13 +89,11 @@ 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) {
|
||||
eddy_current_value_report();
|
||||
} else if (strcmp(combined_str, "M2") == 0)
|
||||
{
|
||||
tempture_value_report();
|
||||
} else if (strcmp(combined_str, "M3") == 0)
|
||||
{
|
||||
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
||||
g_statusSwitch = true;
|
||||
} else if (strcmp(combined_str, "M2") == 0) {
|
||||
g_statusSwitch = false;
|
||||
} else if (strcmp(combined_str, "M3") == 0) {
|
||||
printf("%c%c%c%c%c%c", 0xB5, 0xF0, 0x02, 0x6F, 0x6B, 0xCC);
|
||||
fwdgt_reset_mcu();
|
||||
} else {
|
||||
printf("%c%c%c%c%c%c%c", 0xB5, 0xF0, 0x03, 0x65, 0x72, 0x72, 0x3C);
|
||||
|
Reference in New Issue
Block a user