This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
CMS3in1/1.Cabin/1.Software/STM32_AD7606/User/Src/main.c

82 lines
2.4 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "usb_device.h"
#include "usbd_cdc_if.h"
#include "./SYSTEM/sys/sys.h"
#include "./SYSTEM/usart/usart.h"
#include "./BSP/AD7606/ControlCommandReceive.h"
#include "./SYSTEM/adc/adc.h"
#include "./BSP/CD4051B/cd4051b.h"
#include "./BSP/AD7606/AD7606.h"
void CollectionStar(void); /* 开始采样函数 */
void CollectionStop(void); /* 停止采样函数 */
void OffLineStart(void); /* 开始断线检测 */
int main(void)
{
HAL_Init();
HAL_Delay(1000); /* 延时等待晶振起振 */
sys_stm32_clock_init(336, 8, 2, 7); /* 设置时钟,168Mhz */
Data_to_ADbuf(); /* 初始化数组 */
HAL_Delay(1000); /* 延时等待晶振起振 */
MX_USB_DEVICE_Init(); /* USB初始化 */
HAL_Delay(30); /* 延时等待usb初始化完成 */
usart_init(115200); /* 串口初始化为115200 */
MX_ADC3_Init(); /* adc3初始化 */
CD4051B_Init(); /* cd4051b初始化 */
MX_FSMC_Init(); /* 初始化FSMC */
AD7606_Init(); /* 初始化AD7606 */
OffLineStart(); /* 开始断线检测 */
while (1)
{
/* 循环等待判断USB是否接受到消息 接收到消息标志位Control_Ins_Flag = 1*/
if(Control_Ins_Flag==1){
printf("处理数据\r\n");
Instruct_Judgment(); //处理USB传输的指令
/* 判断是否采样 */
if(sampling_control==1){
CollectionStar(); //开始采样
}
else if(sampling_control==0){
CollectionStop(); //停止采样
}
Control_Ins_Flag = 0; //修改标志位,防止重复进入
}
}
}
/*
开始采样程序,包括断线检测、振动数据采集、转速采集
*/
void CollectionStar(void){
printf("开始采集\r\n");
/* AD7606振动采集函数 包含转速采集 */
AD7606_StartRecord(); /* 开始采集 */
}
/*
停止采样程序
*/
void CollectionStop(void){
AD7606_StopRecord();
OffLineStart(); /* 开始断线检测 */
}
void OffLineStart(void){
/* 调用断线检测函数 将结果保存在数组中*/
DetectionResults results = OffLineDetection(); // 调用函数并接收返回的结果
DataArray[12856] = results.result1; // 结果以LSB格式保存
DataArray[12857] = results.result2;
DataArray[26220] = results.result1; // 结果以LSB格式保存
DataArray[26221] = results.result2;
}