cancel
Showing results for 
Search instead for 
Did you mean: 

How detect a rising edge ?

P07
Associate

Hi,

I have a school projet about preventive maintenance on WC. Due to the COVID-19, we no longer have access to the material, but we have to try to continue the project.

We use a turbine which is connected to the water access (in the WC) and it will be connect to the Arduino shield (PA0) link to our uC "b-l072z-lrwan1" (STM32L0). We only use our uC to check the data of the turbine and send it to The Thing Network.

We want that when a flush was used our uC run a code while the WC is filling up and depending on the time to refill it, sent an error.

I learned that we need to enable the clock of the pin, after configure the GPIO, but I can't remember what I have to do next.

void Turbine_Init(){
	GPIO_InitTypeDef GPIO_InitStruct;
 
	RCC_GPIO_CLK_ENABLE(GPIOA);
 
	GPIO_InitStruct.Pin = GPIO_PIN_A0;
	GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
 
	HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}

Thank you !

1 REPLY 1
berendi
Principal

Read the GPIO chapter of the reference manual.

The state of the input pins are available in the GPIOx->IDR register. Bit 0 is 0 when pin 0 is low, 1 when pin 0 is high. Bit 1 reflects the state of pin 1, etc up to pin 15.

Your input pin is on PA0, so you read GPIOA->IDR, check bit 0, and decide what to do when it is 0 or not 0.

if(GPIOA->IDR & (1 << 0)) {
  // PA0 is high
} else {
  // PA0 is low
}

Or you can simply assign it to a variable for later use

pa0 = (GPIOA->IDR & (1 << 0)) != 0;

With that you can build a state machine that checks the input in a loop, sends a message when the state has changed, marks the time etc.