116 lines
3.5 KiB
C
116 lines
3.5 KiB
C
|
/*
|
|||
|
* user.h
|
|||
|
*
|
|||
|
* Created on: Sep 23, 2024
|
|||
|
* Author: 10425
|
|||
|
*/
|
|||
|
|
|||
|
#ifndef INC_USER_H_
|
|||
|
#define INC_USER_H_
|
|||
|
#include "string.h"
|
|||
|
#include "stdlib.h"
|
|||
|
|
|||
|
#include "main.h"
|
|||
|
#include "main.h"
|
|||
|
#include "adc.h"
|
|||
|
#include "dma.h"
|
|||
|
#include "i2c.h"
|
|||
|
#include "tim.h"
|
|||
|
#include "usart.h"
|
|||
|
#include "gpio.h"
|
|||
|
|
|||
|
|
|||
|
#include "user_stick.h"
|
|||
|
#include "AHT20.h"
|
|||
|
#include "AT24C16.h"
|
|||
|
|
|||
|
#define ENABLE_INT() __set_PRIMASK(0) /* 使能全局中断 */
|
|||
|
#define DISABLE_INT() __set_PRIMASK(1) /* 禁止全局中断 */
|
|||
|
|
|||
|
extern DMA_HandleTypeDef hdma_adc;
|
|||
|
extern ADC_HandleTypeDef hadc1;
|
|||
|
extern TIM_HandleTypeDef htim14;
|
|||
|
extern DMA_HandleTypeDef hdma_usart1_rx;
|
|||
|
extern DMA_HandleTypeDef hdma_usart1_tx;
|
|||
|
extern UART_HandleTypeDef huart1;
|
|||
|
|
|||
|
#define BUFF_LEN 256
|
|||
|
#define ADCBUFF_LEN 250
|
|||
|
|
|||
|
#define FLASH_BASE_ADDR 0x08000000 //STM32 FLASH的起始地址
|
|||
|
#define FLASH_SECTOR_NUM 64 //STM32 FLASH所有扇区数
|
|||
|
#define FLASH_SECTOR_SIZE 2048
|
|||
|
|
|||
|
#define app1_addr 0x08000000
|
|||
|
#define app2_addr 0x0800C800
|
|||
|
#define app_flag 0x08019000
|
|||
|
typedef void (*LoadApp)(void); //定义一个函数指针类型.
|
|||
|
|
|||
|
/* 1:传感器数据 2:投退状态 3:电机状态
|
|||
|
* 4:PWM波占空比 5:传感器缩放系数 6:传感器加减系数
|
|||
|
* 7:电机运行时间 8:设置波特率 9:温湿度
|
|||
|
* 10:方波投退判断阈值 11:传感器退阈值 12:电压值
|
|||
|
* 13:电压阈值,电压小于该值时为退
|
|||
|
*/
|
|||
|
struct REGISTER
|
|||
|
{
|
|||
|
uint8_t addr;
|
|||
|
int16_t adc_max; //1:传感器数据
|
|||
|
int8_t adc_state; // 2:投退状态
|
|||
|
uint8_t motor_state; //电机状态
|
|||
|
uint16_t pwm_pulse; //PWM占空比
|
|||
|
uint16_t adcValue_factor; //传感器数据缩放系数
|
|||
|
uint16_t adcValue_addnum; //传感器数据加减系数
|
|||
|
int16_t peak_value; //峰峰值
|
|||
|
uint8_t baud_rate; //波特率
|
|||
|
uint8_t humidness; //湿度
|
|||
|
uint8_t tempe; //温度
|
|||
|
uint16_t estimate_value; //方波投退判断阈值
|
|||
|
uint16_t threshold_value; //传感器退阈值
|
|||
|
int16_t voltage; //电压值
|
|||
|
int16_t reference; //电压参考值
|
|||
|
uint16_t voltage_thresh; //电压阈值;
|
|||
|
};
|
|||
|
extern volatile struct REGISTER dev_reg;
|
|||
|
|
|||
|
enum WRITE_REG_ADDR
|
|||
|
{
|
|||
|
write_addr =0,
|
|||
|
write_baud =2,
|
|||
|
write_pulse = 4,
|
|||
|
write_factor = 6,
|
|||
|
write_addnum = 8,
|
|||
|
write_estimate = 10,
|
|||
|
write_threshold = 12,
|
|||
|
write_reference = 14,
|
|||
|
write_voltageth = 16
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
extern uint32_t updata_appaddr;
|
|||
|
extern volatile uint8_t usart_count; //串口接收数据个数
|
|||
|
extern uint8_t RxBuff[BUFF_LEN] ; //串口接收缓冲区
|
|||
|
extern uint8_t TXBuff[BUFF_LEN] ; //串口发送缓冲区
|
|||
|
extern uint8_t uBuff[BUFF_LEN] ; //用户缓冲区
|
|||
|
extern volatile int8_t polarity; //电场极性,投退状态
|
|||
|
extern volatile uint8_t electric_flag ; //外加的反向电场极限,0为负,1为正
|
|||
|
extern uint16_t RegularConvData_Tab[ADCBUFF_LEN] ; //ADC采集原始数据 //最终峰峰值和
|
|||
|
extern volatile int16_t adc_positive , adc_negative; //加外加电场后的adc值
|
|||
|
extern uint16_t user_temp;
|
|||
|
|
|||
|
void ADC_MAX();
|
|||
|
void user_main();
|
|||
|
void user_init();
|
|||
|
void Usart_Receive();
|
|||
|
void MODBUS_03H();
|
|||
|
void MODBUS_06H();
|
|||
|
void send_ack(uint8_t cnt);
|
|||
|
uint16_t crc16_modbus(uint8_t *data, uint16_t length);
|
|||
|
void Uart_SetBaud(int16_t baud);
|
|||
|
void calculate_voltage(void);
|
|||
|
HAL_StatusTypeDef write_flash(uint16_t addr,int16_t data);
|
|||
|
void MODBUS_10H();
|
|||
|
HAL_StatusTypeDef write_code(uint32_t addr,uint8_t* data,uint16_t length);
|
|||
|
|
|||
|
#endif /* INC_USER_H_ */
|