cancel
Showing results for 
Search instead for 
Did you mean: 

stm32L4: wakeup pin polarity confusing.

VD1
Associate

Hello.

I try to calculate some pulses by wakeups from shutdown mode. I have 2 pins which are

WKUP1, WKUP4. They are configured to wake up by rising edge. But sometimes when only 1 of them is rising, I receive 2 notifications, from both pins.

The problem occurs when one of pins is on high state:

1sensor: _____|``````````|___________
2sensor:____________|```````````````
------------- ^     ^
-------------p1     p2

on state p1 I receive wakeup from only from sensor1, But on state p2 I receive wakeup from both pins WKUP1, WKUP4, but rising edge only on single pin.

My initialization:

    __HAL_RCC_PWR_CLK_ENABLE();
    HAL_PWR_EnableBkUpAccess();
    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);
    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN4_HIGH);

Code which checks wakeup event:

    if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF1) != RESET) {
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
        sens_num++;
        rtc_inc(COUNTER1_IDX);
    }
 
    if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF4) != RESET) {
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF4);
        sens_num++;
        rtc_inc(COUNTER2_IDX);
    }
 
    if (sens_num == 2) {
        // ERROR!!!!!;
    }

Why both flags are set? How can I check only really rising event?

Also reference manual (5.4.4) about PWR_CR4 says:

"Bit 3 WP4: Wakeup pin WKUP4 polarity

This bit defines the polarity used for an event detection on external wake-up pin,

0: Detection on high level (rising edge)

1: Detection on low level (falling edge)"

What is detected by MCU? high level, or rising edge? manual is unclear

0 REPLIES 0