The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

53

This answer is general to processors and peripherals, and has an SRAM specific comment at the end, which is probably pertinent to your specific RAM and CPU. Output pins can be driven in three different modes: open drain - a transistor connects to low and nothing else open drain, with pull-up - a transistor connects to low, and a resistor connects to high ...


43

GPIO_PuPd (Pull-up / Pull-down) In digital circuits, is is important that signal lines are never allowed to "float". That is, they need to always be in a high state or a low state. When floating, the state is undetermined, and causes a few different types of problems. The way to correct this is to add a resistor from the signal line either to Vcc or Gnd. ...


28

The circuit you show should work, but is unnecessarily complicated and expensive. Here is something simpler and cheaper: Just about any small NPN transistor you can find will work in this role. If the B-E drop of the transistor is 700 mV, the LED drops 2.0 V, then there will be 600 mV accross R1 when the LED is on. In this example, that will allow 17 mA ...


22

First off, an Arduino cannot directly drive 100 LEDs, as the combined current that the device must source or sink will far exceed both the microcontroller, and the voltage regulator on the Arduino board. A custom Arduino Shield with its own power source and regulation might fit the bill, though. There are several easy approaches, the simplest approach is ...


22

The original 8051 used so-called pseudo-bidirectional output ports (open-drain with pullups), so there was really no port direction setting. Of course for modern true bidirectional output ports it's better to have a known value set before enabling the port pin for output, because otherwise you could have a transient on the output that could do something ...


21

Pull-up and Pull-downs are normally used to ensure a line has a defined state while not actively driven. They are used on inputs to prevent floating lines, rapidly switching between high and low and a middle "undefined" region. Outputs normally do not need them. But most mcu pins are GPIO, and sometimes on startup are defined as inputs instead of outputs. ...


18

Sadly this setup won't work. If you examine the datasheet carefully it states that the MOSFET has a threshold voltage which is guaranteed to be between 1.5V and 2.5V, with 1.8V typical. Even assuming you are lucky and you've got a specimen whose threshold is at 1.5V (best case for you), that doesn't mean that the MOSFET magically turns ON when its Vgs ...


17

That's right, open collector is BJT, open drain (C)MOS. In logic circuits where currents are low the saturation voltage of the BJT may be a bit higher than the voltage drop due to \$R_{DS(ON)}\$ for the FET, but it still will be much lower than the maximum voltage for a logic low. Exception: you can't use a TTL open collector output as a level shifter to ...


17

I found this answer from STM32 Understanding GPIO Settings GPIO_PuPd (Pull-up / Pull-down) In digital circuits, is is important that signal lines are never allowed to "float". That is, they need to always be in a high state or a low state. When floating, the state is undetermined, and causes a few different types of problems. The way to correct this is ...


17

Ray. Yes, there are hundreds if not thousands of good pages on using BJTs for pretty much any kind of switching arrangement you can imagine. They also work fine as level shifters, though despite your use of that phrase I actually don't think that's your situation here. If you want to look at an example of level shifting using BJTs, you can see my answer here....


17

This is actually an age old problem with PLCs and not nearly as simple as your intended solutions. The biggest issue you have is that as well has having a wide variety of potential logic voltages you need to be able to handle, the actual logic levels can be far higher than the 3.3V rail you are using internally. Some sensors and devices have logic ...


16

The TPIC6C595 is a power version of the 74HC595 shift register, serial in parallel out, with 8 output channels, each capable of driving 100mA. You only need three pins: serial data, serial clock and latch, and if needed you can cascade multiple devices for more than 8 outputs. It contains clamping diodes to protect against the relays' inductive voltage.


16

If you set the direction first, the pin will briefly be configured to output whatever its current output value is. If you set the value first, this won't happen. So, doing it the way you've been recommended avoids glitches on the output, which could range from harmless to catastrophic, depending on what the pin is connected to.


15

Unless the datasheet and associated documentation specify otherwise, do not apply a non-ground voltage to an unpowered device. The device may become powered through the input protection diodes on the pin and could behave erratically. If there is no way to modify the schematic such that unpowered devices do not have voltage applied to their inputs then use ...


14

Perhaps the simplest solution to the stated requirement is the FTDI FT245R IC. The key points of note in the context of the question are: Royalty-free USB drivers from FTDI for Windows, MacOS and Linux (MacOS support only for USB VCP mode) Complete USB device mode protocol handled on-chip without custom programming Complete USB hardware on-chip, including ...


