Verified Commit f83a4fd5 authored by Jakob Moser's avatar Jakob Moser
Browse files

Use GPIO 16 as SPI1CE0 pin

parent 39d8f365
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -54,12 +54,26 @@ Then, connect the cables to the Pi as described in this chart:
2. Go to “Interface Options”
3. Go to “SPI”
4. Enable it (no reboot necessary)
5. Add the line `dtoverlay=spi1-1cs` somewhere in `/boot/firmware/config.txt` (reboot might be necessary here)
   * This will enable the first SPI bus (SPI0)
5. Add the line `dtoverlay=spi1-1cs,cs0_pin=16` somewhere in `/boot/firmware/config.txt` (reboot might be necessary here)
   * This will enable the second SPI bus (SPI1). Furthermore, it will set the Chip Select pin for device 0 (`cs0`) to GPIO 16.

<details>
<summary>Further information on enabling SPI</summary>
<summary>Further information on SPI</summary>

Enabling SPI will place the line `dtparam=spi=on` in the file `/boot/firmware/config.txt` 
Enabling SPI will place the line `dtparam=spi=on` in the file `/boot/firmware/config.txt`.

Multiple devices can be connected to a single SPI bus (e.g. SPI0). They share the SCLK (clock), MISO and MOSI pins, however, each device has to be wired to a dedicated Chip Select (CS, = CE) pin. This is why an SPI devices is listed as `/dev/spi0.0`: The first `0` is the bus, the second `0` the device.

So, do we use this to connect both the LCD and the NFC reader? **Actually, no.**

The Raspberry Pi also has two SPI buses (SPI0 and SPI1). They have different SCLK, MISO and MOSI pins; and as stated above, each SPI bus has its own set of CS pins. In the pinout.xyz diagram, you can see that there is e.g. a `SPI0 CE0` and a `SPI1 CE0` pin.

Okay, so we wire up the LCD on SPI0 as device 0 and connect it to the respective pins; and then the NFC reader on SPI1 as device 0 and connect it to the respective pins, right? **Almost.**

The problem is that `SPI1 CE0` is pin 18, which is occupied by the GPIO header for the display. I don't know if it is needed, but I didn't want to take the risk. This is why I am remapping pin 18 (which would normally be `SPI1 CE2`) to the Chip Select pin for device 0 on SPI1. This is done with the `cs0_pin=16` instruction.

**This means that the NFC reader will be `/dev/spi1.0` (device 0 on SPI1), but wired physically as if it were device 2.**
</details>

<details>
@@ -71,6 +85,7 @@ Enabling SPI will place the line `dtparam=spi=on` in the file `/boot/firmware/co
- [Instructions (de)](https://cdn-reichelt.de/documents/datenblatt/C300/SBC-RFID-RC522-ANLEITUNG-08-07-2019.pdf)
- [Instructions (en)](https://cdn-reichelt.de/documents/datenblatt/C300/SBC-RFID-RC522-MANUAL-08-07-2019.pdf)
- [How to enable SPI0 and SPI1 at the same time](https://raspberrypi.stackexchange.com/questions/73346/how-to-enable-spi1-and-spi0-at-the-same-time)
- [SPI pinout map](https://pinout.xyz/pinout/spi)
</details>

### WiFi hotspot