Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UART vs I2C vs SPI for inter-processor communication between microcontrollers

I am examining a way to connect two microcontrollers. On the level of serialization I am thinking of using Nano protobuffers (http://code.google.com/p/nanopb/). This way I can encode/decode messages and send them between two processors.

Basically, one small processor would be the RPC server, capable of doing several functions. Bigger processor will call there RPCs via messages sent, and then when data is ready, it will read it from smaller processor.

What would be the pros/cons of using UART, I2C or SPI?

Messages will be put in the mailbox que prior to sending.

Best regards, Drasko

like image 637
Drasko DRASKOVIC Avatar asked Jan 30 '14 23:01

Drasko DRASKOVIC


People also ask

What is difference between UART I2C and SPI?

UART vs I2C vs SPI Unlike communication protocols like I2C and SPI, UART is a physical circuit. While SPI and I2C use a master/slave paradigm to control devices and send data, UART communication incorporates two UART devices to send and receive the data.

Which is better UART or I2C?

I2C is also generally faster than UART, and can reach speed of up to 3.4 MHz. Some of the disadvantages of I2C include its increasing circuit complexity with additional master/slave setups, and is only able to operate in half-duplex, meaning data can only be transmitted in one direction at a time.

Which is better UART or SPI?

SPI protocol is significantly faster than UART. SPI offers high-speed synchronous communication, whereas UART devices communicate with each other at speeds that are three times lower than SPI protocol.

Is it better to use I2C or SPI for data communication between a microprocessor and DSP?

Overall, SPI is better for high speed and low power applications, while I2C is better suited for communication with a large number of peripherals, as well as in situations involving dynamic changing of the primary device role among peripherals on the I2C bus.


1 Answers

It depends on your total requirements and how expensive are pins.

I2C only needs two pins, but it's slow and to handle it with or without interrupts is a pain, even with the build in peripheral modules. It's a master/slave system, it's good for controlling many slow devices like temp sensors.
Only two lines for all bus devices, the selection is done via an I2C-Address in the protocol.

Uart needs two pins, it's normally faster, easier to handle, but requires (nearly) the same clocks at both sides. One to one asynchronous system, can be good if both systems needs to be send sometimes data without waiting for a master poll request.
Can also be used as a bus system, but then you need a master/slave structure or more complex protocols.

SPI needs 3 (or 4 with CS) pins, it's the fastest, simple to implement even with DMA, low cpu time overhead, often buffered. When you have enough free pins I would prefer it.

like image 188
jeb Avatar answered Sep 28 '22 05:09

jeb