SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
User avatar
By roach
#10859
First, the problem:

I need to interface a bunch of parts to an ATmega128. They are:
- USB interface (cp2103 from sparkfun)
- Motor controller (polulu micro dual serial motor controller, here)
- Wireless receiver (more on that here).

All of these devices communicate via serial RX/TX. Ideally, I'd like to get them all talking on a single UART. Theoretically this should be possible, because:

-The USB module should override all other modules, disabling communication to the motor controller and wireless receiver. Assume the uC would "know" when the USB module is active (by some magic I have yet to figure out).
-The motor controller only listens, never talks, so it doesn't need access to the RX pin on the UART.
-The wireless receiver only talks, never listens, so it doesn't need access to the TX pin on the UART.

I'm certain there's some kind of pulldown transistor setup I could implement (possibly from the 3.3V output of the cp2103 to NPN base) to disable the signals to the wireless receiver and motor controller when the USB connection is active, but I'm just not bright enough to figure it out.

I think the basic problem is that I just don't know enough about transistors. What is the difference between a PNP and an NPN transistor? Every time I try to read up on this, terms like "gallium arsenide", "doping", "current gain", and "Bell Labs" induce a loud humming noise in my brain until I fall unconscious. What is the fundamental, functional difference between the two? If I connect the 3.3V output from the cp2103 to base, will that be enough to trigger the transistor if the voltage at the collector is VLOGIC (5V)? Does that last question even make sense?

How can I get multiple devices talking on an RX/TX "bus"-type architecture, without busting my brains trying to code a comms protocol?

Before anyone jumps in with an immediate solution, here's what I've got so far:
- No, I'm not interested in coding a software UART, thanks.
- And yes, I know that having multiple devices on an RX/TX line is less than ideal. Unfortunately, I can't control the bricks, only the mortar I use to put them together :)
By SOI_Sentinel
#10863
A few things:

Do any of them have any type of comm enable/disable pin? It'd take more lines, but you might be able to switch some off (like SPI).

Do any of them talk RS422 or RS485? These are addressable multidrop serial comms that are often supported in UARTs. This would fix your issue if they all talked.

