银杏科技有限公司旗下技术文档发布平台 | |||
技术支持电话 | 0379-69926675-801 | ||
技术支持邮件 | Gingko@vip.163.com | ||
版本 | 日期 | 作者 | 修改内容 |
---|---|---|---|
V1.0 | 2019-02-22 | gingko | 初次建立 |
1.在主界面选择File–>New Project 或者直接点击ACCEE TO MCU SELECTOR 2.出现芯片型号选择,搜索自己芯片的型号,双击型号,或者点击Start Project进入配置 在搜索栏的下面,提供的各 种查找方式,可以选择芯片内核,型号,等等,可以帮助你查找芯片。本实验选取的芯片型号为:STM32H750IBKx。 3.配置RCC,使用外部时钟源 4.时基源选择SysTick 5.将PA10设置为GPIO_Output 6.引脚模式配置 7.设置串口 8.在NVIC Settings一栏使能接收中断 9.配置ADC 10.时钟源设置,选择外部高速时钟源,配置为最大主频 11.工程文件的设置, 这里就是工程的各种配置 我们只用到有限几个,其他的默认即可 IDE我们使用的是 MDK V5.27 12.点击Code Generator,进行进一步配置
int main(void) { HAL_Init(); SystemClock_Config(); i2c.initialize(); axp152.initialize(); axp152.set_dcdc1(3500);//[ARM & FPGA BK1/2/6 &OTHER] axp152.set_dcdc2(1200);//[FPGA INT & PLL D] axp152.set_aldo1(2500);//[FPGA PLL A] axp152.set_dcdc4(3300);//[POWER_OUTPUT] axp152.set_dcdc3(3300);//[FPGA BK4][Adjustable] axp152.set_aldo2(3300);//[FPGA BK3][Adjustable] axp152.set_dldo1(3300);//[FPGA BK7][Adjustable] axp152.set_dldo2(3300);//[FPGA BK5][Adjustable] MX_GPIO_Init(); MX_USART2_UART_Init(); MX_ADC1_Init(); /* USER CODE BEGIN 2 */ usart2.initialize(115200); while (1) { if(systick._500ms_flag == 1){ systick._500ms_flag = 0; LED_ON; my_adc.read(0); usart2.printf("\x0c"); usart2.printf("\033[1;32;40m"); usart2.printf("Hello,I am iCore4T!\r\n\r\n"); usart2.printf("[V ] %4.2fV\r\n",my_adc.value[0] * 6); //打印输入电源电压值 LED_OFF; } }
void MX_ADC1_Init(void) { ADC_MultiModeTypeDef multimode = {0}; ADC_ChannelConfTypeDef sConfig = {0}; hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV16; hadc1.Init.Resolution = ADC_RESOLUTION_16B; //ADC转换分辨率16位 hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; //非扫描模式 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; //关闭 EOC 中断 hadc1.Init.LowPowerAutoWait = DISABLE; //自动低功耗关闭 hadc1.Init.ContinuousConvMode = DISABLE; //关闭连续转换 hadc1.Init.NbrOfConversion = 1; hadc1.Init.DiscontinuousConvMode = DISABLE; //禁止不连续采样模式 hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; //软件触发 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; //禁止触发检测 hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR; hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; //过采样关闭 hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE; hadc1.Init.OversamplingMode = DISABLE; if (HAL_ADC_Init(&hadc1) != HAL_OK) { Error_Handler(); } multimode.Mode = ADC_MODE_INDEPENDENT; if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK) { Error_Handler(); } sConfig.Channel = ADC_CHANNEL_16; //通道16 sConfig.Rank = ADC_REGULAR_RANK_1; //第 1 个序列 sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; //采样时间 sConfig.SingleDiff = ADC_SINGLE_ENDED; sConfig.OffsetNumber = ADC_OFFSET_NONE; sConfig.Offset = 0; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); } }
int read(int channel) { int i; unsigned long int temp = 0; unsigned short int data[50]; ADC_ChannelConfTypeDef channel_config; int channel_remap[2] = {ADC_CHANNEL_16,ADC_CHANNEL_1}; channel_config.Channel = channel_remap[channel]; channel_config.Offset = 0; channel_config.Rank = ADC_REGULAR_RANK_1; channel_config.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; channel_config.SingleDiff = ADC_SINGLE_ENDED; channel_config.OffsetNumber = ADC_OFFSET_NONE; for(i = 0;i < 50;i ++){ if(channel == 0){ HAL_ADC_ConfigChannel(&hadc1,&channel_config); HAL_ADC_Start(&hadc1); while(!__HAL_ADC_GET_FLAG(&hadc1,ADC_FLAG_EOC)); data[i] = HAL_ADC_GetValue(&hadc1); } } sort(data,50); for(i = 20;i < 30;i++){ temp += data[i]; } temp = temp / 10; if(channel == 0){ my_adc.value[channel] = temp * ADC_REF / 65536; } return temp; }