반응형
Notice
Recent Posts
Recent Comments
Link
Brise
STM32F401RE-nucleo Standard Peripheral ADC 본문
반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include "stm32f4xx.h" __IO uint16_t verti; __IO float v = 0.0f; int main(void) { GPIO_InitTypeDef GPIO_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; ADC_InitTypeDef ADC_InitStructure; RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE); GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOA, &GPIO_InitStructure); ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div8; ADC_CommonInit(&ADC_CommonInitStructure); RCC_APB2PeriphClockCmd (RCC_APB2Periph_ADC1, ENABLE); ADC_StructInit(&ADC_InitStructure); ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init(ADC1, &ADC_InitStructure); ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_3Cycles); ADC_Cmd (ADC1,ENABLE); //enable ADC1 while(1) { ADC_SoftwareStartConv(ADC1); // start ONE conversion while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET) {} verti=ADC_GetConversionValue(ADC1); v = (float)verti/4096.0f*3.3f; } } | cs |
반응형
'MCU' 카테고리의 다른 글
IAR EWARM에서 stm32 SWO로 printf 사용하기 (0) | 2018.03.20 |
---|---|
Eclipse 기반의 AVR 개발 환경 구축하기 (0) | 2018.03.16 |
HAL SPI DMA 코드 (0) | 2017.12.24 |
STM32F401RE-nucleo CMSIS ADC (0) | 2017.12.07 |
STM32F411RE-nucleo UART 데이터 중계 예제 (0) | 2017.12.05 |
STM32F411RE-nucleo Printf 예제 (0) | 2017.12.05 |
STM32F411RE-nucleo Standard Peripheral UART 예제 (0) | 2017.12.05 |
Comments