23rd of October 2023, Saturday

Hello Gophers!

I was playing around with an Arduino today, where I tested an idea of mine
for a super simple multidrop communication bus on one wire. (Yeah I know 1-Wire
exists, but I want to do something by myself sometimes...)

So I wired the base of a NPN transistor (the old and ubiquitous BC547C) to an
output of the Arduino via a 5k resistor, and connected the collector to the 5V
via a 1k pullup. Emitter to ground. The pulled-up collector goes into an input
again. This node (collector-1K) is the bus connection. (Besides GND or course)

This way we have 1 wire (pulled up by the 1k) that can be actively pulled to
ground by the output, and read back by the input, by any user on the
bus that has this connection. Effectively it is a wired-OR bus that has a
"HIGH" level resting situation.

This gives the possibility to make a multidrop bus with simple bus collision
detection: Pulling down ("writing LOW") the bus, will always win from "writing
HIGH", so anyone starting a transmission can check whether what they are try-
ing to write, actually is getting through.

This concept stems from CAN, and is called CSMA-CA: Carrier Sense Multiple
Access - Collision Avoidance

The signalling is also held super simple: a "1" is written by 1 cycle of "LOW"
followed by one cycle of "HIGH", and a "0" is written by 2 cycles of "LOW".
Also there is always one cycle of "HIGH" between bits. This makes it effec-
tively a pulse width modulated system. Every user listens back whether the
"HIGH's" that they are writing are actually seen back. If not, someone on
the bus is already writing a "LOW", and the node will have to back off for
a while, as the other one has 'won'. Anyone wanting to access the bus will
wait for at least 6 cycles of "HIGH" before attempting to start writing
(again).

I think this would be great for simple communication between microcontrollers
and their peripherals for example. It only costs two pins on your micro, and
it gives you communication to all others on the bus.

This protocol will need a structure for the communication as well. I would
like a MSB-first, 8 bit word approach, where all communication is:

{1 byte importance}           << an importance level 0x00 will always 'win'
{1 byte receiver address}     << 256 possible users on the bus
{1 byte sender address}
{1 byte command}              << 256 commands possible
{n byte payload of command (fixed length per command) << payload necessary

It's just an experiment, but my head likes to think about these things..

Let me know what you think!

Cheers,

Fripster

0--------1---------2---------3---------4---------5---------6---------7---------8