EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: anvoice on March 27, 2018, 12:17:01 am

Title: Communication protocol for MCU
Post by: anvoice on March 27, 2018, 12:17:01 am
I have a circuit I'd like to control with either an external controller or a PC. I'm guessing the cable length might be as much as half a meter or so, possibly a bit longer. I2C seemed like the simplest option until I started reading about the length/speed tradeoffs, and I don't know right now whether that is the right way to go.
There may be multiple instances of the circuit connected to the master device, so I need some form of addressing, preferably not involving chip select as that could take too many pins. I'm currently reading about RS422/RS485 which appears to be a robust protocol, but I'd need to set up a converter to interface with the uC (SAMD21), and also the master will need a way to implement the same RS485 so if it's another uC it'll need an adapter of its own.
Is there a recommended way for doing this? Perhaps some sources of information that I've missed on other standards that could be more suitable? Thanks for reading.
Title: Re: Communication protocol for MCU
Post by: ataradov on March 27, 2018, 01:12:56 am
Half a meter is not a problem. Just go with I2C and reduce the speed if you start having problems.

Or use SPI without SS.
Title: Re: Communication protocol for MCU
Post by: anvoice on March 27, 2018, 01:24:00 am
SPI without chip select? How do you distinguish between slave devices then?

I'm basically thinking this device might see use beyond my home someday, and then I'd like a fairly robust communication protocol that's reasonably fast. I2C would be perfect for its simplicity and compatibility with MCUs as well as adaptability to PCs, but the only example of something related to a servo using the I2C protocol I could find was this: https://www.adafruit.com/product/815 (https://www.adafruit.com/product/815)
Title: Re: Communication protocol for MCU
Post by: ataradov on March 27, 2018, 01:25:49 am
SPI without chip select? How do you distinguish between slave devices then?
Missed the part about multiple devices. Just go with I2C, don't overthink it.

Title: Re: Communication protocol for MCU
Post by: anvoice on March 27, 2018, 01:34:06 am
Believe me I don't want to overthink it.  :) Just trying to think ahead a little. I'm all for I2C being enough.
Title: Re: Communication protocol for MCU
Post by: mdijkens on March 27, 2018, 07:46:15 am
websockets over wifi with esp8266 ?
Title: Re: Communication protocol for MCU
Post by: anvoice on March 27, 2018, 09:50:22 pm
websockets over wifi with esp8266 ?

But there will need to be power wires going to the device anyway, so might as well route a mechanical comm connection. Adding an esp8266 will complicate the design and increase cost, which isn't great if I later decide to make say 100 of these. Plus, then the controlling unit (for example a microcontroller) will also need wifi capability.
Title: Re: Communication protocol for MCU
Post by: DC1MC on March 28, 2018, 07:30:13 am
What about 1-Wire protocol:

https://www.maximintegrated.com/en/app-notes/index.mvp/id/1796 (https://www.maximintegrated.com/en/app-notes/index.mvp/id/1796)

DC1MC
Title: Re: Communication protocol for MCU
Post by: ataradov on March 28, 2018, 07:33:39 am
What about 1-Wire protocol:
It is still subject to the same problems as I2C. But yes, you will save one wire.
Title: Re: Communication protocol for MCU
Post by: zzattack on March 28, 2018, 08:46:52 am
CANBUS wouldn't be a crazy choice either
Title: Re: Communication protocol for MCU
Post by: anvoice on March 28, 2018, 10:13:32 am
What about 1-Wire protocol:

https://www.maximintegrated.com/en/app-notes/index.mvp/id/1796 (https://www.maximintegrated.com/en/app-notes/index.mvp/id/1796)

DC1MC
But then I'd have to use a different chip than the SAMD21E I'm designing around now? I'll give that a read though.

CANBUS wouldn't be a crazy choice either
While I'm reading up on that, would you mind throwing in some advantages/downsides? I believe I'll need interface circuitry if I were to use that, but how is it superior to I2C?
Title: Re: Communication protocol for MCU
Post by: ataradov on March 28, 2018, 03:26:13 pm
But then I'd have to use a different chip than the SAMD21E I'm designing around now? I'll give that a read though.
Any MCU can bit-bang 1W, it is not that hard.

While I'm reading up on that, would you mind throwing in some advantages/downsides? I believe I'll need interface circuitry if I were to use that, but how is it superior to I2C?
It is explicitly designed for extremely noisy conditions, but it will add to the cost considerably.

If you were doing 10 meters of wires or something like that, you would have to go with CAN or similar. But for half a meter, you are overthinking it.