Electrical – 74HC14 for debouncing: output is too low with Vcc=3.3V

debounceschmitt-triggerstm32

I'm trying to make a keypad for STM32 MCU using a 74HC14D.653 for debouncing. Datasheet says that it can be fed with 3.3V Vcc so I will not have to make level-shifting between it and MCU.
The schematic

The circuit (in theory) outputs logic LOW when buttons are released and logic HIGH when they're pressed.

When I already ordered the PCB and assembled it (I know it's (a bit) stupid not to test this particular circuit before putting it all together…) I found out a pretty unpleasant thing: when for example SW3 is pressed the output on pin 2 is not 3.3V at all. It's only 0.90V!

At the same time the rotary encoder connected to another 74HC14 in the same way works somehow but the built-in switch also does not work (my guess it's just a capacitor discharge when the shaft is being rotated and MCU catches this noise as a valid signal).

What I did wrong and how can I fix it (if it's still possible)?

Best Answer

So here's the solution (which looks more like "How-To" for other electronics newbies like me):

  1. Program your IO expander (PCF8574AT in my case) to have all the pins that used for buttons/encoders as INPUTS by writing logic 1's to them:

    uint8_t* buffer;
    buffer = malloc(1 * sizeof(uint8_t));
    *(buffer + 0) = 0b11111111; // all pins are INPUTS
    HAL_I2C_Master_Transmit(&hi2c1, 0x38 << 1, buffer, 1, 200);
    

    where hi2c1 is your I2C port for PCF8574, 0x38 is a PCF's address (pay attention that it must be shifted 1 bit left — see the "<< 1") and buffer is a pointer to data that we want to send to PCF8574. If pins are not set up then you may experience the strange voltage dropdowns on Schmitt trigger outputs down to 0.87-0.90V and PCF will not react to these signals at all (sorry for not describing the phisics of this process here as I still don't understand this yet...);

  2. Reset the interrupt pin by simply reading the data from PCF8574. This operation must be done after the every interrupt that your STM32 responds to:

    *(buffer + 0) = 0;
    HAL_I2C_Master_Receive(&hi2c1, 0x38 << 1, buffer, 1, 200);
    

(Sorry for my bad C and my English and correct me if/where I'm wrong...)


Oh, and here's full keypad schematic for those who want to use this in their projects: Keypad and encoder with Schmitt trigger-based debounce and I2C port expander