You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/device-tree-overlay/software-spi.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,9 @@ Users that need to use different pins can create their own customized version ba
20
20
21
21
:::caution **Drawback: Lower Bus Speed**
22
22
23
-
Since this is a software-based bus, it will not be as fast as a hardware SPI bus. This is adequate for most SPI devices, but it is not recommended for data-intensive use cases like driving a display.
23
+
Since this is a software-based bus, it will not be as fast as a hardware SPI bus. The maximum bus speed is **1.4MHz** if CPU load is low - much slower compared the 40MHz maximum of the hardware SPI bus.
24
+
25
+
This is adequate for most SPI devices, but it is not recommended for data-intensive use cases like driving a display.
import { GiscusDocComment } from '/src/components/GiscusComment';
@@ -35,27 +35,91 @@ opkg update
35
35
opkg install python3-light python3-spidev
36
36
```
37
37
38
-
<!-- TODO: add a step where the user chooses between harware SPI or the sw spi? -->
38
+
## Step 2: Choose Between Hardware or Software SPI
39
39
40
-
## Step 2: Physically Connect an SPI Device
40
+
The Omega2 supports both **hardware SPI** (using a built-in controller) and **software SPI** (bit-banging GPIOs). Before proceeding, choose the SPI bus that best suits your needs.
41
+
42
+
### Comparison: Hardware SPI vs. Software SPI on the Omega2
<!-- TODO: see if chart from docs/hardware-interfaces/spi.md can be reused -->
52
+
53
+
### Option 1: Using the Hardware SPI Bus (CS1)
54
+
The **hardware SPI bus** is pre-configured on the Omega2 and is accessed through `/dev/spidev0.1`. It supports **high-speed** SPI communication but is limited to **half-duplex mode** and uses **the fixed SPI pins**:
55
+
- GPIO6
56
+
- SPI_CLK pin
57
+
- SPI_MOSI pin
58
+
- SPI_MISO pin
59
+
60
+
If this setup meets your needs, **proceed to [Step 3](#step-3-physically-connect-an-spi-device)** to connect SPI devices. **For most users, this is the quickest option.**
61
+
62
+
63
+
### Option 2: Enabling a Software SPI Bus
64
+
If you need **full-duplex SPI**, additional SPI buses, or different GPIO assignments, you can enable a **software SPI bus** by installing one of two available **Software SPI Device Tree Overlay packages**.
65
+
66
+
67
+
#### Enabling a Software SPI Bus
68
+
To enable a software SPI bus, install one of the following overlay packages:
69
+
70
+
**For an SPI bus on GPIOs 14, 15, 16, and 17:**
71
+
```
72
+
opkg update
73
+
opkg install onion-dt-overlay-sw-spi
74
+
```
75
+
76
+
**For an SPI bus on GPIOs 0, 1, 2, and 3:**
77
+
```
78
+
opkg update
79
+
opkg install onion-dt-overlay-sw-spi-alt
80
+
```
81
+
82
+
After installation, the software SPI bus will be accessible at `/dev/spidev1.0`. Note this down for the next steps.
83
+
84
+
:::tip
85
+
86
+
Each package predefines the GPIOs that function as SPI signals. For more details, see the [Software SPI Bus article in the Device Tree Overlay chapter](/device-tree-overlay/software-spi).
87
+
88
+
:::
89
+
90
+
---
91
+
92
+
**Next Step:** Once you've chosen your SPI bus, proceed to [Step 3](#step-3-physically-connect-an-spi-device).
93
+
94
+
95
+
## Step 3: Physically Connect an SPI Device
41
96
42
97
Before we can send data, we need to connect an SPI device to the Omega2's SPI bus.
43
98
44
99
### Pin Connections
45
100
46
-
Connect the SPI pins of your external device to the Omega2 according to this table:
101
+
If you decided to use **hardware SPI** in Step 2, connect the SPI pins of your external device to the Omega2 according to this table:
47
102
48
-
| SPI Signal | Omega2 Pin |
103
+
| SPI Signal | Omega2 Pin |
49
104
|-------------|------------------|
50
105
| Clock / SCK | SPI_CLK / GPIO7 |
51
106
| MOSI | SPI_MOSI / GPIO8 |
52
107
| MISO | SPI_MISO / GPIO9 |
53
108
| CS | SPI_CS1 / GPIO6 |
54
109
110
+
If you decided to use **software SPI** in Step 2, connect the SPI pins of the external device according to the table below:
111
+
112
+
| SPI Signal | Omega2 Pin when using `onion-dt-overlay-sw-spi`| Omega2 Pin when using `onion-dt-overlay-sw-spi-alt`|
113
+
|-------------|---------|--------|
114
+
| Clock / SCK | GPIO14 | GPIO3 |
115
+
| MOSI | GPIO16 | GPIO1 |
116
+
| MISO | GPIO15 | GPIO0 |
117
+
| CS | GPIO17 | GPIO2 |
118
+
55
119
56
120
Additionally, make sure the SPI device is supplied with power according to its specifications.
57
121
58
-
## Step 3: SPI Hello World - Write Bytes to the Device
122
+
## Step 4: SPI Hello World - Write Bytes to the Device
59
123
60
124
To confirm that the SPI bus is working, we'll run a Python program that **writes 256 bytes of incremental data** over SPI in eight cycles.
If you decided to use a software SPI bus in step 2, the script needs to be updated to use the correct device.
139
+
140
+
Use the `vi` editor to modify the change
141
+
142
+
```
143
+
spi = spidev.SpiDev(0,1)
144
+
```
145
+
146
+
to
147
+
148
+
```
149
+
spi = spidev.SpiDev(1,0)
150
+
```
151
+
152
+
:::tip Using the vi Editor
153
+
154
+
If you're not familiar, the `vi` text editor is included on the Omega by default. To make the change:
155
+
1. Run `vi /root/writebytes.py`
156
+
1. Enter insert mode by pressing `i`
157
+
1. Make the changes
158
+
1. Return to command mode by pressing `esc` once
159
+
1. Save and close the file by typing `:wq` and pressing enter
160
+
161
+
Learn more about the small but powerful `vi` editor [online](https://www.redhat.com/en/blog/introduction-vi-editor).
162
+
163
+
:::
164
+
165
+
72
166
### Run the Program
73
167
74
168
Now, let’s run the script to send data over SPI:
@@ -77,11 +171,16 @@ Now, let’s run the script to send data over SPI:
77
171
python writebytes.py
78
172
```
79
173
80
-
This will send 256 bytes of incremental data (`0x00`, `0x01`, `0x02`, ...) over SPI, repeating 8 times. If you have a logic analyzer or oscilloscope connected, you should see activity.
174
+
This will send 256 bytes of incremental data (`0x00`, `0x01`, `0x02`, ...) over SPI, repeating 8 times. If you have a logic analyzer or oscilloscope connected, you should see activity:
*Logic analyzer showing eight blocks of SPI writes*
81
178
82
-
<!-- TODO: add screenhot output of logic analyzer? -->
179
+
Zooming in, we can confirm the data being sent is incremental:
180
+
181
+

