2020-03-09 10:07 PM
2020-03-09 10:31 PM
This is because the return value of the HAL_GPIO_ReadPin() function is GPIO_PinState; the GPIO_PinState contains only the RESET(0) or SET(1) value.
typedef enum
{
GPIO_PIN_RESET = 0U,
GPIO_PIN_SET
} GPIO_PinState;
2020-03-09 10:55 PM
Dear Ekim.1
I tried GPIO_PinState, but still the value changes from SET to RESET and vice-versa...
do you think I should use a different function for reading PS Status?
2020-03-09 11:16 PM
If you want to read the sensor value of an optical sensor (e.g., a PS pin), you will need to use ADC.
2020-03-09 11:23 PM
The STM32 GPIO peripheral has a IDR register that contains the input values.
Not sure how to access it with Cube functionality, never used that.
> If you want to read the sensor value of an optical sensor (e.g., a PS pin), you will need to use ADC.
Using a Schmitt trigger is a legit option.
2020-03-10 12:05 AM
can I use GPIO_Analog in CubeMX?
2020-03-10 01:00 AM
You should measure the voltage levels when the the sensor is covered/uncovered. There are application notes with detailes about the GPIO input voltage conditions. Some STM32 have comparator inputs with adjustable voltage levels.
2020-03-10 01:05 AM
you are right dear KnarfB
2020-03-10 01:36 AM
> comparator input
Some chip families have a COMP peripheral which can compare input voltage to some reference value. Its easier than ADC where you need software for evaluating the measurments. What MCU are you using?
> BTW, can I use GPIO_Analog
GPIO_Analog is meant for two purposes:
it cannot be used for reading digital input value.
2020-03-10 01:42 AM
> it cannot be used for reading digital input value.
In other words, GPIO functionality and analog functionality for a pin are mutually exclusive.
And the schmitt trigger configuration is ok for the purpose with a well-defined situation (covered/non-covered threshold). No need for analog input.