Short version: Can the digital pins handle 5V input?
Longer version: I hooked my new Spark Core into my existing Arduino project by making my Arduino think the Spark Core was a button. I connected a Spark Core digital pin to an UNO pin configured as INPUT_PULLUP (an input pin with pullup resistor enabled, which supplies low amperage 5V). Sure enough, if I set the Spark pin to output/LOW, the Arduino thinks the button has been pressed. When I set it to HIGH, it thinks the button is released.
I was very happy to see this work, but then I realized I should make sure the digital pins on the Spark Core can handle the 5V I’m feeding it. Hopefully this question makes sense?.. Thanks. Loving the Spark Core, and am totally blown away by the cloud functionality out of the box.
Just in case anybody needs to have bi-directional high frequency low current level shifting between 5 and 3.3 volts this circuit is cheap (>20p), tested and works:
It would not work for analogue, I presume a voltage divider and diode would be required for analogue inputs (with the addition of a transistor for outputs) but have not tested that yet.
If you had numerous 5 volt sensors the 74HC4050 will level down shift 6 inputs at a reasonable price. I am sure there are cheap bi-directional ics somewhere but have yet to find them.
Looking at the datasheet for the STM32F103CB, I don’t see any “pin circuit diagrams” (a la Microchip PICs) indicating whether the A/D pins have blocking diodes or not, so I have a question. Is it electrically permissible to connect an A/D line through 47K to a line that can go up to 5v? I fully understand that the A/Ds won’t read higher than 4095 if taken beyond 3.3v…but if the pins have blocking diodes, they simply won’t go much above 3.3v. Obviously, if forced, the blocking diodes (and input) will be damaged.
Did a quick test. With 100K to +5v, the voltage on A4 reads 3.6v. The Core’s internal regulator is 3.3v. So…I am assuming that if the pin is NOT rated as 5v tolerant, it will have blocking diodes preventing the pin from going over 3.6v, and from going below 0.3v. That is, unless the diodes blow. Now, if it’s 5v tolerant…well…I don’t have a clue what it’ll do. FWIW, I do recall a reference in the STM32 datasheet indicating that “weak pullups should be disabled if a 5v tolerant input is taken to 5v.”
Well, I inadvertently tested the A5 input pin beyond spec. My bad…a 2.2K resistor is no substitute for a 22K resistor, especially from 12vDC. But at least I can report my findings:
Basically, the circuit was a resistor bridge, 2.2K (whoops!) from 12v to the A5 pin, and 1.8K from A5 to GND. Basically, a resistor divider calculated to read 40+v DC. That is, with a 22K resistor on top .
OK, what did I notice? The code to read the pin wasn’t working. I don’t know what value the pin was reading (and don’t want to try again to find out!), but it was definitely >700 A/D counts (12-bit range of 0-4095). Taking the top of the resistor divider to 0v did not bring the A/D reading below 700; I suspect that it was “stuck” at full scale. Replacing the top resistor with a 22K resistor (watch that third band!) restored proper functionality–the pin appears to be undamaged . The Core was powered off during the change, so I suspect that a reset “freed” A5.
With a meter (and the 2.2K resistor), I measured 3.9v on A5…that’s when I realized that the problem was circuit-based, not code-based! There was some resistance from the Core to that voltage, as the resistor divider would have otherwise outputted 5.85v. My guess is that the total current sunk by A5 was below 5mA.