void initial_opa(void) { OPAMP_InitTypeDef OPAMP_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); //OPA1 OPAMP_InitStructure.OPAMP_NonInvertingInput = OPAMP_NonInvertingInput_IO4; OPAMP_InitStructure.OPAMP_InvertingInput = OPAMP_InvertingInput_Vout; OPAMP_Init(OPAMP_Selection_OPAMP1, &OPAMP_InitStructure); OPAMP_PGAConfig(OPAMP_Selection_OPAMP1, OPAMP_OPAMP_PGAGain_2, OPAMP_PGAConnect_No); //OPA2 OPAMP_InitStructure.OPAMP_NonInvertingInput = OPAMP_NonInvertingInput_IO3; OPAMP_Init(OPAMP_Selection_OPAMP2, &OPAMP_InitStructure); OPAMP_PGAConfig(OPAMP_Selection_OPAMP2, OPAMP_OPAMP_PGAGain_2, OPAMP_PGAConnect_No); //OPA3 OPAMP_InitStructure.OPAMP_NonInvertingInput = OPAMP_NonInvertingInput_IO1; OPAMP_Init(OPAMP_Selection_OPAMP3, &OPAMP_InitStructure); OPAMP_PGAConfig(OPAMP_Selection_OPAMP3, OPAMP_OPAMP_PGAGain_2, OPAMP_PGAConnect_No); //OPA4 OPAMP_InitStructure.OPAMP_NonInvertingInput = OPAMP_NonInvertingInput_IO1; OPAMP_Init(OPAMP_Selection_OPAMP4, &OPAMP_InitStructure); OPAMP_PGAConfig(OPAMP_Selection_OPAMP4, OPAMP_OPAMP_PGAGain_2, OPAMP_PGAConnect_No); OPAMP_Cmd(OPAMP_Selection_OPAMP1, ENABLE); OPAMP_Cmd(OPAMP_Selection_OPAMP2, ENABLE); OPAMP_Cmd(OPAMP_Selection_OPAMP3, ENABLE); OPAMP_Cmd(OPAMP_Selection_OPAMP4, ENABLE); }
/** * @brief OPAMP configuration. * @param None * @retval None */ static void OPAMP_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; OPAMP_InitTypeDef OPAMP_InitStructure; /* GPIOA Peripheral clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Configure OPAMP1 non inverting input IO1 (PA7) and OPAMP1 Out (PA2) in analog mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Enable SYSCFG clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); /* Select Vout as inverting input (internal follower) for OPAMP1 */ OPAMP_InitStructure.OPAMP_InvertingInput = OPAMP_InvertingInput_Vout; /* Select IO1 (PA7) as non inverting input for OPAMP1 */ OPAMP_InitStructure.OPAMP_NonInvertingInput = OPAMP_NonInvertingInput_IO1; OPAMP_Init(OPAMP_Selection_OPAMP1, &OPAMP_InitStructure); /* Enable OPAMP1 */ OPAMP_Cmd(OPAMP_Selection_OPAMP1, ENABLE); }