Communication protocol for MCU - Page 1
Forum section: electronics / beginners

author: anvoice
author_rank: Frequent Contributor
timestamp: March 27, 2018, 12:17:01 am
content: 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.

author: ataradov
author_rank: Super Contributor
timestamp: March 27, 2018, 01:12:56 am
content: 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.

author: anvoice
author_rank: Frequent Contributor
timestamp: March 27, 2018, 01:24:00 am
content: 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

author: ataradov
author_rank: Super Contributor
timestamp: March 27, 2018, 01:25:49 am
content: Quote from: anvoice on March 27, 2018, 01:24:00 amMissed the part about multiple devices. Just go with I2C, don't overthink it.

author: anvoice
author_rank: Frequent Contributor
timestamp: March 27, 2018, 01:34:06 am
content: Believe me I don't want to overthink it.Just trying to think ahead a little. I'm all for I2C being enough.

author: mdijkens
author_rank: Regular Contributor
timestamp: March 27, 2018, 07:46:15 am
content: websockets over wifi with esp8266 ?

author: anvoice
author_rank: Frequent Contributor
timestamp: March 27, 2018, 09:50:22 pm
content: Quote from: mdijkens on March 27, 2018, 07:46:15 amBut 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.

author: DC1MC
author_rank: Super Contributor
timestamp: March 28, 2018, 07:30:13 am
content: What about 1-Wire protocol:https://www.maximintegrated.com/en/app-notes/index.mvp/id/1796DC1MC

author: ataradov
author_rank: Super Contributor
timestamp: March 28, 2018, 07:33:39 am
content: Quote from: DC1MC on March 28, 2018, 07:30:13 amIt is still subject to the same problems as I2C. But yes, you will save one wire.

author: zzattack
author_rank: Regular Contributor
timestamp: March 28, 2018, 08:46:52 am
content: CANBUS wouldn't be a crazy choice either

author: anvoice
author_rank: Frequent Contributor
timestamp: March 28, 2018, 10:13:32 am
content: Quote from: DC1MC on March 28, 2018, 07:30:13 amBut then I'd have to use a different chip than the SAMD21E I'm designing around now? I'll give that a read though.Quote from: zzattack on March 28, 2018, 08:46:52 amWhile 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?

author: ataradov
author_rank: Super Contributor
timestamp: March 28, 2018, 03:26:13 pm
content: Quote from: anvoice on March 28, 2018, 10:13:32 amAny MCU can bit-bang 1W, it is not that hard.Quote from: anvoice on March 28, 2018, 10:13:32 amIt 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.