LPC Exported Functions
- group LPC_Exported_Functions
Functions
-
void LPC_DeInit(void)
Reset LPC.
- Returns:
None.
-
void LPC_Init(LPC_InitTypeDef *LPC_InitStruct)
Initialize LPC peripheral according to the specified parameters in LPC_InitStruct.
Example usage
void driver_lpc_init(void) { LPC_InitTypeDef LPC_InitStruct; LPC_StructInit(&LPC_InitStruct); LPC_InitStruct.LPC_Channel = LPC_CAPTURE_CHANNEL; LPC_InitStruct.LPC_Edge = LPC_VOLTAGE_DETECT_EDGE; LPC_InitStruct.LPC_Threshold = LPC_VOLTAGE_DETECT_THRESHOLD; LPC_Init(&LPC_InitStruct); LPC_Cmd(ENABLE); LPC_ResetCounter(); LPC_SetCompValue(LPC_COMP_VALUE); LPC_CounterCmd(ENABLE); LPC_INTConfig(LPC_INT_LPCOMP_CNT, ENABLE); NVIC_InitTypeDef NVIC_InitStruct; NVIC_InitStruct.NVIC_IRQChannel = LPCOMP_IRQn; NVIC_InitStruct.NVIC_IRQChannelPriority = 2; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); LPC_INTCmd(ENABLE); }
- Parameters:
LPC_InitStruct – [in] Pointer to a LPC_InitTypeDef structure that contains the configuration information for the specified LPC peripheral.
- Returns:
None.
-
void LPC_StructInit(LPC_InitTypeDef *LPC_InitStruct)
Fill each LPC_InitStruct member with its default value.
Example usage
void driver_lpc_init(void) { LPC_InitTypeDef LPC_InitStruct; LPC_StructInit(&LPC_InitStruct); LPC_InitStruct.LPC_Channel = LPC_CAPTURE_CHANNEL; LPC_InitStruct.LPC_Edge = LPC_VOLTAGE_DETECT_EDGE; LPC_InitStruct.LPC_Threshold = LPC_VOLTAGE_DETECT_THRESHOLD; LPC_Init(&LPC_InitStruct); }
- Parameters:
LPC_InitStruct – [in] : Pointer to a LPC_InitTypeDef structure which will be initialized.
- Returns:
None.
-
void LPC_Cmd(FunctionalState NewState)
Enable or disable LPC peripheral.
Example usage
void driver_lpc_init(void) { LPC_InitTypeDef LPC_InitStruct; LPC_StructInit(&LPC_InitStruct); LPC_InitStruct.LPC_Channel = LPC_CAPTURE_CHANNEL; LPC_InitStruct.LPC_Edge = LPC_VOLTAGE_DETECT_EDGE; LPC_InitStruct.LPC_Threshold = LPC_VOLTAGE_DETECT_THRESHOLD; LPC_Init(&LPC_InitStruct); LPC_Cmd(ENABLE); }
- Parameters:
NewState – [in] New state of LPC peripheral. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void LPC_CounterCmd(FunctionalState NewState)
Start or stop the LPC counter.
Example usage
void driver_lpc_init(void) { LPC_InitTypeDef LPC_InitStruct; LPC_StructInit(&LPC_InitStruct); LPC_InitStruct.LPC_Channel = LPC_CAPTURE_CHANNEL; LPC_InitStruct.LPC_Edge = LPC_VOLTAGE_DETECT_EDGE; LPC_InitStruct.LPC_Threshold = LPC_VOLTAGE_DETECT_THRESHOLD; LPC_Init(&LPC_InitStruct); LPC_Cmd(ENABLE); LPC_ResetCounter(); LPC_SetCompValue(LPC_COMP_VALUE); LPC_CounterCmd(ENABLE); }
- Parameters:
NewState – [in] New state of the LPC counter. This parameter can be one of the following values:
ENABLE: Start LPCOMP counter.
DISABLE: Stop LPCOMP counter.
- Returns:
None.
-
void LPC_INTConfig(uint32_t LPC_INT, FunctionalState NewState)
Enable or disable the specified LPC interrupts.
Example usage
void driver_lpc_init(void) { LPC_InitTypeDef LPC_InitStruct; LPC_StructInit(&LPC_InitStruct); LPC_InitStruct.LPC_Channel = LPC_CAPTURE_CHANNEL; LPC_InitStruct.LPC_Edge = LPC_VOLTAGE_DETECT_EDGE; LPC_InitStruct.LPC_Threshold = LPC_VOLTAGE_DETECT_THRESHOLD; LPC_Init(&LPC_InitStruct); LPC_Cmd(ENABLE); LPC_ResetCounter(); LPC_SetCompValue(LPC_COMP_VALUE); LPC_CounterCmd(ENABLE); LPC_INTConfig(LPC_INT_LPCOMP_CNT, ENABLE); NVIC_InitTypeDef NVIC_InitStruct; NVIC_InitStruct.NVIC_IRQChannel = LPCOMP_IRQn; NVIC_InitStruct.NVIC_IRQChannelPriority = 2; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); LPC_INTCmd(ENABLE); }
- Parameters:
LPC_INT – [in] Specify the LPC interrupt source to be enabled or disabled. This parameter can be one of the following values, which refer to LPC Interrupts Definition.
LPC_INT_LPCOMP_VOL: Voltage detection interrupt source. If Vin<Vth, cause this interrupt.
LPC_INT_LPCOMP_CNT: Counter comparator interrupt source.
NewState – [in] New state of the specified LPC interrupt. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void LPC_INTCmd(FunctionalState NewState)
Enable LPC interrupt signal to CPU NVIC.
Example usage
void driver_lpc_init(void) { LPC_InitTypeDef LPC_InitStruct; LPC_StructInit(&LPC_InitStruct); LPC_InitStruct.LPC_Channel = LPC_CAPTURE_CHANNEL; LPC_InitStruct.LPC_Edge = LPC_VOLTAGE_DETECT_EDGE; LPC_InitStruct.LPC_Threshold = LPC_VOLTAGE_DETECT_THRESHOLD; LPC_Init(&LPC_InitStruct); LPC_Cmd(ENABLE); LPC_ResetCounter(); LPC_SetCompValue(LPC_COMP_VALUE); LPC_CounterCmd(ENABLE); LPC_INTConfig(LPC_INT_LPCOMP_CNT, ENABLE); LPC_CompOutputConfig(ENABLE); NVIC_InitTypeDef NVIC_InitStruct; NVIC_InitStruct.NVIC_IRQChannel = LPCOMP_IRQn; NVIC_InitStruct.NVIC_IRQChannelPriority = 2; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); LPC_INTCmd(ENABLE); }
- Parameters:
NewState – [in] Enable or disable RTC interrupt signal to CCU. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void LPC_WKCmd(FunctionalState NewState)
Enable wakeup signal to power sequence.
Example usage
void driver_lpc_init(void) { LPC_InitTypeDef LPC_InitStruct; LPC_StructInit(&LPC_InitStruct); LPC_InitStruct.LPC_Channel = LPC_CAPTURE_CHANNEL; LPC_InitStruct.LPC_Edge = LPC_VOLTAGE_DETECT_EDGE; LPC_InitStruct.LPC_Threshold = LPC_VOLTAGE_DETECT_THRESHOLD; LPC_Init(&LPC_InitStruct); LPC_Cmd(ENABLE); LPC_ResetCounter(); LPC_SetCompValue(LPC_COMP_VALUE); LPC_CounterCmd(ENABLE); LPC_INTConfig(LPC_INT_LPCOMP_CNT, ENABLE); LPC_INTCmd(ENABLE); LPC_WKCmd(ENABLE); NVIC_InitTypeDef NVIC_InitStruct; NVIC_InitStruct.NVIC_IRQChannel = LPCOMP_IRQn; NVIC_InitStruct.NVIC_IRQChannelPriority = 2; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); }
- Parameters:
NewState – [in] Enable or disable LPC wakeup signal to power sequence. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void LPC_SetCompValue(uint32_t value)
Configure LPCOMP counter’s comparator value.
Example usage
void driver_lpc_init(void) { LPC_InitTypeDef LPC_InitStruct; LPC_StructInit(&LPC_InitStruct); LPC_InitStruct.LPC_Channel = LPC_CAPTURE_CHANNEL; LPC_InitStruct.LPC_Edge = LPC_VOLTAGE_DETECT_EDGE; LPC_InitStruct.LPC_Threshold = LPC_VOLTAGE_DETECT_THRESHOLD; LPC_Init(&LPC_InitStruct); LPC_Cmd(ENABLE); LPC_ResetCounter(); LPC_SetCompValue(LPC_COMP_VALUE); LPC_CounterCmd(ENABLE); }
- Parameters:
value – [in] LPCOMP counter’s comparator value which can be 0 to 0xfff.
- Returns:
None.
-
void LPC_ResetCounter(void)
Reset the LPC counter.
Example usage
void driver_lpc_init(void) { LPC_InitTypeDef LPC_InitStruct; LPC_StructInit(&LPC_InitStruct); LPC_InitStruct.LPC_Channel = LPC_CAPTURE_CHANNEL; LPC_InitStruct.LPC_Edge = LPC_VOLTAGE_DETECT_EDGE; LPC_InitStruct.LPC_Threshold = LPC_VOLTAGE_DETECT_THRESHOLD; LPC_Init(&LPC_InitStruct); LPC_Cmd(ENABLE); LPC_ResetCounter(); LPC_SetCompValue(LPC_COMP_VALUE); LPC_CounterCmd(ENABLE); }
- Returns:
None.
-
FlagStatus LPC_GetFlagStatus(uint32_t LPC_FLAG)
Check whether the specified LPC interrupt is set or not.
- Parameters:
LPC_FLAG – [in] Specify the LPC interrupt to check. This parameter can be one of the following values, which refer to LPC Flags Definition.
LPC_FLAG_LPCOMP_AON: counter comparator AON flag.
LPC_FLAG_LPCOMP_CNT: counter comparator flag.
- Returns:
LPC_FLAG: The new state of LPC_INT (SET or RESET).
-
void LPC_ClearFlag(uint32_t LPC_FLAG)
Clear the specified LPC flag.
- Parameters:
LPC_FLAG – [in] Specify the LPC flag to clear. This parameter can be one of the following values:
LPC_FLAG_LPCOMP_CNT: counter comparator flag.
- Returns:
None.
-
ITStatus LPC_GetINTStatus(uint32_t LPC_INT)
Checks whether the specified LPC interrupt is set or not.
Example usage
#define LPC_CAPTURE_PIN P2_3 #define LPC_CAPTURE_CHANNEL LPC_CAPTURE_PIN - P2_0 #define LPC_VOLTAGE_DETECT_EDGE LPC_Vin_Over_Vth; #define LPC_VOLTAGE_DETECT_THRESHOLD LPC_2400_mV; #define LPC_COMP_VALUE 0x0A//A LPC comparator interrupt occurs every ten times void board_lpc_init(void) { Pad_Config(LPC_CAPTURE_PIN, PAD_PINMUX_MODE, PAD_IS_PWRON, PAD_PULL_NONE, PAD_OUT_DISABLE, PAD_OUT_HIGH); Pinmux_Config(LPC_CAPTURE_PIN, IDLE_MODE); } void driver_lpc_init(void) { LPC_InitTypeDef LPC_InitStruct; LPC_StructInit(&LPC_InitStruct); LPC_InitStruct.LPC_Channel = LPC_CAPTURE_CHANNEL; LPC_InitStruct.LPC_Edge = LPC_VOLTAGE_DETECT_EDGE; LPC_InitStruct.LPC_Threshold = LPC_VOLTAGE_DETECT_THRESHOLD; LPC_Init(&LPC_InitStruct); LPC_Cmd(ENABLE); LPC_ResetCounter(); LPC_SetCompValue(LPC_COMP_VALUE); LPC_CounterCmd(ENABLE); LPC_INTConfig(LPC_INT_LPCOMP_CNT, ENABLE); NVIC_InitTypeDef NVIC_InitStruct; NVIC_InitStruct.NVIC_IRQChannel = LPCOMP_IRQn; NVIC_InitStruct.NVIC_IRQChannelPriority = 2; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); LPC_INTCmd(ENABLE); } void lpc_demo(void) { board_lpc_init(); driver_lpc_init(); } void LPCOMP_Handler(void) { if (LPC_GetINTStatus(LPC_INT_LPCOMP_CNT) == SET) { LPC_SetCompValue(LPC_GetCounter() + LPC_COMP_VALUE); LPC_ClearINTPendingBit(LPC_INT_LPCOMP_CNT); } }
- Parameters:
LPC_INT – [in] Specify the LPC interrupt to check. This parameter can be one of the following values:
LPC_INT_LPCOMP_CNT: counter comparator interrupt.
- Returns:
The new state of LPC_INT (SET or RESET).
-
void LPC_ClearINTPendingBit(uint32_t LPC_INT)
Clear the specified LPC interrupt pending bit.
Example usage
void lpc_demo(void) { LPC_ClearINTPendingBit(LPC_INT_LPCOMP_CNT); }
- Parameters:
LPC_INT – [in] Specify the LPC interrupt to clear. This parameter can be one of the following values:
LPC_INT_LPCOMP_CNT: Counter comparator interrupt.
- Returns:
None.
-
void LPC_32k_Off_Output_En(FunctionalState NewState)
Enable or disable lpcomp out to NVIC and power sequence.
- Parameters:
NewState – [in] This parameter can be ENABLE or DISABLE.
- Returns:
None.
-
uint16_t LPC_GetCompValue(void)
Read LPCOMP comparator value.
Example usage
void lpc_demo(void) { uint16_t value = LPC_GetCompValue(); }
- Returns:
LPCOMP comparator value.
-
uint16_t LPC_GetCounter(void)
Read LPC counter value.
Example usage
void lpc_demo(void) { uint16_t counter = LPC_GetCounter(); }
- Returns:
LPCOMP counter value.
-
void LPC_DeInit(void)