83
182
84
-
## Step 4: Half-Duplex SPI Transmission
183
+
## Step 5: Half-Duplex SPI Transmission
85
184
86
185
Next, let's run a Python script that performs a half-duplex SPI transaction—meaning it writes a byte and immediately reads a specified number of bytes in return. This is useful for reading registers on an SPI device.
87
186
@@ -116,6 +215,35 @@ This kind of transaction is useful when interacting with SPI devices that store
116
215
117
216
To exit the vi editor without saving changes, type `:q!` and press Enter.
118
217
218
+
### Software SPI: Change SPI bus in script
219
+
220
+
If you decided to use a software SPI bus in step 2, the script needs to be updated to use the correct device.
221
+
222
+
Use the `vi` editor to modify the change
223
+
224
+
```
225
+
spi = spidev.SpiDev(0,1)
226
+
```
227
+
228
+
to
229
+
230
+
```
231
+
spi = spidev.SpiDev(1,0)
232
+
```
233
+
234
+
:::tip Using the vi Editor
235
+
236
+
If you're not familiar, the `vi` text editor is included on the Omega by default. To make the change:
237
+
1. Run `vi /root/xfer3.py`
238
+
1. Enter insert mode by pressing `i`
239
+
1. Make the changes
240
+
1. Return to command mode by pressing `esc` once
241
+
1. Save and close the file by typing `:wq` and pressing enter
242
+
243
+
Learn more about the small but powerful `vi` editor [online](https://www.redhat.com/en/blog/introduction-vi-editor).
244
+
245
+
:::
246
+
119
247
### Run the Program
120
248
121
249
How, execute the script:
@@ -128,14 +256,12 @@ python xfer3.py
128
256
The program will display the received bytes on the terminal:
0 commit comments