Now, possible additional hardware(I'm browsing TI at the moment):

Bidirectional bus multiplexing (you'd either need to poll periodically or have an indicator line of "data ready" from each part):
http://focus.ti.com/docs/prod/folders/p ... 3253c.html

Ultimate solution:
http://focus.ti.com/docs/prod/folders/p ... 6c554.html
Probably most pin count and possibly most software complex. However, you'd also still have the onboard UART for your "critical" communication.

These are just examples, you can probably find others that fit your needs better by looking around
By Philba
#10868
In simple terms you have 2 TX/1 RX (avr) and 1 TX (avr)/2 RX. I am assuming that they all talk TTL serial I/O.

the 3253 seems like a nice chip. perhaps a bit overkill, though. It is compatible with TTL so you can mix 3.3V and 5V logic with it. You'll need to use 2 avr pins to control it. There's a fairchild cross ref (fst3253) that is $.38 from mouser.

If there wasn't the 3.3V/5V mixing problem, I'd use tinylogic (1 mux and 1 demux) as they really are tiny... too bad they don't have open drain versions - that would solve the 3.3/5 problem.
Last edited by Philba on Fri Mar 10, 2006 12:46 pm, edited 1 time in total.
By Kuroi Kenjin
#10873
Ok this is probably a moot point if you follow Philiba and Sentinel's advice, but....

PNP is a transistor that you need to sink current from the base and
NPN is a transistor that you need to source current to the base.

Note a transistor is sort of like a current controlled switch. Basically if you hook a resistor up to the base to a controller pin, you should be able to turn it on and off. There's another post around somewhere with more info on this. I think Philba comes to the rescue again with a nice formula for current driving capability.
User avatar
By roach
#10883
SOI_Sentinel wrote:Do any of them have any type of comm enable/disable pin? It'd take more lines, but you might be able to switch some off (like SPI).
The motor controller has a RESET pin that can be pulled low to kill it.

Basically, I want the AVR to ignore any comms on the UART that aren't from the cp2103 when USB is plugged in. When USB is not connected, all comms (TX and RX) should be available (since there will be nothing from the cp2103).
Philba wrote:In simple terms you have 2 TX/1 RX (avr) and 1 TX (avr)/2 RX. I am assuming that they all talk TTL serial I/O.
This is exactly correct.
Philba wrote:the 3253 seems like a nice chip. perhaps a bit overkill, though. It is compatible with TTL so you can mix 3.3V and 5V logic with it. You'll need to use 2 avr pins to control it. There's a fairchild cross ref (fst3253) that is $.38 from mouser.

If there wasn't the 3.3V/5V mixing problem, I'd use tinylogic (1 mux and 1 demux) as they really are tiny... too bad they don't have open drain versions - that would solve the 3.3/5 problem.
I don't really need to "mix" 3.3V and 5V logic. It's just that there's an available 3.3 regulated supply pin on the cp2103, so I thought I'd use that to trigger a transistor setup, to kill comms from other modules. There's also an unregulated 5V supply (direct from USB) that I could use, if that's a better option. Like I said, I don't know enough about transisotrs to really know...

All "logic" signals will be at 5V, so mixing levels is not really a concern (as far as I can tell).

Can't a couple of trans handle this?
Kuroi Kenjin wrote:PNP is a transistor that you need to sink current from the base and
NPN is a transistor that you need to source current to the base.
God, I'm thick. This is probably the most concise, simplest explanation anyone could offer, and yet I still don't get it.

Do you mean: In order to "close" a PNP transistor, I must pull the base pin low, whereas, in order to "close" an NPN, I need to apply current?

Sorry for my obvious lack of knowledge, and thanks for all your patience, guys.
User avatar
By leon_heller
#10884
You turn a BJT on by forward biasing the B-E junction. That works for both PNP and NPN BJTs.

Leon
By Kuroi Kenjin
#10889
hmmm...Ok... transistors have a Collector, Base, and Emitter. The Base-Emitter junction is the important part here really.

On a PNP you need to reverse-bias this junction to make the emitter voltage lower than the base voltage (hence sinking current from the base).

Although you'll most likely use an NPN transistor (2N2222A are very common), in which the base voltage has to be higher than the emitter votlage (full on would be around 0.7V) (hence forcing a current into the base, usually with the emitter grounded).

This site may help a little, IF you keep in mind that that a digital signal is like a amplifier going rail to rail (0 to 5 V or what-not)

http://www.williamson-labs.com/480_xtor.htm

Or better yet... head to the library and look for some books.
User avatar
By roach
#10898
Kuroi Kenjin wrote:On a PNP you need to reverse-bias this junction to make the emitter voltage lower than the base voltage (hence sinking current from the base).
reverse-bias. Sinking current. Gotcha.
IF you keep in mind that that a digital signal is like a amplifier going rail to rail (0 to 5 V or what-not)
rail-to-rail. uh-huh.
Or better yet... head to the library and look for some books.
Yeah, I'm thinking that's a good idea...

[EDIT] found a site that explains it in terms even a bronze-age luddite like myself can understand!
http://www.satcure-focus.com/tutor/page4.htm
By transcendentnb2
#10899
roach wrote:
Kuroi Kenjin wrote:On a PNP you need to reverse-bias this junction to make the emitter voltage lower than the base voltage (hence sinking current from the base).
reverse-bias. Sinking current. Gotcha.
No no no no no. You are ALWAYS forward biasing the Base Emitter junction on a BJT for it to work. Basically, if you're looking on the schematic, you're making the current flow in the direction of the arrow. Doing so will make your Collector Emitter junction also conduct current (again, in the same direction of the arrow).

A forward biased PN junction (either diode or transistor) is always P to N.

EDIT: Also, since you don't want to get too complicated, stick with BJTs. You can look into FETs if you want (and if you do, you'd want a MOSFET specifically... no JFET, MISFET, or MESFET...). FETs are a different beast and can be destroyed easier. Plus, unless you really want to know what "enhancement mode" and "depletion mode" mean and how it works, just stick to BJTs (bi-polar junction transistor, if you didn't know yet).
User avatar
By roach
#10900
transcendentnb2 wrote:Basically, if you're looking on the schematic, you're making the current flow in the direction of the arrow.
Yay! Someone said something in english!
You can look into FETs if you want (and if you do, you'd want a MOSFET specifically... no JFET, MISFET, or MESFET...).
What about MOOSEFEET and MISFITS?
(bi-polar junction transistor, if you didn't know yet).
Yeah, I knew that. Of course I did. Who doesn't know that? I mean pfft, c'mon :roll: .

Okay, seriously, though. Thanks for all your help, guys. I know these are n00b questions about things that must seem pretty obvious, and I appreciate your taking the time to explain to me in small words :)