Skip to main content
Lex Trc
Associate II
July 20, 2017
Question

Why is priority HAL_DELAY compared to button?

  • July 20, 2017
  • 3 replies
  • 903 views
Posted on July 20, 2017 at 15:38

Hi,

i've a little problem with stm32L0.

I want change state with button B1, but HAL_DELAY is priority of button.

the mian is:

uint8_t stato;

stato = 0;

while (1)

{

switch(stato)

{

case 0:

HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);

HAL_Delay(500);

HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

HAL_Delay(500);

if(HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin)==GPIO_PIN_RESET)

{

stato = 1;

}

break;

case 1:

HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);

HAL_Delay(100);

HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

HAL_Delay(100);

if(HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin)==GPIO_PIN_RESET)

{

stato = 0;

}

break;

}

}

    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    July 20, 2017
    Posted on July 20, 2017 at 22:11

    Sorry, don't understand the question.

    The HAL_Delay() typically depends on SysTick and the priority assigned to that interrupt, usually needs to be rather high otherwise other code would dead-lock.

    HAL_Delay() isn't going to end early because you press the button, your code here is just inserting fixed delays. Don't see any interrupt handlers or setup.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Lex Trc
    Lex TrcAuthor
    Associate II
    July 21, 2017
    Posted on July 21, 2017 at 10:25

    I want change the type of blink of the led with button

    Tesla DeLorean
    Guru
    July 21, 2017
    Posted on July 21, 2017 at 14:45

    Ok, so use a variable, loop the delay while checking the button, so the LED/BUTTON occur in parallel. ie 100 or 500 loops of HAL_Delay(1), and more responsive change based on button

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..