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/07/13 05:29] nick |
products:sbc:common:applications:gpio:spi [2025/02/17 21:40] (current) nick [Enable SPI] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== SPI ====== | ||
| - | ===== Introduction | + | ===== SPI Reference table ===== |
| - | This document mainly introduces the usage of SPI on [[products:sbc:common:applications:gpio:40pin-header|40-Pin Header]]. | + | | |
| + | ^ VIM3/ | ||
| + | | ::: | ::: | | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | ^ VIM4 | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | ^ VIM1S | SPI_A | 29 | SPI_A_MOSI | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| - | ===== SPI Information ===== | + | ===== Enable |
| - | + | ||
| - | | | + | |
| - | ^ VIM3/ | + | |
| - | ^ VIM4 | + | |
| - | + | ||
| - | + | ||
| - | ===== Enabel | + | |
| 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 ''/ | ||
| - | Take VIM3 as an example to enable '' | + | Take VIM3 as an example to enable '' |
| ```shell | ```shell | ||
| Line 33: | Line 37: | ||
| After reboot, you will see the spi device node. | After reboot, you will see the spi device node. | ||
| + | ```shell | ||
| $ ls / | $ ls / | ||
| / | / | ||
| + | ``` | ||
| - | < | + | < |
| - | TODO. | + | Edit ''/ |
| - | </ | ||
| + | e.g. Enable '' | ||
| - | ===== Disable I2C to Use GPIO ===== | + | ```shell |
| + | fdt_overlays=spi1 | ||
| + | ``` | ||
| - | If you want to use normal GPIO instead of I2C, you can remove | + | After reboot, you will see the SPI device |
| + | ```shell | ||
| + | $ ls / | ||
| + | / | ||
| + | ``` | ||
| + | <tabbox VIM3L with 5.15 kernel> | ||
| - | ===== System Configuration ===== | + | Edit ''/ |
| + | |||
| + | |||
| + | e.g. Enable '' | ||
| - | The default SPI is disabled. If you need to use SPI, you can enable it through the overlays function. | ||
| ```shell | ```shell | ||
| - | $ sudo vim / | + | fdt_overlays=spi1 |
| ``` | ``` | ||
| - | Modify the overlays part, remove '' | ||
| - | ```diff | + | After reboot, you will see the SPI device node. |
| - | - overlays=uart3 pwm_f i2c3 os08a10 | + | |
| - | + overlays=i2c3 os08a10 spi1 | + | ```shell |
| + | $ ls / | ||
| + | / | ||
| ``` | ``` | ||
| - | Reboot | + | <tabbox VIM4> |
| + | |||
| + | Edit ''/ | ||
| - | <WRAP info > | ||
| - | For Overlays documentation, | ||
| - | </ | ||
| - | SPI configures a loopback test device by default. | + | e.g. Enable '' |
| ```shell | ```shell | ||
| - | $ ls / | + | fdt_overlays=spi0 |
| - | / | + | |
| ``` | ``` | ||
| - | ===== Demo Source Code ===== | + | After reboot, you will see the SPI device node. |
| - | Get test code | + | ```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 ===== | ||
| + | |||
| + | If you want to use normal GPIO instead of SPI, you can remove the SPI node in [[products: | ||
| + | |||
| + | |||
| + | ===== Demo Source Code ===== | ||
| ```c spidev_test.c | ```c spidev_test.c | ||
| Line 112: | 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 561: | Line 607: | ||
| ``` | ``` | ||
| - | Compile test code | + | Compile test code: |
| ```shell | ```shell | ||
| Line 567: | Line 613: | ||
| ``` | ``` | ||
| - | ===== Demonstrate | + | ===== Test demonstration |
| - | + | Prepare | |
| - | Prepare | + | |
| ```shell | ```shell | ||
| Line 576: | Line 621: | ||
| ``` | ``` | ||
| - | Run '' | + | Connect PIN36(MOSI), |
| + | |||
| ```shell | ```shell | ||
| - | $ ./ | + | $ ./ |
| spi mode: 0x0 | spi mode: 0x0 | ||
| bits per word: 8 | bits per word: 8 | ||
| Line 585: | Line 632: | ||
| ``` | ``` | ||
| - | Check output data. | + | <WRAP important > |
| + | Please choose the correct spi device node. | ||
| + | </ | ||
| + | |||
| + | |||
| + | Check output data: | ||
| ```shell | ```shell | ||
| $ cat ./ | $ cat ./ | ||
| Amazing Khadas! | Amazing Khadas! | ||
| ``` | ``` | ||