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.1k4 gold badges42 silver badges81 bronze badges
asked Oct 2, 2024 at 14:06
1
  • You can use external pull-up or pull-down resistors. Commented Oct 2, 2024 at 17:27

2 Answers 2

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,4089 silver badges18 bronze badges
answered Oct 2, 2024 at 14:35
1
  • Some micro-controllers have registers which allow controlling the behaviour of some pins during reboots. No idea if that's the case on this one. But indeed, appropriate external resistors would solve the issue. Commented Oct 4, 2024 at 12:16
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.

answered Oct 4, 2024 at 16:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.