This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
products:sbc:common:applications:gpio:spi [2022/10/07 23:11] hyphop [Introduction] |
products:sbc:common:applications:gpio:spi [2025/02/17 21:40] (current) nick [Enable SPI] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== SPI ====== | ||
| - | SPI interface usage examples on [[products: | + | ===== SPI Reference table ===== |
| - | + | ||
| - | ===== Reference table ===== | + | |
| - | + | ||
| - | | | + | |
| - | ^ VIM3/ | + | |
| - | | ::: | ::: | + | |
| - | | ::: | ::: | + | |
| - | | ::: | ::: | + | |
| - | ^ VIM4 | + | |
| + | | | ||
| + | ^ VIM3/ | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | ^ VIM4 | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | ^ VIM1S | SPI_A | 29 | SPI_A_MOSI | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| ===== Enable SPI ===== | ===== Enable SPI ===== | ||
| Line 17: | Line 20: | ||
| In order to use the SPI, you need to enable the SPI function via [[products: | In order to use the SPI, you need to enable the SPI function via [[products: | ||
| - | < | + | < |
| Edit ''/ | Edit ''/ | ||
| Line 37: | Line 40: | ||
| $ ls / | $ ls / | ||
| / | / | ||
| + | ``` | ||
| + | |||
| + | <tabbox VIM3 with 5.15 kernel> | ||
| + | |||
| + | Edit ''/ | ||
| + | |||
| + | |||
| + | e.g. Enable '' | ||
| + | |||
| + | ```shell | ||
| + | fdt_overlays=spi1 | ||
| + | ``` | ||
| + | |||
| + | After reboot, you will see the SPI device node. | ||
| + | |||
| + | ```shell | ||
| + | $ ls / | ||
| + | / | ||
| + | ``` | ||
| + | |||
| + | <tabbox VIM3L with 5.15 kernel> | ||
| + | |||
| + | Edit ''/ | ||
| + | |||
| + | |||
| + | e.g. Enable '' | ||
| + | |||
| + | ```shell | ||
| + | fdt_overlays=spi1 | ||
| + | |||
| + | ``` | ||
| + | |||
| + | After reboot, you will see the SPI device node. | ||
| + | |||
| + | ```shell | ||
| + | $ ls / | ||
| + | / | ||
| ``` | ``` | ||
| <tabbox VIM4> | <tabbox VIM4> | ||
| - | TODO. | + | Edit ''/ |
| - | </ | ||
| + | e.g. Enable '' | ||
| + | |||
| + | ```shell | ||
| + | fdt_overlays=spi0 | ||
| + | |||
| + | ``` | ||
| + | |||
| + | After reboot, you will see the SPI device node. | ||
| + | |||
| + | ```shell | ||
| + | $ ls / | ||
| + | / | ||
| + | ``` | ||
| + | <tabbox VIM1S> | ||
| + | |||
| + | Edit ''/ | ||
| + | |||
| + | |||
| + | e.g. Enable '' | ||
| + | |||
| + | ```shell | ||
| + | fdt_overlays=spi0 | ||
| + | |||
| + | ``` | ||
| + | |||
| + | After reboot, you will see the SPI device node. | ||
| + | |||
| + | ```shell | ||
| + | $ ls / | ||
| + | / | ||
| + | ``` | ||
| + | |||
| + | </ | ||
| - | ===== Disable SPI to Use GPIO ===== | + | ===== Disable SPI ===== |
| If you want to use normal GPIO instead of SPI, you can remove the SPI node in [[products: | If you want to use normal GPIO instead of SPI, you can remove the SPI node in [[products: | ||
| Line 52: | Line 124: | ||
| ===== Demo Source Code ===== | ===== Demo Source Code ===== | ||
| - | |||
| - | **Get test code.** | ||
| ```c spidev_test.c | ```c spidev_test.c | ||
| Line 88: | Line 158: | ||
| } | } | ||
| - | static const char *device = "/ | + | static const char *device = "/ |
| static uint32_t mode; | static uint32_t mode; | ||
| static uint8_t bits = 8; | static uint8_t bits = 8; | ||
| Line 537: | Line 607: | ||
| ``` | ``` | ||
| - | **Compile test code.** | + | Compile test code: |
| ```shell | ```shell | ||
| Line 543: | Line 613: | ||
| ``` | ``` | ||
| - | ===== Demonstrate | + | ===== Test demonstration |
| - | + | Prepare | |
| - | **Prepare | + | |
| ```shell | ```shell | ||
| Line 552: | Line 621: | ||
| ``` | ``` | ||
| - | **Run '' | + | Connect PIN36(MOSI), |
| + | |||
| ```shell | ```shell | ||
| - | $ ./ | + | $ ./ |
| spi mode: 0x0 | spi mode: 0x0 | ||
| bits per word: 8 | bits per word: 8 | ||
| Line 561: | Line 632: | ||
| ``` | ``` | ||
| - | **Check output data.** | + | <WRAP important > |
| + | Please choose the correct spi device node. | ||
| + | </ | ||
| + | |||
| + | |||
| + | Check output data: | ||
| ```shell | ```shell | ||