14

Okay, here is a block diagram of a typical microcontroller (PIC16F616) I/O pin (Figure 4-1 in datasheet). Manufacturers do not typically publish transistor-level descriptions of anything complex these days, but we can deconstruct the block diagram with a bit of effort. If you want transistor-level schematics of a D flip-flop, it would be something like ...


14

It's there to protect the B-E junction of Q1 from reverse breakdown. For positive input voltages, the B-E junction of Q1 will conduct, and the voltage at the base will be limited to about +0.65V. As long as R1 is sized appropriately to limit the current, fairly arbitrary positive voltages can be applied to the input. D1 provides a similar path for negative ...


13

The best way to do this would be to use a transistor as a comparator to make the transition sharp. Here is an example circuit: It uses the LDR as the upper part of a voltage divider. When the LDR resistance drops the voltage at the transistor base rises and turns it on. The transistor can be any general purpose NPN. We can calculate the resistor value based ...


13

Honest truth: What you're trying to do is easier implemented just by using a microcontroller with enough pins. It's probably even cheaper than an Attiny85. Who knows. But: If you really must, you can do various things to get more output out of a single line: Buy an IO expander that uses the 1-Wire (pseudo)standard, and implement a 1-Wire transmitter on the ...


12

If you can still find one, it's worth mentioning that a true parallel port is about as close to a GPIO as you'll find in an off-the-shelf PC. Classic implementations lack some flexibility in that many of the pins have fixed direction, and some are inverted, but people have been working around that for years. The greater limitation is that such ports are ...


12

A GPIO pin is a 'general purpose input/output' pin. This is by default only high or low (voltage levels, high being the micro controller's supply voltage, low usually being ground, or 0V). But the levels of 'high' and 'low' are usually given as voltages as a proportion of the supply voltage. So anything usually above 66% of the supply voltage is considered a ...


12

That is called an "input clamping" diode. It's often done with two diodes, not just one (one to Vcc as well as one to GND), and is used to "clamp" the incoming voltage to ground minus the forward voltage of the diode (or Vcc plus the forward voltage for the upper diode). In your circuit it is specifically to remove any negative voltages from the input.


12

In the special case of the TMSC5515 you have 3 channels for 3 pins and 3 channels only for the pin GPAIN0. Pin GPAIN0 allows higher voltages and provides a built-in voltage divider. You may select the undivided voltage or the divided voltage by selecting one of the three channels. (See page 10 of the data sheet.)


11

Are you familiar with shift registers like 74HC595? It requires 3 pins from your RPI and you can control 8 output lines. You can easily cascade them effectively controlling n×8 output lines. Data is serially clocked into the shift register and once all 8 output bits are transferred, you latch the bits onto the outputs. I was about to add the datasheet here,...


11

Assumption: The question is about a device to transmit 32 or more digital inputs to a PC over USB. The device you are looking for is a 32-port (or more) USB GPIO module: Ideally with integrated pull-up or pull-down resistors, so the state of those limit switches can be directly sensed Ideally with a USB HID interface so a bespoke USB device driver is not ...


11

Yes, it's possible to damage the chip by driving it from a low impedance source when Vdd is 0. As you read from the datasheet, the absolute maximum input voltage is Vsupply -0.3. So if Vsupply is 0, you should not apply more than +/- 300mV to any input. As well as possible damage to the particular I/O pin's protection network, if you apply power when ...


10

To eliminate any possibility of surprise, and to generally make things more robust, I'd suggest using an optocoupler like 4N25. simulate this circuit – Schematic created using CircuitLab With this arrangement, you don't need to worry about how to combine the separate grounds of the two systems, because their grounds simply aren't connected. Also, if ...


10

No, in general you can not assume anything about GPIO pins of an unpowered chip, unless this is explicitly stated in the datasheet. What will likely happen is that the protection diodes in the chip will try to power the 'unpowered' chip from any pin that is high.


10

@Lorenzo has explained why this is not working for his, and if it did work it would be marginal, which might considered worse. Here is what a spec for a suitable MOSFET (AO3416) looks like: The Rds(on) is guaranteed at 1.8V Vgs, and at 34m\$\Omega\$ even if it's a bit higher because of tolerance on the 1.8V supply or temperature, still plenty of drive for ...


Only top voted, non community-wiki answers of a minimum length are eligible