UART vs I2C vs SPI

Firmware/software/electronics/mechanics
Post Reply
Astrobiologist
Beginner
Posts: 25
Joined: Fri Jan 19, 2018 10:35 pm

UART vs I2C vs SPI

Post by Astrobiologist »

I have been considering creating my own deck. Looking over some similar posts on the fora, there have been some reports of incompatibilities using both the I2C and SPI buses, so what would work best? I note also that there are two UARTs available.
Which of these four options is on which pin please on the expansion bus? Apologies, I could see RX, TX 1 & 2, presumably the UARTs, but I was unsure of the nomenclature for the I2C and SPI pins.
Finally, is there any example code for talking over any of these? (preferably in Python)
Thanks in advance
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: UART vs I2C vs SPI

Post by arnaud »

Usually when making your own deck, the sensors or chips you put on the deck dictates what interface you will be using. If you put an MCU, UARTs are usually nice to use, if it is a sensor, it will usually be either SPI or I2C, we tend to prefer I2C when possible since it requires connecting 2 pins only and it is a bus that can be shared with other devices. The SPI bus requires more pins but can be much faster and with lower latency.

You can find the connection for the different buses in the wiki: https://wiki.bitcraze.io/projects:crazy ... ort_pinout
Image

You may also want to consider compatiblity with other decks, lower on the same wiki page there is a table that lists the pins used by the existing decks. Different bus can be shared diferently: I2C can be shared as long as there are not 2 device with the same address, SPI can be share if the CS pin is different, UART cannot be shared generally speaking.

If you make a deck, you will have to at least make a minimal deck driver in C in the Crazyflie, the driver can expose log and param variables. There is a specially made API for making a deck driver: https://wiki.bitcraze.io/doc:crazyflie: ... mware:deck. There is currently no way to control a deck from python directly. For examples, the best is to look at currently implemented decks.

As a side note: This is the second request in 2 weeks to interface a deck from python directly so I am curious of what would be your 'ideal' solution: would you want to write a python driver to run in the Crazyflie (with micropython), or to have an API on the ground to configure and use the different ports and IO from the ground using the radio (a little bit like Firmata for arduino).
Post Reply