How to pull down an input pin on the Teensy 4.0

Status
Not open for further replies.

LukasFun

Member
Is there any way to pull down an input pin on the Teensy 4.0 other that manually connecting it to GND via a resistor?
 
It seems that the Pins are connected to GND via a 100 kOhm resistor by default. It is possible to disconnect them though using

Code:
pinMode(pin, INPUT_PULLUP);

See also https://www.pjrc.com/teensy/td_digital.html.

If a pin was set as an output and you want to change it to an input, it will automatically be pulled down via a 100 kOhm resistor. The two commands

Code:
pinMode(pin, INPUT);

and

Code:
pinMode(pin, INPUT_PULLDOWN);

have the same effect.
 
Note: the web page : https://www.pjrc.com/teensy/td_digital.html as well as several others is more specific to the Teensy 1 and 2 (AVR) based setup.

For information on some of this stuff you should look at the actual processor reference pdfs which you can download from the PJRC site.

Example look at section 11.4.2.2 for T4...

Note input pinMode(pin, INPUT) is NOT the same as pinMode(pin, INPUT_PULLDOWN);
You can confirm this by looking at the sources (digital.c) under teensy4...

Code:
void pinMode(uint8_t pin, uint8_t mode)
{
	const struct digital_pin_bitband_and_config_table_struct *p;

	if (pin >= CORE_NUM_DIGITAL) return;
	p = digital_pin_to_info_PGM + pin;
	if (mode == OUTPUT || mode == OUTPUT_OPENDRAIN) {
		*(p->reg + 1) |= p->mask; // TODO: atomic
		if (mode == OUTPUT) {
			*(p->pad) = IOMUXC_PAD_DSE(7);
		} else { // OUTPUT_OPENDRAIN
			*(p->pad) = IOMUXC_PAD_DSE(7) | IOMUXC_PAD_ODE;
		}
	} else {
		*(p->reg + 1) &= ~(p->mask); // TODO: atomic
		if (mode == INPUT) {
			*(p->pad) = IOMUXC_PAD_DSE(7);
		} else if (mode == INPUT_PULLUP) {
			*(p->pad) = IOMUXC_PAD_DSE(7) | [COLOR="#FF0000"]IOMUXC_PAD_PKE | IOMUXC_PAD_PUE | IOMUXC_PAD_PUS(3)[/COLOR] | IOMUXC_PAD_HYS;
		} else if (mode == INPUT_PULLDOWN) {
			*(p->pad) = IOMUXC_PAD_DSE(7) | [COLOR="#FF0000"]IOMUXC_PAD_PKE | IOMUXC_PAD_PUE | IOMUXC_PAD_PUS(0) [/COLOR]| IOMUXC_PAD_HYS;
		} else { // INPUT_DISABLE
			*(p->pad) = IOMUXC_PAD_DSE(7) | IOMUXC_PAD_HYS;
		}
	}
	*(p->mux) = 5 | 0x10;
}
Note the Input and output, set PKE and PUE and PUS (Pull up/down enabled and PUS(0) says 100K Ohm Pull Down and: PUS(3) says 22K Ohm Pull Up

And notice that INPUT does not set these, so no PULL up or PULL down enabled. i.e. the pin is floating. Now if you have that pin hooked up to something else like an another IO pin of the processor or other processor it will be the value of that other pin...
 
Status
Not open for further replies.
Back
Top