32F417: can one detect if a GPIO pin has 2k2+LED connected to it? - Page 1
Forum section: electronics / general

author: peter-h
author_rank: Super Contributor
timestamp: November 27, 2022, 02:32:43 pm
content: I am driving two TLP281 optoisolators from PE0 and PE1. These are part of a factory option, and I would like to auto detect if this circuit is present.Obviously I can config a pin to be an output (like it already is), or an input. I am thinking about setting it to an input, with a pullup and then reading the pin but the range of pullup resistance is pretty wide - 30k to 50k according to the DS, which is very weak and would merely pull the GPIO to the LED Vf i.e. about +1.5V. Now if I could read PE0 or PE1 with an ADC that would be perfect but the AF maps show no way to do that.I wonder if anyone has come across a slick way to do this.And I don't want to change the PCBThere is also an ADS1118 in the option but my tests with it missing just read back all zeroes, which is a possible (if very unlikely) valid value. Same for the ADS1118's on-chip temp sensor. Damn annoying...

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 27, 2022, 05:42:31 pm
content: If you put the 2k2 resistor to gnd, yes, you should read the pin as "0":3.3V/32k*2k = 0.2V, max voltage you'll get at the pin.Don't use that 2k2 resistor for the led, use another one, otherwise you'll read Vf, usually >1.5V.

author: cv007
author_rank: Frequent Contributor
timestamp: November 28, 2022, 10:02:50 am
content: A pin unconnected will not be in a hurry to do anything after it was switched from an output/high to an input. In contrast, an led connected pin will not be so lazy about what it wants to be.Simple test with a stm32g031-Code:#include "MyStm32.hpp"GpioPin mypins[]{GpioPin(board.D).mode(OUTPUT).off(), //all unusedGpioPin(board.D).mode(OUTPUT).off(),GpioPin(board.D).mode(OUTPUT).off(),GpioPin(board.D).mode(OUTPUT).off(),GpioPin(PINS::PC6).mode(OUTPUT).off() //this is the green led};int main(){while( true ) {for( auto& p : mypins ){p.mode( OUTPUT ).on();delayMS( 1 );p.mode( INPUT );auto i = 0;while( p.isOn() and ++i < 1000 ){}uart << "ABC"[p.portNumber()] << p.pinNumber() << ": "<< (i < 10 ? "in use" : "unused") << " i: " << i << endl;}delayMS( 1000 );}}/* outputB0: unused i: 1000B2: unused i: 1000B8: unused i: 1000A8: unused i: 1000C6: in use i: 1*/I would think there is something along these lines which could be done.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 28, 2022, 10:51:28 am
content: Ah, c++ encryption

author: wek
author_rank: Frequent Contributor
timestamp: November 28, 2022, 10:58:19 am
content: You mean, to rely on parasitic capacitances and leakages? Not impossible but with potential to bite...ADCs can be used with internal pullups/pulldowns on TC (non 5V-tolerant) pins. None of such are available on 'F4, though, I used this on 'F0.JW

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 28, 2022, 11:25:53 am
content: Just do this, no sense in such crazy engineering overthinking.With the internal pullup enabled, the pin will always read 0.

author: peter-h
author_rank: Super Contributor
timestamp: November 28, 2022, 06:21:17 pm
content: Unfortunately my resistor and LED go from the GPIO to GND, not to VCC.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 28, 2022, 08:09:13 pm
content: Where's VCC in that picture?

author: peter-h
author_rank: Super Contributor
timestamp: November 28, 2022, 08:47:08 pm
content: Didn't look properlyYes that will work. I need to add that 2k2 as an indicator that the option is installed.