📄 stm32l1xx_opamp.c
字号:
OPAMP->CSR |= OPAMP_Trimming;
}
/**
* @brief Configure the trimming value of OPAMPs in normal mode.
* @param OPAMP_Selection: the selected OPAMP.
* This parameter can be one of the following values:
* @arg OPAMP_Selection_OPAMP1: OPAMP1 is selected to configure the trimming value.
* @arg OPAMP_Selection_OPAMP2: OPAMP2 is selected to configure the trimming value.
* @arg OPAMP_Selection_OPAMP3: OPAMP3 is selected to configure the trimming value.
* @param OPAMP_Input: the selected OPAMP input.
* This parameter can be one of the following values:
* @arg OPAMP_Input_NMOS: NMOS input is selected to configure the trimming value.
* @arg OPAMP_Input_PMOS: PMOS input is selected to configure the trimming value.
* @param OPAMP_TrimValue: the trimming value. This parameter can be any value lower
* or equal to 0x0000001F.
* @retval None
*/
void OPAMP_OffsetTrimConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Input, uint32_t OPAMP_TrimValue)
{
uint32_t tmpreg = 0;
/* Check the parameter */
assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
assert_param(IS_OPAMP_INPUT(OPAMP_Input));
assert_param(IS_OPAMP_TRIMMINGVALUE(OPAMP_TrimValue));
/* Get the OPAMP_OTR value */
tmpreg = OPAMP->OTR;
if(OPAMP_Selection == OPAMP_Selection_OPAMP1)
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA1CAL_L | OPAMP_CSR_OPA1CAL_H);
/* Select the OPAMP input */
tmpreg |= OPAMP_Input;
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP1 PMOS input */
tmpreg &= (0xFFFFFFE0);
/* Set the new trimming value corresponding to OPAMP1 PMOS input */
tmpreg |= (OPAMP_TrimValue);
}
else
{
/* Reset the trimming value corresponding to OPAMP1 NMOS input */
tmpreg &= (0xFFFFFC1F);
/* Set the new trimming value corresponding to OPAMP1 NMOS input */
tmpreg |= (OPAMP_TrimValue<<5);
}
}
else if (OPAMP_Selection == OPAMP_Selection_OPAMP2)
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA2CAL_L | OPAMP_CSR_OPA2CAL_H);
/* Select the OPAMP input */
tmpreg |= (uint32_t)(OPAMP_Input<<8);
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP2 PMOS input */
tmpreg &= (0xFFFF83FF);
/* Set the new trimming value corresponding to OPAMP2 PMOS input */
tmpreg |= (OPAMP_TrimValue<<10);
}
else
{
/* Reset the trimming value corresponding to OPAMP2 NMOS input */
tmpreg &= (0xFFF07FFF);
/* Set the new trimming value corresponding to OPAMP2 NMOS input */
tmpreg |= (OPAMP_TrimValue<<15);
}
}
else
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA3CAL_L | OPAMP_CSR_OPA3CAL_H);
/* Select the OPAMP input */
tmpreg |= (uint32_t)(OPAMP_Input<<16);
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP3 PMOS input */
tmpreg &= (0xFE0FFFFF);
/* Set the new trimming value corresponding to OPAMP3 PMOS input */
tmpreg |= (OPAMP_TrimValue<<20);
}
else
{
/* Reset the trimming value corresponding to OPAMP3 NMOS input */
tmpreg &= (0xC1FFFFFF);
/* Set the new trimming value corresponding to OPAMP3 NMOS input */
tmpreg |= (OPAMP_TrimValue<<25);
}
}
/* Set the OPAMP_OTR register */
OPAMP->OTR = tmpreg;
}
/**
* @brief Configure the trimming value of OPAMPs in low power mode.
* @param OPAMP_Selection: the selected OPAMP.
* This parameter can be one of the following values:
* @arg OPAMP_Selection_OPAMP1: OPAMP1 is selected to configure the trimming value.
* @arg OPAMP_Selection_OPAMP2: OPAMP2 is selected to configure the trimming value.
* @arg OPAMP_Selection_OPAMP3: OPAMP3 is selected to configure the trimming value.
* @param OPAMP_Input: the selected OPAMP input.
* This parameter can be one of the following values:
* @arg OPAMP_Input_NMOS: NMOS input is selected to configure the trimming value.
* @arg OPAMP_Input_PMOS: PMOS input is selected to configure the trimming value.
* @param OPAMP_TrimValue: the trimming value.
* This parameter can be any value lower or equal to 0x0000001F.
* @retval None
*/
void OPAMP_OffsetTrimLowPowerConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Input, uint32_t OPAMP_TrimValue)
{
uint32_t tmpreg = 0;
/* Check the parameter */
assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
assert_param(IS_OPAMP_INPUT(OPAMP_Input));
assert_param(IS_OPAMP_TRIMMINGVALUE(OPAMP_TrimValue));
/* Get the OPAMP_LPOTR value */
tmpreg = OPAMP->LPOTR;
if(OPAMP_Selection == OPAMP_Selection_OPAMP1)
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA1CAL_L | OPAMP_CSR_OPA1CAL_H);
/* Select the OPAMP input */
tmpreg |= OPAMP_Input;
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP1 PMOS input */
tmpreg &= (0xFFFFFFE0);
/* Set the new trimming value corresponding to OPAMP1 PMOS input */
tmpreg |= (OPAMP_TrimValue);
}
else
{
/* Reset the trimming value corresponding to OPAMP1 NMOS input */
tmpreg &= (0xFFFFFC1F);
/* Set the new trimming value corresponding to OPAMP1 NMOS input */
tmpreg |= (OPAMP_TrimValue<<5);
}
}
else if (OPAMP_Selection == OPAMP_Selection_OPAMP2)
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA2CAL_L | OPAMP_CSR_OPA2CAL_H);
/* Select the OPAMP input */
tmpreg |= (uint32_t)(OPAMP_Input<<8);
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP2 PMOS input */
tmpreg &= (0xFFFF83FF);
/* Set the new trimming value corresponding to OPAMP2 PMOS input */
tmpreg |= (OPAMP_TrimValue<<10);
}
else
{
/* Reset the trimming value corresponding to OPAMP2 NMOS input */
tmpreg &= (0xFFF07FFF);
/* Set the new trimming value corresponding to OPAMP2 NMOS input */
tmpreg |= (OPAMP_TrimValue<<15);
}
}
else
{
/* Reset the OPAMP inputs selection */
tmpreg &= (uint32_t)~(OPAMP_CSR_OPA3CAL_L | OPAMP_CSR_OPA3CAL_H);
/* Select the OPAMP input */
tmpreg |= (uint32_t)(OPAMP_Input<<16);
if(OPAMP_Input == OPAMP_Input_PMOS)
{
/* Reset the trimming value corresponding to OPAMP3 PMOS input */
tmpreg &= (0xFE0FFFFF);
/* Set the new trimming value corresponding to OPAMP3 PMOS input */
tmpreg |= (OPAMP_TrimValue<<20);
}
else
{
/* Reset the trimming value corresponding to OPAMP3 NMOS input */
tmpreg &= (0xC1FFFFFF);
/* Set the new trimming value corresponding to OPAMP3 NMOS input */
tmpreg |= (OPAMP_TrimValue<<25);
}
}
/* Set the OPAMP_LPOTR register */
OPAMP->LPOTR = tmpreg;
}
/**
* @brief Checks whether the specified OPAMP calibration flag is set or not.
* @note User should wait until calibration flag change the value when changing
* the trimming value.
* @param OPAMP_Selection: the selected OPAMP.
* This parameter can be one of the following values:
* @arg OPAMP_Selection_OPAMP1: OPAMP1 is selected.
* @arg OPAMP_Selection_OPAMP2: OPAMP2 is selected.
* @arg OPAMP_Selection_OPAMP3: OPAMP3 is selected.
* @retval The new state of the OPAMP calibration flag (SET or RESET).
*/
FlagStatus OPAMP_GetFlagStatus(uint32_t OPAMP_Selection)
{
FlagStatus bitstatus = RESET;
uint32_t tmpreg = 0;
/* Check the parameter */
assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
/* Get the CSR register value */
tmpreg = OPAMP->CSR;
/* Check if OPAMP1 is selected */
if(OPAMP_Selection == OPAMP_Selection_OPAMP1)
{
/* Check OPAMP1 CAL bit status */
if ((tmpreg & OPAMP_CSR_OPA1CALOUT) != (uint32_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
}
/* Check if OPAMP2 is selected */
else if(OPAMP_Selection == OPAMP_Selection_OPAMP2)
{
/* Check OPAMP2 CAL bit status */
if ((tmpreg & OPAMP_CSR_OPA2CALOUT) != (uint32_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
}
else
{
/* Check OPAMP3 CAL bit status */
if ((tmpreg & OPAMP_CSR_OPA3CALOUT) != (uint32_t)RESET)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
}
return bitstatus;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2012 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -