Serial communications on the RPi - three kinds I2C (IIC), SPI, UART

Very quick question. I have read material regarding the three types of serial communication - I2C, SPI and UART. I have seen that in order to set up the RPi’s GPIO for I2C (IIC) or SPI, one runs the raspi-config program and go through the menu and enable/disable I2C or SPI.

Do I have to the same thing when wanting to run a UART by running raspi-config and selecting enable serial?

Theoretical question, can one enable UART (serial) and I2C at the same time or UART (serial) and SPI at the same time?

Thank you,
Anthony of Sydney

Hi Anthony,

Yes, all those interfaces are enabled through either raspi-config, or by editing the /boot/config.txt file directly. You can enable as many as you want at once, so you shouldn’t have any problems.

What’re you planning to make that needs all 3? Sounds interesting.

Dear Josh,
Thanks for the reply. It is very surprising that you can run all three methods of serial communication at the same time. I thought that if you used SPI (1) and SPI (2) you cannot use say I2C and UART. It is really interesting that the RPi can do all four methods SPI(1), SPI(2), I2C and UART at the same time!

To answer the question, it is not a specific project, rather it is to learn how to communicate using parallel, and serial via three methods - UART, SPI, I2C. And the way to learn is to get some dirt cheap peripherals that can handle one of each protocol. In addition from my research one has to be very careful as to connect the power 3.3V & 5V and signalling, for example connect TX to TX and RX to RX in UART Being careful is to avoid the risk of destroying the RPi and/or the cheap peripheral.

Something completely different. I will post this project when I have tried and tested it. (I like the scientific method.) I may have found a way of installing the IoT core with a non Windows 10 OS. It does not follow any of the complicated methods online. BUT if it works, I would like to publish it as a project on your site.

Anthony of Sydney

You shouldn’t need to use both SPI’s, as you can connect multiple devices to the same bus, only creating a different chip select (CS or SS) pin for each.

Further to the question on the IIC (I2C). It is understood that IIC on the RPi can connect up to 127 devices. You can connect the SDAs together and the SCLs together.

According to this article, there are two IIC connections. We know SDA1 and SCLA1 are at physical pins 3 and 5 on the hader. In addition there are SDA0 and SCL0 at physical pins 27 and 28 respectively.

So we could have 256 devices connected in parallel.

My questions are:

  • While I know we know the addresses of device at a particular II2 bus to be:
    sudo i2cdetect -y 1 # pins 3 and 5
    sudo i2cdetect -y 1 # pins 27 and 28
    And setting the bus in python is something like:
    import smbus

    address = 0x21; #not specific device, only for purposes of exercise.
    addressfrom1 = address
    addressfrom0 = address ; # same device different bus
    bus1 = smbus.SMBus(1)
    bus0= smbus.SMBus(0)

    read1 = bus1.read_byte_data(address, 1)
    read0 = bus0.read_byte_data(address,0)

My question is it possible to have both I2C (IIC) buses open at the same time using the above code?

  • The header label for pins 27 and 28 say I2C ID EEPROM (each).
    What eeprom are we talking about?
    When using pins 27 and 28 for I2C (IIC) between devices, will that affect the eeprom?

Thank you
Anthony of Sydney

Hi Anthony,

Both I2C busses should be able to be open at the same time. They technically take turns communicating over the same bus. As far as EEPROM, I’m not too sure. It shouldn’t affect the rest of the operation of your Pi

The pi3 has 2 completely separate I2C buses, and they can both be used at the same time. One of the buses shares some pins with the built-in eeprom, so if you’re using the onboard eeprom, be aware of this.

Not not sure of the earlier pi boards or the zero.