Not executing while condition
float init_sensor(void){
uint32_t numTicks;
float distance;
RCC->AHB1ENR |= (1U<<1);
GPIOB->MODER &=~ (1U<<19); // pin 9 as output
GPIOB->MODER |= (1U<<18); // pin 9 as output
GPIOB->MODER &=~ (1U<<16); // pin 8 as input
GPIOB->MODER &=~ (1U<<17); // pin 8 as input
GPIOA->MODER |= (1U<<10);
GPIOA->MODER &=~ (1U<<11);
RCC->CFGR |= (1U<<4);
RCC->CFGR |= (1U<<5);
RCC->CFGR &=~ (1U<<6);
RCC->CFGR |= (1U<<7);
while(1){
//generate 10uS pulse and 250uS delay
GPIOB->ODR |= (1U<<9);
delay_us(10);
GPIOB->ODR &=~ (1U<<9);
delay_us(200);
numTicks=0;
while((GPIOB->IDR) & (1U<<8)){
numTicks++;
}
distance = (numTicks)/58;
}
return distance;
}
Hello,
I wrote this code,
and the code get stuck in the while GPIOB condition and I don't know why..
it's also happens when I tried similar condition to check UIF timer flag.
I checked it with my oscilloscope and pin8 generate pulses so numTick should be increment, I don't know why the code not processed.
Edit: the problem is the IDR not updating value although the pin get signals from the sensor.
any ideas?
