2017-07-20 06:38 AM
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; }}
2017-07-20 01:11 PM
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.
2017-07-21 03:25 AM
I want change the type of blink of the led with button
2017-07-21 07:45 AM
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