#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
*************************************************************
*************************************************************
注意:
ADC转换的值存放在32位宽的uhADCxyConvertedValue[]数组中,该数组长度为20000
再经数据处理一下后,ADC1的数据会存放在16位宽的uhADCxyConvertedValue_Lock[]数组中,ADC2会存在uhADCxyConvertedValue_Lock[]的6144+后面的6144个里面。
当需要的数据个数很多时,要更改数组长度。数组定义在ADC_DMA.h的DataBuffer_Length中
USB发送时使用的是小端模式(低地址存放低位,高地址存放高位),上位机接受需要组合成
unsigned short类型的数
*************************************************************
*************************************************************
接线:
串口VCC: CN8-7(左边从上数第4个)
串口GND: CN8-13(左边从下数第2个)
串口RX : CN9-4(右边从上数第2个)
串口TX : CN9-6(右边从上数第3个)
ADC_IN : CN9-11(左边从上数第6个)
ADC_GND : CN9-12(右边从上数第6个)
EXTI_IN: CN9-29(左边从下数第1个)
EXTI_GND:CN9-23(左边从下数第4个)
外接电源VIN:CN8-15(左边从下数第1个),同时还要将JP3的跳线帽接到最右边VIN-5V端
*************************************************************
*************************************************************
指示灯:
LED3亮表示AD转换成功,每次触发后会被刷新
LED2亮表示USER BUTTON被按下触发,每次触发后会被刷新
LED1亮表示被外部信号触发,每次触发后会被刷新
*************************************************************
*************************************************************
ADC电压采样范围为:0--3.3V
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
__IO uint16_t uhADCxConvertedValue[DataBuffer_Length]={0} ;
__IO uint16_t uhADCyConvertedValue[DataBuffer_Length]={0} ;
uint32_t NumOfPoint = NumOfWave * NUMofOneWave; //DMA发送的数据个数12*512=6144个数据////???是否需要改成12288
uint32_t SampleRate = Frequence * NUMofOneWave; //采样率22*512=11264
uint32_t DMA_DelayTime = 0; //初始化DMA搬运延时时间
USBD_HandleTypeDef USBD_Device; //USB设备结构体
uint8_t * CHAR_PTR =(uint8_t *)&uhADCxyConvertedValue[0]; //把要发送的 unsigned short型数据强制变成char型
uint8_t * CHAR_PTR_2 = (uint8_t *)&lBufMagArray[0];
uint8_t * CHAR_PTR_3 = (uint8_t *)&FFT_REB[0];
float Res_out = 0;
//double Res_out = 0;
uint8_t * CHAR_PTR_1;
int main(void)
{
//系统初始化
CPU_CACHE_Enable(); //初始化Cache
HAL_Init();
SystemClock_Config(); //系统时钟216MHz
//外设初始化
UART_Init(BaudRate_URAT); //串口初始化
BSP_LED_Init(LED3); //初始化LED3,用于指示AD转换成功
BSP_LED_Init(LED2); //初始化LED2,用于指示按钮是否按下
BSP_LED_Init(LED1); //初始化LED1,用于指示外部触发
TIMER1_Init((uint32_t)(100000/(Frequence*NUMofOneWave))-1); //TIMER初始化 //(100000/(22*512)-1)=
Dual_ADC_DMA_Init();
EXTI_Init(); //使能外部中断
//USB初始化
USBD_Init(&USBD_Device, &VCP_Desc, 0); //USB设备初始化
USBD_RegisterClass(&USBD_Device, USBD_CDC_CLASS); //CDC类初始化
USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops); //CDC类接口初始化
USBD_Start(&USBD_Device); //开启USB
while(1)
{
if(EXTI_BUTTON_FLAG||EXTI_TRIGGER_FLAG)
{
//开启AD转换
ADC_DMA_START( NumOfPoint); //启动ADC_DMA
ADC_TRIGGER_START(); //启动TIMER
DMA_DelayTime = (uint32_t)(NumOfPoint*1000/SampleRate)+10;////(6144*1000/11264)+10=555.454545
HAL_Delay(DMA_DelayTime); //需要延时等DMA把数都运完
//停止AD转化
ADC_DMA_STOP(); //关闭ADC_DMA
//串口发送数据
for(uint32_t ADC_DATA_POINT=0;ADC_DATA_POINT<NumOfPoint;ADC_DATA_POINT++)
{
uhADCxConvertedValue[ADC_DATA_POINT] = uhADCxyConvertedValue[ADC_DATA_POINT];
uhADCyConvertedValue[ADC_DATA_POINT] = uhADCxyConvertedValue[ADC_DATA_POINT]>>16;
uhADCxyConvertedValue_Lock[ADC_DATA_POINT] = uhADCxConvertedValue[ADC_DATA_POINT];
uhADCxyConvertedValue_Lock[ADC_DATA_POINT+NumOfPoint] = uhADCyConvertedValue[ADC_DATA_POINT];
printf("%u\n",uhADCxConvertedValue[ADC_DATA_POINT]);
printf("%u\n",uhADCyConvertedValue[ADC_DATA_POINT]);
}
// Res_out = DATA_PROCESS();
// printf("%f\n",Res_out);
EXTI_BUTTON_FLAG = 0;
EXTI_TRIGGER_FLAG = 0;
BSP_LED_Off(LED3);
BSP_LED_Off(LED2);
BSP_LED_Off(LED1);
//以下部分用于数据处理
//Res_out = DATA_PROCESS();
//
// CHAR_PTR_1 = (uint8_t *)&Res_out;
//
// USBD_CDC_SetTxBuffer(&USBD_Device,CHAR_PTR_1,(sizeof(float))); //USB通讯
// USBD_CDC_SetTxBuffer(&USBD_Device,CHAR_PTR_3,(NPT/2)*(sizeof(double)));
//USB数据发送
// USBD_CDC_SetTxBuffer(&USBD_Device,CHAR_PTR,NumOfPoint*SIZE);
while(USBD_CDC_TransmitPacket(&USBD_Device)!=USBD_OK)
{BSP_LED_On(LED1);} //未发送成功则LED1亮
}
}
}
/**
* @brief System Clock Configuration
* The system Clock is configured as follow :
* System Clock source = PLL (HSE)
* SYSCLK(Hz) = 216000000
* HCLK(Hz) = 216000000
* AHB Prescaler = 1
* APB1 Prescaler = 4
* APB2 Prescaler = 2
* HSE Frequency(Hz) = 8000000
* PLL_M = 8
* PLL_N = 432
* PLL_P = 2
* PLL_Q = 9
* VDD(V) = 3.3
* Main regulator output voltage = Scale1 mode
* Flash Latency(WS) = 7
*/
void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
/* Enable HSE Oscillator and activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 432;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 9;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
while(1) {};
}
/* Activate the OverDrive to reach the 216 Mhz Frequency */
if(HAL_PWREx_EnableOverDrive() != HAL_OK)
{
while(1) {};
}
/* Select PLLSAI output as USB clock source */
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CLK48;
PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48SOURCE_PLLSAIP;
PeriphClkInitStruct.PLLSAI.PLLSAIN = 384;
PeriphClkInitStruct.PLLSAI.PLLSAIQ = 7;
PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV8;
if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
while(1) {};
}
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
{
while(1) {};
}
}
/**
* @brief CPU L1-Cache enable.
* @param None
* @retval None
*/
static void CPU_CACHE_Enable(void)
{
/* Enable I-Cache */
SCB_EnableICache();
/* Enable D-Cache */
SCB_EnableDCache();
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
评分
查看全部评分
评分
查看全部评分