Why a program stucks(even systick timer interrrupt is not coming ) while waiting for an GPIO input
I am using STM32L072RB
MCU is in while loop of main function. with Timer6(for Blinking and LED every 2sec) and systick timer is running.
Now i call function : adc_spi_chip().
I am waiting for PA2 pin to become low
but i found that waiting for it using a while loop stops everything like systick timer
In below code , i am reading a adc chip ,first i write to start conversion and then wait for end of conversion.Sometimes EOC signal doesn't comes and my code stucks
#define SPI2_CS_HIGH GPIOB->BSRR = GPIO_PIN_12 ;
#define SPI2_CS_LOW GPIOB->BRR = GPIO_PIN_12 ;
#define EOC_N HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_2)
uint8_t data_received[26];
void spi_chip()
{
uint8_t *data_received_pointer;
data_received_pointer = &data_received[0];
SPI2_CS_LOW
if((HAL_SPI_Transmit(&hspi2,(uint8_t *)&conversion_register_buffer,sizeof(conversion_register_buffer),500))!=HAL_OK)
{
Error_Handler();
}
SPI2_CS_HIGH
flag_eoc_check = 1;
while((EOC_N)==1)
{
if(flag_eoc_check == 0)
{
break ;
}
}
SPI2_CS_LOW
if((HAL_SPI_Receive(&hspi2,data_received_pointer,26,1000))!=HAL_OK)
{
Error_Handler();
}
}void SysTick_Handler(void)
{
if(flag_eoc_check == 1)
{
counter_eoc ++ ;
if(counter_eoc > 5000)
{
flag_eoc_check = 0 ;
}
}
else
{
counter_eoc = 0;
}
}So as per above code , i am stuck at line 18
while((EOC_N==1) ;
waiting for input to become low
I want if EOC_N doesn't becomes low in 5 second ,ishould break the loop,so i added a flag to turn on counter in systick timer and when it gets over ,i can break loop,but i found even systick timer not incrementing (have also checked in keil software).
To resolve issue i kept a counter inside while itself and break loop when it gets over ,but for incrementing a valuefrom 0 to 65536 in whille loop takes very less time and hence i wanted to use a timer ,
What is the reason and how to resolve issue ?
