void f3d_uart_init(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC,&GPIO_InitStructure); GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC , &GPIO_InitStructure); GPIO_PinAFConfig(GPIOC,4,GPIO_AF_7); GPIO_PinAFConfig(GPIOC,5,GPIO_AF_7); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); USART_StructInit(&USART_InitStructure); USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART1 ,&USART_InitStructure); USART_Cmd(USART1 , ENABLE); // Initialize the rx and tx queues init_queue(&rxbuf); init_queue(&txbuf); // Setup the NVIC priority and subpriority NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x08; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x08; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // Enable the RX interrupt USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); }
void DacInit(void) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); DAC_InitTypeDef DAC_InitStructure; DAC_StructInit(&DAC_InitStructure); DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); DAC_Cmd(DAC_Channel_1, ENABLE); DAC_SetChannel1Data(DAC_Align_12b_R, DAC_ZERO); }
// TODO: Verify pins setting needed for RX and TX inline void STM32_M0_UART::init_gpio(void) { GPIO_InitTypeDef GPIO; // Enable GPIO clock RCC_AHBPeriphClockCmd(USART_TX_GPIO_CLK | USART_RX_GPIO_CLK, ENABLE); // Configure USART Tx and Rx as alternate function push-pull GPIO_StructInit(&GPIO); //TX GPIO.GPIO_Pin = USART_TX_PIN; GPIO.GPIO_Mode = GPIO_Mode_AF; GPIO.GPIO_Speed = GPIO_Speed_2MHz; GPIO.GPIO_OType = GPIO_OType_PP; GPIO.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(USART_TX_GPIO_PORT, &GPIO); //RX GPIO.GPIO_Pin = USART_RX_PIN; GPIO.GPIO_Mode = GPIO_Mode_AF; GPIO.GPIO_Speed = GPIO_Speed_2MHz; GPIO.GPIO_OType = GPIO_OType_PP; GPIO.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(USART_RX_GPIO_PORT, &GPIO); // Connect USART pins to AF GPIO_PinAFConfig(USART_TX_GPIO_PORT, USART_TX_SOURCE, USART_TX_AF); GPIO_PinAFConfig(USART_RX_GPIO_PORT, USART_RX_SOURCE, USART_RX_AF); }
static void BSP_ADC_Init (void) { ADC_InitTypeDef adc_init; GPIO_InitTypeDef gpio_init; RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_StructInit(&gpio_init); gpio_init.GPIO_Pin = GPIO_Pin_0; gpio_init.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOB, &gpio_init); adc_init.ADC_Mode = ADC_Mode_Independent; adc_init.ADC_ScanConvMode = DISABLE; adc_init.ADC_ContinuousConvMode = ENABLE; adc_init.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; adc_init.ADC_DataAlign = ADC_DataAlign_Right; adc_init.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &adc_init); ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_13Cycles5); ADC_Cmd(ADC1, ENABLE); ADC_SoftwareStartConvCmd(ADC1, ENABLE); }
/** * @brief Configures COMP1: DAC channel 1 to COMP1 inverting input * and COMP1 output to TIM2 IC4. * @param None * @retval None */ void COMP_Config(void) { /* Init Structure definition */ COMP_InitTypeDef COMP_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* GPIOA Peripheral clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Configure PA1: PA1 is used as COMP1 non inveting input */ 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); /* COMP Peripheral clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); /* COMP1 Init: DAC1 output is used COMP1 inverting input */ COMP_StructInit(&COMP_InitStructure); COMP_InitStructure.COMP_InvertingInput = COMP_InvertingInput_DAC1; /* Redirect COMP1 output to TIM2 Input capture 4 */ COMP_InitStructure.COMP_Output = COMP_Output_TIM2IC4; COMP_InitStructure.COMP_Mode = COMP_Mode_HighSpeed; COMP_InitStructure.COMP_Hysteresis = COMP_Hysteresis_No; COMP_Init(COMP_Selection_COMP1, &COMP_InitStructure); /* Enable COMP1 */ COMP_Cmd(COMP_Selection_COMP1, ENABLE); }
void LEDS_Init(void) { GPIO_InitTypeDef gpioE; // // Turn on clocks to GPIO E so we can drive the outputs // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE); // // Set up default values // GPIO_StructInit(&gpioE); // // Make pins 8-15 outputs since they are connected to the LEDS // gpioE.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 |GPIO_Pin_14 | GPIO_Pin_15; gpioE.GPIO_Mode = GPIO_Mode_OUT; // // Initialize the hardware // GPIO_Init(GPIOE, &gpioE); return; }
void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); // Set all as default GPIO_Init(PORTA, &GPIO_InitStructure); GPIO_Init(PORTB, &GPIO_InitStructure); GPIO_Init(PORTC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = LED1_PIN; GPIO_Init(LED1_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = LED2_PIN; GPIO_Init(LED2_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = WIZ_RESET_PIN; GPIO_Init(WIZ_RESET_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = WIZ_PWDN_PIN; GPIO_Init(WIZ_PWDN_PORT, &GPIO_InitStructure); //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // For IIN Chip EXTI //GPIO_InitStructure.GPIO_Pin = WIZ_INT_PIN; //GPIO_Init(WIZ_INT_PORT, &GPIO_InitStructure); wizpf_led_set(WIZ_LED1, VAL_OFF); wizpf_led_set(WIZ_LED2, VAL_OFF); GPIO_SetBits(WIZ_RESET_PORT, WIZ_RESET_PIN); GPIO_ResetBits(WIZ_PWDN_PORT, WIZ_PWDN_PIN); // ToDo }
void TEST_INIT(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(LED_GPIO_RCC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Pin = LED1; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(LED_GPIO, &GPIO_InitStructure); GPIO_SetBits(LED_GPIO,LED1); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_14|GPIO_Pin_15; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(LED_GPIO, &GPIO_InitStructure); GPIO_SetBits(LED_GPIO,GPIO_Pin_12); GPIO_SetBits(LED_GPIO,GPIO_Pin_14); GPIO_SetBits(LED_GPIO,GPIO_Pin_15); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); }
void USART1_init(int baudrate) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; /*Enable peripheral clock for GPIOA*/ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); /*Enable peripheral clock for UART1*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); /*GPIOA Configuration PA9 as TX PA10 as RX*/ GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9|GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP; GPIO_Init(GPIOA,&GPIO_InitStructure); /*Connect USART2 pins to AF7*/ //PA9=USART1_TX //PA10=USART1_RX GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_7); GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_7); USART_StructInit(&USART_InitStructure); USART_InitStructure.USART_BaudRate=baudrate; 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_Tx|USART_Mode_Rx; USART_Init(USART1,&USART_InitStructure); USART_Cmd(USART1,ENABLE); }
void fdi_i2c_initialize(void) { RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); GPIO_InitTypeDef GPIO_InitStruct; GPIO_StructInit(&GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7 /* SCL */| GPIO_Pin_8 /* SDA */; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_OType = GPIO_OType_OD; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStruct); GPIO_PinAFConfig(GPIOB, GPIO_PinSource8 /* SCL */, GPIO_AF_I2C1); GPIO_PinAFConfig(GPIOB, GPIO_PinSource7 /* SDA */, GPIO_AF_I2C1); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); I2C_InitTypeDef I2C_InitStruct; I2C_StructInit(&I2C_InitStruct); I2C_InitStruct.I2C_ClockSpeed = 100000; I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStruct.I2C_OwnAddress1 = 0x00; I2C_InitStruct.I2C_Ack = I2C_Ack_Disable; I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_Init(I2C1, &I2C_InitStruct); I2C_Cmd(I2C1, ENABLE); }
void f3d_i2c1_init() { GPIO_InitTypeDef GPIO_InitStructure; I2C_InitTypeDef I2C_InitStructure; SPI_InitTypeDef SPI_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE); // Enable the clock to the I2C peripheral RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); // Port B - SDA (7) and SCL (6) GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB , &GPIO_InitStructure); GPIO_PinAFConfig(GPIOB, 6, GPIO_AF_4); GPIO_PinAFConfig(GPIOB, 7, GPIO_AF_4); // I2C GPIO Initialization and Alternate Function Selection I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable; I2C_InitStructure.I2C_DigitalFilter = 0x00; I2C_InitStructure.I2C_OwnAddress1 = 0x00; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_Timing = 0x00902025; I2C_Init(I2C1, &I2C_InitStructure); I2C_Cmd(I2C1, ENABLE); }
void Sensor_Configuration(void) { ADC_CommonInitTypeDef ADC_CommonInitStructure; GPIO_InitTypeDef GPIO_InitStructure; SensorGPIO_Configuration(); DMA2_Configuration(); GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOA, &GPIO_InitStructure); ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles; ADC_CommonInit(&ADC_CommonInitStructure); ADC1_Config(); ADC2_Config(); ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE); ADC_Cmd(ADC1, ENABLE); ADC_Cmd(ADC2, ENABLE); ADC_DMACmd(ADC1, ENABLE); ADC_SoftwareStartConv(ADC1); }
void GPIO_Configuration(void) { { GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); // Set all as default GPIO_Init(PORTA, &GPIO_InitStructure); GPIO_Init(PORTB, &GPIO_InitStructure); GPIO_Init(PORTC, &GPIO_InitStructure); } #ifdef LED1_PIN GPIO_INIT_SIMP(GPIO_Mode_Out_PP, LED1_PORT, LED1_PIN); wizpf_led_set(WIZ_LED1, VAL_OFF); #endif #ifdef LED2_PIN GPIO_INIT_SIMP(GPIO_Mode_Out_PP, LED2_PORT, LED2_PIN); wizpf_led_set(WIZ_LED2, VAL_OFF); #endif #ifdef WIZ_RESET_PIN GPIO_INIT_SIMP(GPIO_Mode_Out_PP, WIZ_RESET_PORT, WIZ_RESET_PIN); GPIO_SetBits(WIZ_RESET_PORT, WIZ_RESET_PIN); #endif #ifdef WIZ_PWDN_PIN GPIO_INIT_SIMP(GPIO_Mode_Out_PP, WIZ_PWDN_PORT, WIZ_PWDN_PIN); GPIO_ResetBits(WIZ_PWDN_PORT, WIZ_PWDN_PIN); #endif #ifdef WIZ_INT_PIN GPIO_INIT_SIMP(GPIO_Mode_IPU, WIZ_INT_PORT, WIZ_INT_PIN); // For IIN Chip EXTI #endif // ToDo }
void TIMER2_CH2_PWM_Init(int prescaler,int autoreload){ //USER LED / PB3 / TIM2_CH2 / AF1 RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOBEN ,ENABLE); GPIO_InitTypeDef myGPIO; GPIO_StructInit(&myGPIO); myGPIO.GPIO_Pin=GPIO_Pin_3; myGPIO.GPIO_Mode=GPIO_Mode_AF; myGPIO.GPIO_Speed=GPIO_Speed_10MHz; GPIO_Init(GPIOB,&myGPIO); GPIO_PinAFConfig(GPIOB,GPIO_PinSource3,GPIO_AF_1); //select the output mode by writing the CCS bits in the CCMRx register //Timer time base configuration RCC_APB1PeriphClockCmd(RCC_APB1ENR_TIM2EN,ENABLE); TIM_TimeBaseInitTypeDef myTimeBase; TIM_TimeBaseStructInit(&myTimeBase); myTimeBase.TIM_CounterMode=TIM_CounterMode_Up; myTimeBase.TIM_Period=autoreload; myTimeBase.TIM_Prescaler=prescaler; myTimeBase.TIM_ClockDivision= TIM_CKD_DIV1; TIM_TimeBaseInit(TIM2,&myTimeBase); //Timer capture compare configuration TIM_OCInitTypeDef myTimerOC; TIM_OCStructInit(&myTimerOC); myTimerOC.TIM_OCMode=TIM_OCMode_PWM1; myTimerOC.TIM_OCPolarity=TIM_OCPolarity_High; myTimerOC.TIM_OutputState=TIM_OutputState_Enable; myTimerOC.TIM_Pulse=autoreload;//0 Duty cycle at start TIM_OC2Init(TIM2,&myTimerOC); TIM_CCxCmd(TIM2,TIM_Channel_2,TIM_CCx_Enable);//enable CCP2 //start Timer TIM_Cmd(TIM2,ENABLE);//Counter enabled }
void ADC1_Config(void) { ADC_InitTypeDef ADC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIO ports B */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); /* ADC1 Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* Configure Pin & Port as input push-pull for ADC channel 1 usage */ GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_PIN_ADCin1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIO_PORT_ADCin1, &GPIO_InitStructure); /* Reset ADC to default values */ ADC_DeInit(); /* ADC1 Configuration */ ADC_StructInit(&ADC_InitStructure); ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init(ADC1, &ADC_InitStructure); ADC_Cmd(ADC1, ENABLE); }
void enableGPIOPowerUsageAndNoiseReductions(void) { RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOF, ENABLE ); GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Pin &= ~(GPIO_Pin_13 | GPIO_Pin_14); // leave JTAG pins alone GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOE, &GPIO_InitStructure); }
void EINT_Config(void) { GPIO_StructInit(&GPIO_InitStructure1); GPIO_InitStructure1.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure1.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOG, &GPIO_InitStructure1); //SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0); EXTI_InitTypeDef EXTI_InitStructure; EXTI_StructInit(&EXTI_InitStructure); EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); NVIC_InitTypeDef NVIC_InitStructure1; NVIC_InitStructure1.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure1.NVIC_IRQChannelPreemptionPriority = 0x01; NVIC_InitStructure1.NVIC_IRQChannelSubPriority = 0x01; NVIC_InitStructure1.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure1); }
void Battery::initialize(){ GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC|RCC_APB2Periph_ADC1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOCEN,ENABLE); ADC_DeInit(); ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; ADC_CommonInit(&ADC_CommonInitStructure); ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init(ADC1, &ADC_InitStructure); ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_112Cycles); ADC_Cmd(ADC1, ENABLE); ADC_DMACmd(ADC1,DISABLE); }
void adcInit() { GPIO_InitTypeDef GPIO_InitStruct; ADC_CommonInitTypeDef ADC_CommonInitStruct; ADC_InitTypeDef ciguMigu; RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_StructInit(&GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStruct); ADC_CommonStructInit(&ADC_CommonInitStruct); ADC_CommonInitStruct.ADC_Prescaler = ADC_Prescaler_Div4; ADC_CommonInit(&ADC_CommonInitStruct); ADC_StructInit(&ciguMigu); ciguMigu.ADC_Resolution = ADC_Resolution_10b; ADC_Init(ADC1, &ciguMigu); ADC_Cmd(ADC1, ENABLE); ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_480Cycles); }
void nRF24L01_spi_init() { RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); GPIO_InitTypeDef gpio; GPIO_StructInit(&gpio); gpio.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; gpio.GPIO_Mode = GPIO_Mode_AF; gpio.GPIO_Speed = GPIO_Speed_100MHz; gpio.GPIO_OType = GPIO_OType_PP; gpio.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC,&gpio); GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SPI3); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE); SPI_InitTypeDef spi1; SPI_StructInit(&spi1); spi1.SPI_Mode = SPI_Mode_Master; spi1.SPI_DataSize = SPI_DataSize_8b; spi1.SPI_NSS = SPI_NSS_Soft; spi1.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32; SPI_Init(SPI3,&spi1); SPI_Cmd(SPI3,ENABLE); }
/******************************************************************************* * Function Name : GPIO_Configuration * Description : Configures the different GPIO ports. * Input : None * Output : None * Return : None *******************************************************************************/ void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); // PORTB CONFIG GPIO_InitStructure.GPIO_Pin = PIN_ENABLE_TXD | PIN_ENABLE_RXD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = PIN_DXL_RXD | PIN_PC_RXD; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = PIN_DXL_TXD | PIN_PC_TXD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_PinRemapConfig( GPIO_Remap_USART1, ENABLE); GPIO_PinRemapConfig( GPIO_Remap_SWJ_Disable, ENABLE); GPIO_ResetBits(PORT_ENABLE_TXD, PIN_ENABLE_TXD); // TX Disable GPIO_SetBits(PORT_ENABLE_RXD, PIN_ENABLE_RXD); // RX Enable }
void init_debug_usart_lib() { GPIO_InitTypeDef gpio; USART_InitTypeDef usart; RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); GPIO_StructInit(&gpio); gpio.GPIO_Mode = GPIO_Mode_AF; gpio.GPIO_Pin = GPIO_Pin_5; gpio.GPIO_Speed = GPIO_Speed_50MHz; gpio.GPIO_OType = GPIO_OType_PP; gpio.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOD, &gpio); GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2); USART_StructInit(&usart); usart.USART_Mode = USART_Mode_Tx; usart.USART_BaudRate = 9600; usart.USART_HardwareFlowControl = USART_HardwareFlowControl_None; usart.USART_WordLength = USART_WordLength_8b; usart.USART_StopBits = USART_StopBits_1; usart.USART_Parity = USART_Parity_No; USART_Init(USART2, &usart); USART2->BRR = 0x0000016d; USART_Cmd(USART2, ENABLE); }
/* initialize the encoder */ void init_encoder(void){ GPIO_InitTypeDef GPIO_InitStruct; //Enable GPIO clock RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_StructInit(&GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin = ENCODER_LEFT_A_PIN | ENCODER_RIGHT_A_PIN | ENCODER_LEFT_B_PIN | ENCODER_RIGHT_B_PIN; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(ENCODER_PORT, &GPIO_InitStruct); resetEncoder(&ENCODER_L); resetEncoder(&ENCODER_R); ENCODER_L.phaseA = ENCODER_LEFT_A_PIN; ENCODER_L.phaseB = ENCODER_LEFT_B_PIN; ENCODER_R.phaseA = ENCODER_RIGHT_A_PIN; ENCODER_R.phaseB = ENCODER_RIGHT_B_PIN; init_encoder_exti(EXTI_PinSource0, EXTI0_IRQn, EXTI_Line0); init_encoder_exti(EXTI_PinSource1, EXTI1_IRQn, EXTI_Line1); init_encoder_exti(EXTI_PinSource2, EXTI2_IRQn, EXTI_Line2); init_encoder_exti(EXTI_PinSource3, EXTI3_IRQn, EXTI_Line3); /* get encoder data every period */ //EncoderTimer = xTimerCreate("Encoder Polling", (ENCODER_PERIOD), pdTRUE, (void *) 1, Encoder_Polling); //xTimerStart(EncoderTimer, 0); }
void Initialize_ADC(void) { ADC_InitTypeDef ADC_InitStruct; GPIO_InitTypeDef GPIO_InitStruct; GPIO_StructInit(&GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin = 0x01; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStruct); ADC_DeInit(); ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b; ADC_InitStruct.ADC_ContinuousConvMode = ENABLE; ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStruct.ADC_NbrOfConversion = 1; ADC_InitStruct.ADC_ScanConvMode = DISABLE; ADC_Init(ADC1, &ADC_InitStruct); ADC_Cmd(ADC1, ENABLE); ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_144Cycles); //InitializeTimer(); }
/** * @brief Configures COMP2: PA3 as COMP2 non inverting input * VREFINT as COMP2 inverting input * and COMP2 output to TIM2 BKIN. * @param None * @retval None */ void COMP_Config(void) { COMP_InitTypeDef COMP_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* GPIOA Peripheral clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Configure PA3 in analog mode: PA3 is connected to COMP2 non inverting input */ GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* COMP Peripheral clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); /* COMP2 config */ COMP_StructInit(&COMP_InitStructure); COMP_InitStructure.COMP_InvertingInput = COMP_InvertingInput_VREFINT; COMP_InitStructure.COMP_Output = COMP_Output_TIM1BKIN; COMP_InitStructure.COMP_Hysteresis = COMP_Hysteresis_No; COMP_InitStructure.COMP_Mode = COMP_Mode_UltraLowPower; COMP_InitStructure.COMP_OutputPol = COMP_OutputPol_NonInverted; COMP_Init(COMP_Selection_COMP2, &COMP_InitStructure); /* Enable COMP2 */ COMP_Cmd(COMP_Selection_COMP2, ENABLE); }
/************************************************************************* * Description: Initialize the LED hardware * Returns: none * Notes: none *************************************************************************/ void led_init( void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); /* Configure the Receive LED on MS/TP board */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure the Transmit LED on MS/TP board */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /* Configure the LD4 on Discovery board */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure the LD3 on Discovery board */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Enable the GPIO_LED Clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); led_tx_on(); led_rx_on(); led_ld3_on(); led_ld4_on(); }
//key static void BSP_PB_Init (void) { GPIO_InitTypeDef gpio_init; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); GPIO_StructInit(&gpio_init); gpio_init.GPIO_Pin = BSP_KEY1; gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &gpio_init); GPIO_StructInit(&gpio_init); gpio_init.GPIO_Pin = BSP_KEY2; gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &gpio_init); }
/** * @brief This function initialises quadrature encoder input to capture AB phase output from ENB encoder. * @param void * @retval void * @brief * PB4 --> TIM3 CH1 * PB5 --> TIM3 CH2 */ void QEI1_init (void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_ICInitTypeDef TIM_ICInitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* TIM3 clock source enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); /* Enable GPIOB, clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); GPIO_StructInit(&GPIO_InitStructure); /* Configure PB.4,5 as encoder alternate function */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Connect TIM3 pins to AF2 */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_TIM3); GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_TIM3); /* Enable the TIM3 Update Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Timer configuration in Encoder mode */ TIM_DeInit(TIM3); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Prescaler = 0x0; // No prescaling TIM_TimeBaseStructure.TIM_Period = (4*4000)-1; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising); TIM_ICStructInit(&TIM_ICInitStructure); TIM_ICInitStructure.TIM_ICFilter = 6; TIM_ICInit(TIM3, &TIM_ICInitStructure); // Clear all pending interrupts TIM_ClearFlag(TIM3, TIM_FLAG_Update); TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE); //Reset counter TIM3->CNT = 0; //encoder value TIM_Cmd(TIM3, ENABLE); }
void GPIO_Configuration(void) { { GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); // Set all as default GPIO_Init(PORTA, &GPIO_InitStructure); GPIO_Init(PORTB, &GPIO_InitStructure); GPIO_Init(PORTC, &GPIO_InitStructure); } #ifdef LED1_PIN wizpf_gpio_init(LED1_PORT, LED1_PIN, GMOD_OUT_PUSHPULL); wizpf_led_set(WIZ_LED1, VAL_OFF); #endif #ifdef LED2_PIN wizpf_gpio_init(LED2_PORT, LED2_PIN, GMOD_OUT_PUSHPULL); wizpf_led_set(WIZ_LED2, VAL_OFF); #endif #ifdef WIZ_RESET_PIN wizpf_gpio_init(WIZ_RESET_PORT, WIZ_RESET_PIN, GMOD_OUT_PUSHPULL); GPIO_SetBits(WIZ_RESET_PORT, WIZ_RESET_PIN); #endif #ifdef WIZ_PWDN_PIN wizpf_gpio_init(WIZ_PWDN_PORT, WIZ_PWDN_PIN, GMOD_OUT_PUSHPULL); GPIO_ResetBits(WIZ_PWDN_PORT, WIZ_PWDN_PIN); #endif #ifdef WIZ_INT_PIN wizpf_gpio_init(WIZ_INT_PORT, WIZ_INT_PIN, GMOD_IN_PULLUP); // For IIN Chip EXTI #endif // ToDo }
int main(void) { ledval = 0; GPIO_InitTypeDef GPIO_InitStruct; //Enable Our Clock for the GPIO Pins RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // Configure Pins. Currently, PortA, Pins 0-7, Push-Pull Output GPIO_StructInit(&GPIO_InitStruct); //Get everything all nice and clean GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; // Push Pull Output GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; //Choose the lowest acceptable speed GPIO_Init(GPIOA, &GPIO_InitStruct); // Configure SysTick // if ( SysTick_Config(SystemCoreClock / 1000)) // while(1); while(1){ //GPIO_SetBits(GPIOA, 0xFF & ledval); GPIO_WriteBit(GPIOA,GPIO_Pin_0, (ledval & 0x01 == 1) ? Bit_SET : Bit_RESET); ledval++; Delay(1500000); //Delay a lot } }