Connecting two baby o ports together

If I want to connect port C0 on one baby-O with port C0 on another baby O, what is the best practice? It is for one way communication going from a slave microcontroller to the master.

Do you simply wire them directly, and use the internal pullup on the master? The slave pulls it low when it wants to talk, and leaves it high otherwise?

What happens if one micro outputs a 0 on the line and the other outputs a 1? It is simply up to software to make sure this never happens?


Are you talking about implementing your own kind of one-way serial communication protocol?

The main thing you want to avoid is connecting two outputs together that are driving at different voltages, as this could damage one or both I/O pins, or possibly even the MCU in general. Fortunately, I/O pins on the AVR default to inputs on power-up/reset, which means you’re safe as long as you don’t explicitly write code on both boards that configures the pins as outputs. If you’re at all worried about shorting two outputs together, you could always put a small (e.g. 150 Ohm) current-limiting resistor between connected pins.

I can’t really give you detailed advice without knowing more about what sort of protocol you envision using.

- Ben

Hi Ben, thanks for your response.

I have TWI implemented between the two controllers currently. I want the TWI slave to be able to send a signal to the master that it needs attention. This portC0 will be “Give me attention!” Then the master will interrogate the slave over TWI. So it is only a flag and I will not be passing any other information over it.

So, since I am the only cook, I can just stay make sure I do not ever put the Master PORTC0 into anything but input.


Yeah, I think the best approach would be to enable the master’s pull-up on that PC0 and then have the slave briefly toggle PC0 from an input to an output and back again. If its PORT bit is zero (and this is the default value for it), this will cause it to go from floating to driving low to floating, and the voltage on the master’s PC0 will go from high to low to high.

I assume you plan on polling for PC0 in your main loop? If you use PD2, you can configure an external interrupt (INT0) to trigger on a falling edge, which might let you do things more efficiently.

- Ben

Great, thanks! I was thinking I could hook any port to an interrupt ,so you saved me some heartache there.


Every I/O pin can be used to trigger what is know as a “pin change interrupt”. There are three pin change interrupt vectors on the ATmega328, one for each port, and when enabled, the ISR will be called when any masked pin on that port has a change in its input state. Because each pin change interrupt applies to an entire port, pin change interrupts are more complicated to set up and use (you typically have to put extra code in the ISR to determine which pin’s state changed and whether it was a rising edge or falling edge).

A few special pins can be used to trigger “external interrupts”, which are easier to set up and easier to use. Each vector is associated with a specific pin, and each ISR can be configured to respond only to the desired state change (i.e. falling edge only).

You could get this working with pin change interrupts, but I think external interrupts are the way to go if you can spare one of the external interrupt pins.

- Ben