2021-08-09 09:23 AM
Hi friends,
I have STM32L053C8T6TR, where I use PPS pulse from GPS connected to PB8. I set this pin:
#define GPS_PPS_Pin LL_GPIO_PIN_8
#define GPS_PPS_GPIO_Port GPIOB
void gps_pps_pin_init(void) {
LL_EXTI_InitTypeDef EXTI_InitStruct = {0};
/**/
LL_SYSCFG_SetEXTISource(LL_SYSCFG_EXTI_PORTB, LL_SYSCFG_EXTI_LINE8); // source line 8
LL_GPIO_SetPinPull(GPS_PPS_GPIO_Port, GPS_PPS_Pin, LL_GPIO_PULL_NO); // Output type is Push-Pull
LL_GPIO_SetPinMode(GPS_PPS_GPIO_Port, GPS_PPS_Pin, LL_GPIO_MODE_INPUT); // Pin as input
/**/
EXTI_InitStruct.Line_0_31 = LL_EXTI_LINE_8;
EXTI_InitStruct.LineCommand = ENABLE;
EXTI_InitStruct.Mode = LL_EXTI_MODE_IT;
EXTI_InitStruct.Trigger = LL_EXTI_TRIGGER_RISING_FALLING; // no check both
LL_EXTI_Init(&EXTI_InitStruct);
/* EXTI interrupt init*/
NVIC_SetPriority(EXTI4_15_IRQn, 2);
NVIC_EnableIRQ(EXTI4_15_IRQn);
}
And I have handler:
void EXTI4_15_IRQHandler(void) {
if (LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_8)) {
// přišlo přerušení z PB8
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_8); // vy�?isti vlajku
pps_puls = TRUE;
}
}
And in the main loop, I check this value.
while(1){
if (pps_puls == TRUE){
pps_puls = FALSE;
print("PPS pulse present");
}
}
The PPS pulse is present, I checked it using the log analyzer:
Does anyone see a problem? I don't thank you.
2021-08-09 09:33 AM
Did you define pps_puls as volatile?
Set a breakpoint in EXTI4_15_IRQHandler and see if it gets hit.
2021-08-09 09:48 AM
Yes I did. And breakpoint doesn't help because the interrupt doesn't work. But after asking a question, I found a solution. The solution below. Omg:beaming_face_with_smiling_eyes:
void gps_pps_pin_init(void) {
LL_EXTI_InitTypeDef EXTI_InitStruct = {0};
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
/**/
LL_SYSCFG_SetEXTISource(LL_SYSCFG_EXTI_PORTB, LL_SYSCFG_EXTI_LINE8);
/**/
LL_GPIO_SetPinPull(GPS_PPS_GPIO_Port, GPS_PPS_Pin, LL_GPIO_PULL_NO);
/**/
LL_GPIO_SetPinMode(GPS_PPS_GPIO_Port, GPS_PPS_Pin, LL_GPIO_MODE_INPUT);
/**/
EXTI_InitStruct.Line_0_31 = LL_EXTI_LINE_8;
EXTI_InitStruct.LineCommand = ENABLE;
EXTI_InitStruct.Mode = LL_EXTI_MODE_IT;
EXTI_InitStruct.Trigger = LL_EXTI_TRIGGER_RISING;
LL_EXTI_Init(&EXTI_InitStruct);
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_8);
/* EXTI interrupt init*/
NVIC_SetPriority(EXTI4_15_IRQn, 3);
NVIC_EnableIRQ(EXTI4_15_IRQn);
}
2021-08-09 12:49 PM
Forgot to enable SYSCFG clock? You surely found it by reading back and checking the related registers (here SYSCFG), didn't you.
If you subscribe to the notion of enabling all related clocks in the routine which initializes a certain functionality, then you should also enable the related GPIO clocks in that function.
JW