1
\$\begingroup\$

I had originally done a PCB for another chip. All pins I'm using (1, 2, 3, 17, 18, 19, 20) are fortunately correct for the ATtiny4313 I'm now using, except GND that arrives on pin #4 of my PCB ... instead of pin #10!

enter image description here

An option for my prototype PCB (I don't want to throw them away) would be to use a small wire between GND and pin #10.

Question: just for learning purposes, would you see another clever option that wouldn't require a wire?

Would something like doing digitalWrite(4, LOW); or analogWrite(4, 0); work and internally wire pin #4 to GND i.e. pin #10? Or wouldn't it work because the ATtiny won't boot first if no GND is connected?

\$\endgroup\$
  • \$\begingroup\$ What is connected to pin 10 now? \$\endgroup\$ – Jeroen3 Sep 30 at 6:58
  • \$\begingroup\$ @Jeroen3 Nothing is now connected to pin 10. \$\endgroup\$ – Basj Sep 30 at 7:02
2
\$\begingroup\$

Given you likely aren't running at high speed (100+MHz), a simple "bodge wire" to connect pins 4 and 10 would work reasonably well. Just make sure that in your code you always leave pin 4 as an input (preferably with pull-up disabled to save power).

I wouldn't do this on a production board, but for a prototype it will be fine.

Regarding your last point, no, you can't just set the pin to be output low to make the connection, because all pins are high-z by default, so the chip likely won't turn on.

\$\endgroup\$
  • \$\begingroup\$ Thank you for your answer. (Of course for production board, I'll fix this, this is only for prototyping). If I don't do anything in the code about pin #4, will it draw a little power? (I mean: pin #4 is named PCINT9/XTAL2/PA1/D2, do you think that having it constantly connected to GND will draw current or have other consequences?). Would you do something in the code about this pin (DigitalWrite? AnalogWrite? pinMode INPUT?) or just do nothing? \$\endgroup\$ – Basj Sep 30 at 7:39
  • \$\begingroup\$ @Basj by default the pin is an input with pull-up disabled, so will not cause any power draw - tying a digital input to ground is no different than driving it low from a digital output, so there is zero danger. In fact tying a digital input to some known state is better than leaving it floating from a power consumption perspective. I wouldn't do anything in the code to the pin, just leave it be. \$\endgroup\$ – Tom Carpenter Sep 30 at 7:58
  • \$\begingroup\$ Thank you very much @TomCarpenter! PS: is pin #4 a digital or analog pin? (I thought A in PA1 was for analog) \$\endgroup\$ – Basj Sep 30 at 7:59
  • 1
    \$\begingroup\$ @Basj ATtiny2313 has no analog pins. PA means Port A, PB is Port B, PD is Port D, etc. \$\endgroup\$ – Tom Carpenter Sep 30 at 8:10
  • \$\begingroup\$ Oh thanks @TomCarpenter, I never realized that! I understand now why I see many projects where people do PWM with ATtiny, it's because there is no analog out... \$\endgroup\$ – Basj Sep 30 at 8:43
1
\$\begingroup\$

I would cut the track to pin 4, leaving that pin not connected to anytyhing, then connect pin 10 to any handy Ground point.

This would leave pin 4 free for other use, should you eventually need it, and would ensure that there would be no problem if your program sets it as a High output for any reason.

You might want to connect an 0.1 uF capacitor between pin 10 and 20 to ensure you have a good power supply bypass on the chip.

\$\endgroup\$
  • \$\begingroup\$ Thank you. The cap between 10 and 20 is to filter out high frequencies variations on the power supply, to keep only DC, is that right? 0.1 uF would correspond to which cut frequency approximately? \$\endgroup\$ – Basj Sep 30 at 15:56
  • \$\begingroup\$ 0.1 uF is just a common value used for power supply bypass - no calculations involved in choosing it. You will find 0.1 uF capacitors used as bypass caps scattered around most circuits. \$\endgroup\$ – Peter Bennett Sep 30 at 16:01
1
\$\begingroup\$

It is a hack, but as long as you are not sinking too much current you can use any GPIO pin on this chip as ground. Really.

How does it work? Every GPIO pin has a built in protection diode that connects it to ground...

enter image description here

Notice that if the voltage on the GPIO pin is lower than the internal ground bus on the chip, that diode will be forward biased and current will flow out the pin. As long as the total voltage between the external Vcc connection and the GPIO-to-ground connection is high enough that the voltage inside the chip is enough for it to operate, then it will run. Note that you have to account for the voltage drop across that diode (likely about 0.6V) and you can not exceed the rated current capacity of that diode (likely single digits of mA).

Wire up this circuit...

schematic

simulate this circuit – Schematic created using CircuitLab

...and then program the chip fuses to run at 1Mhz and write a tiny test program to set pin P2 to output mode and toggle it at, say, 1Hz and you should see blinkness.

Note that...

  1. The power supply voltage must be high enough that the chip see a good internal voltage even with the drop across the protection 5V should be more than enough, especially with the chip running at 1Mhz where it only needs an internal voltage of 1.8V.
  2. The power supply voltage must be high enough to be bigger than the forward voltage gap across the LED including the the protection diode drop. Again 5V more than enough.
  3. The LED should be set up to SOURCE though the chip rather than sink into it. This limits the current flowing though the protect diode on the erstaz ground pin and instead uses the Vcc pin to drive the LED current.

NB: For the haters out there who say that connecting the LED directly to the GPIO will make the world explode, I say try it. If you are really worried about destroying humanity in the process, then connect the circuit to a variable supply and start with a low voltage and work your way up.

\$\endgroup\$
  • \$\begingroup\$ Interesting trick, thank you! \$\endgroup\$ – Basj Sep 30 at 15:59
  • \$\begingroup\$ @Basj: it may be an interesting trick, but not one that I would advise using. It is misusing the protection diodes to carry power - they aren't meant for that. \$\endgroup\$ – Peter Bennett Sep 30 at 16:04
  • \$\begingroup\$ @PeterBennett Admitted hack for sure, but I think exactly responsive to the OP's "just for learning purposes, would you see another clever option that wouldn't require a wire?"! :) \$\endgroup\$ – bigjosh Sep 30 at 16:06
  • \$\begingroup\$ @PeterBennett Yes exactly, I won't use it for real, I will just try once. I just was in a "I made a mistake, how would MacGyver solve it?" mood, and this answer is great for learning purposes and discovering new unexpected things in these chips! \$\endgroup\$ – Basj Sep 30 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.