#include "stm32f10x.h" #include "stm32f10x_gpio.h" #include "stm32f10x_rcc.h" #include "stm32f10x_usart.h" #include "stm32f10x_adc.h" #include "stdio.h" #include "misc.h" //void usart_init(void) //{ // /* Enable USART1 and GPIOA clock */ // RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE); // /* Configure the GPIOs */ // GPIO_InitTypeDef GPIO_InitStructure; // /* Configure USART1 Tx (PA.09) as alternate function push-pull */ // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // GPIO_Init(GPIOA, &GPIO_InitStructure); // /* Configure USART1 Rx (PA.10) as input floating */ // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; // GPIO_Init(GPIOA, &GPIO_InitStructure); // /* Configure the USART1 */ // USART_InitTypeDef USART_InitStructure; // /* USART1 configuration ------------------------------------------------------*/ // /* USART1 configured as follow: // - BaudRate = 115200 baud // - Word Length = 8 Bits // - One Stop Bit // - No parity // - Hardware flow control disabled (RTS and CTS signals) // - Receive and transmit enabled // - USART Clock disabled // - USART CPOL: Clock is active low // - USART CPHA: Data is captured on the middle // - USART LastBit: The clock pulse of the last data bit is not output to // the SCLK pin // */ // USART_InitStructure.USART_BaudRate = 115200; // USART_InitStructure.USART_WordLength = USART_WordLength_8b; // USART_InitStructure.USART_StopBits = USART_StopBits_1; // USART_InitStructure.USART_Parity = USART_Parity_No; // USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; // USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; // USART_Init(USART1, &USART_InitStructure); // /* Enable USART1 */ // USART_Cmd(USART1, ENABLE); // /* Enable the USART1 Receive interrupt: this interrupt is generated when the // USART1 receive data register is not empty */ // //USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //} //void USARTSend(char *pucBuffer) //{ // while (*pucBuffer) // { // USART_SendData(USART1, *pucBuffer++); // while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) // { // } // } //} //void SetSysClockTo72(void) //{ // ErrorStatus HSEStartUpStatus; // /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/ // /* RCC system reset(for debug purpose) */ // RCC_DeInit(); // /* Enable HSE */ // RCC_HSEConfig( RCC_HSE_ON); // /* Wait till HSE is ready */ // HSEStartUpStatus = RCC_WaitForHSEStartUp(); // if (HSEStartUpStatus == SUCCESS) // { // /* Enable Prefetch Buffer */ // //FLASH_PrefetchBufferCmd( FLASH_PrefetchBuffer_Enable); // /* Flash 2 wait state */ // //FLASH_SetLatency( FLASH_Latency_2); // /* HCLK = SYSCLK */ // RCC_HCLKConfig( RCC_SYSCLK_Div1); // /* PCLK2 = HCLK */ // RCC_PCLK2Config( RCC_HCLK_Div1); // /* PCLK1 = HCLK/2 */ // RCC_PCLK1Config( RCC_HCLK_Div2); // /* PLLCLK = 8MHz * 9 = 72 MHz */ // RCC_PLLConfig(0x00010000, RCC_PLLMul_9); // /* Enable PLL */ // RCC_PLLCmd( ENABLE); // /* Wait till PLL is ready */ // while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) // { // } // /* Select PLL as system clock source */ // RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK); // /* Wait till PLL is used as system clock source */ // while (RCC_GetSYSCLKSource() != 0x08) // { // } // } // else // { /* If HSE fails to start-up, the application will have wrong clock configuration. // User can add here some code to deal with this error */ // /* Go to infinite loop */ // while (1) // { // } // } //} //================================================================================= void ADC_Injected_init(void) { GPIO_InitTypeDef GPIO_InitStructure; ADC_InitTypeDef ADC_InitStructure; RCC_ADCCLKConfig (RCC_PCLK2_Div6); /* Enable ADC1 and GPIOA clock */ RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOA | RCC_APB2Periph_ADC1 , ENABLE ) ; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_NbrOfChannel = 2; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_Init(ADC1, &ADC_InitStructure); ADC_InjectedSequencerLengthConfig(ADC1, 2); ADC_InjectedChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_7Cycles5); ADC_InjectedChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_7Cycles5); ADC_ExternalTrigInjectedConvConfig( ADC1, ADC_ExternalTrigInjecConv_None ); ADC_Cmd ( ADC1 , ENABLE ) ; ADC_ResetCalibration(ADC1); while(ADC_GetResetCalibrationStatus(ADC1)); ADC_StartCalibration(ADC1); while(ADC_GetCalibrationStatus(ADC1)); ADC_AutoInjectedConvCmd( ADC1, ENABLE ); ADC_SoftwareStartInjectedConvCmd ( ADC1 , ENABLE ) ; } //================================================================================= int main(void) { char buffer[80] = {'\0'}; uint16_t ADC_value0, ADC_value1; // SetSysClockTo72(); //USART // usart_init(); //ADC ADC_Injected_init(); while (1) { ADC_value0 = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1); ADC_value1 = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_2); sprintf(buffer, "%d : %d\r\n", ADC_value0, ADC_value1); // USARTSend(buffer); } } BAP-Özgeçmiş