In a recent thread regarding ESD damage to a Teensy 3.5, it was suggested that all unused GPIO pins be initialized to some known state (like OUTPUT_LOW). I have now added a 'InitAllPins' function to do just that to my Teensy projects, but I'm curious as to how others manage this.
Currently my T3.5 'InitAllPins()' function looks like this:
But later it occurred to me that I had not initialized ALL the pins - the T3.5 GPIO pin numbering actually goes up to 63 if you count the pins on the back and the SD card pins. Moreover, it 'would be nice' (I used to hate hearing those words when I was working!) if the same function could be used for both T3.2 and T3.5 (and others, but those are the only two I use currently).
Something like
Moreover, I suspect there is a way to automagically change the MAX_PIN_NUM value from 63 (for T3.5) to 33 (for T3.2) at compile time so the '#define MAX_PIN_NUM' wouldn't have to be edited manually.
The above loop-based 'InitAllPins()' function compiles (and apparently runs fine) on my T3.5 project, but I have no idea if I'm causing more problems than I'm fixing.
How are others doing this?
TIA,
Frank
Currently my T3.5 'InitAllPins()' function looks like this:
Code:
void InitAllPins()
{
pinMode(0, OUTPUT); digitalWrite(0, HIGH);
pinMode(1, OUTPUT); digitalWrite(1, HIGH);
pinMode(2, OUTPUT); digitalWrite(2, HIGH);
pinMode(3, OUTPUT); digitalWrite(3, HIGH);
pinMode(4, OUTPUT); digitalWrite(4, HIGH);
pinMode(5, OUTPUT); digitalWrite(5, HIGH);
pinMode(6, OUTPUT); digitalWrite(6, HIGH);
pinMode(7, OUTPUT); digitalWrite(7, HIGH);
pinMode(8, OUTPUT); digitalWrite(8, HIGH);
pinMode(9, OUTPUT); digitalWrite(9, HIGH);
pinMode(10, OUTPUT); digitalWrite(10, HIGH);
pinMode(11, OUTPUT); digitalWrite(11, HIGH);
pinMode(12, OUTPUT); digitalWrite(12, HIGH);
pinMode(13, OUTPUT); digitalWrite(13, HIGH);
pinMode(14, OUTPUT); digitalWrite(14, HIGH);
pinMode(15, OUTPUT); digitalWrite(15, HIGH);
pinMode(16, OUTPUT); digitalWrite(16, HIGH);
pinMode(17, OUTPUT); digitalWrite(17, HIGH);
pinMode(18, OUTPUT); digitalWrite(18, HIGH);
pinMode(19, OUTPUT); digitalWrite(19, HIGH);
pinMode(20, OUTPUT); digitalWrite(20, HIGH);
pinMode(21, OUTPUT); digitalWrite(21, HIGH);
pinMode(22, OUTPUT); digitalWrite(22, HIGH);
pinMode(23, OUTPUT); digitalWrite(23, HIGH);
pinMode(24, OUTPUT); digitalWrite(24, HIGH);
pinMode(25, OUTPUT); digitalWrite(25, HIGH);
pinMode(26, OUTPUT); digitalWrite(26, HIGH);
pinMode(27, OUTPUT); digitalWrite(27, HIGH);
pinMode(28, OUTPUT); digitalWrite(28, HIGH);
pinMode(29, OUTPUT); digitalWrite(29, HIGH);
pinMode(30, OUTPUT); digitalWrite(30, HIGH);
pinMode(31, OUTPUT); digitalWrite(31, HIGH);
pinMode(32, OUTPUT); digitalWrite(32, HIGH);
pinMode(33, OUTPUT); digitalWrite(33, HIGH);
pinMode(34, OUTPUT); digitalWrite(34, HIGH);
pinMode(35, OUTPUT); digitalWrite(35, HIGH);
pinMode(36, OUTPUT); digitalWrite(36, HIGH);
pinMode(37, OUTPUT); digitalWrite(37, HIGH);
pinMode(38, OUTPUT); digitalWrite(38, HIGH);
pinMode(39, OUTPUT); digitalWrite(39, HIGH);
}
But later it occurred to me that I had not initialized ALL the pins - the T3.5 GPIO pin numbering actually goes up to 63 if you count the pins on the back and the SD card pins. Moreover, it 'would be nice' (I used to hate hearing those words when I was working!) if the same function could be used for both T3.2 and T3.5 (and others, but those are the only two I use currently).
Something like
Code:
#define MAX_PIN_NUM 63 //T3.5. For T3.2 it is 33
void InitAllPins
{
for (size_t i = 0; i < MAX_PIN_NUM; i++)
{
pinMode(I, OUTPUT);
digitalWrite(I, HIGH);
}
}
Moreover, I suspect there is a way to automagically change the MAX_PIN_NUM value from 63 (for T3.5) to 33 (for T3.2) at compile time so the '#define MAX_PIN_NUM' wouldn't have to be edited manually.
The above loop-based 'InitAllPins()' function compiles (and apparently runs fine) on my T3.5 project, but I have no idea if I'm causing more problems than I'm fixing.
How are others doing this?
TIA,
Frank
Last edited: