cancel
Showing results for 
Search instead for 
Did you mean: 

Why is priority HAL_DELAY compared to button?

Lex Trc
Associate II
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;

}

}

3 REPLIES 3
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
Up vote any posts that you find helpful, it shows what's working..
Posted on July 21, 2017 at 10:25

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

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
Up vote any posts that you find helpful, it shows what's working..