2

I've got a LattePanda 3 Delta, which runs windows on its main processor and an Arduino sketch called StandardFirmata on its coprocessor. It's connected to a lock, which locks at HIGH and unlocks at LOW.

When I boot/reboot the LattePanda, there is a short time window where the lock goes haywire. I've managed to fix the worst of it by explicitly setting default pin values inside setup(), but I guess the pins float before setup() has a chance to run.

The setup() method now looks like this:

void setup() {

// OUTPUT pins for (int i = 0; i <= 6; i++) { pinMode(i, OUTPUT); }

for (int i = 18; i <= 20; i++) { pinMode(i, OUTPUT); }

// INPUT pins for (int i = 7; i <= 13; i++) { pinMode(i, INPUT_PULLUP); }

for (int i = 21; i <= 23; i++) { pinMode(i, INPUT_PULLUP); }

Firmata.begin(57600); Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION); Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback); Firmata.attach(REPORT_ANALOG, reportAnalogCallback); Firmata.attach(REPORT_DIGITAL, reportDigitalCallback); Firmata.attach(SET_PIN_MODE, setPinModeCallback); Firmata.attach(SET_DIGITAL_PIN_VALUE, setPinValueCallback); Firmata.attach(START_SYSEX, sysexCallback); Firmata.attach(SYSTEM_RESET, systemResetCallback);

while (!Serial) {;} systemResetCallback(); }

Is there a way to set pin values even earlier than setup()? I absolutely need them to NOT float. At all.

Edgar Bonet
  • 45,094
  • 4
  • 42
  • 81
Josmund
  • 21
  • 2

2 Answers2

11

You could in principle set the pin state a little bit earlier, by plugging your code into the C runtime's initialization sequence. This, however, will only buy you a few microseconds: the pins will still float at boot. At the software level, there is nothing you can do about it. This is just how the microcontroller works.

If you need to pins to absolutely never float, you need a hardware solution: pull them LOW or HIGH with external resistors.

the busybee
  • 2,408
  • 9
  • 18
Edgar Bonet
  • 45,094
  • 4
  • 42
  • 81
1

If one needs to have an external I/O device hold either of two states during a reboot without increasing quiescent current draw, a circuit similar to a "bus keeper" may be useful.

schematic

simulate this circuit – Schematic created using CircuitLab The output will default high on power-up (if the board has a brown-out sensor, substitute that for the RC network). If the CPU pin outputs high or low, the output will switch accordingly, but if the CPU pin is floating the output will maintain its state. The specified supply current for a TI quad-NAND 74HC00 is 2 microamps max at 25C, or 20uA max throughout its temperature range. When the CPU pin is floating, driven high, or driven low, no current will be pulled continuously through the 10K resistor, but a weak pull-up or pull-down could pull could pull continuous current through the resistor; such modes should be avoided when using this circuit.

supercat
  • 111
  • 3