开始学习
< 返回

spi-config 命令

介绍

spi-config 命令用于在用户空间查询或设置 SPI 总线配置。

spi-config 命令由 spi-tools 软件包提供,在 Debian/Ubuntu 系统上可以使用如下命令进行安装。

sudo apt install spi-tools

语法

spi-config [options...]

选项

  • -d, --device=DEVICE :使用指定的 spidev 字符设备

  • -q, --query :打印当前的配置

  • -m, --mode=[0-3] :设置 SPI 模式

  • -l, --lsb={0,1} :设置数据传输方式为 LSB first (1) 或者 MSB first (0)

  • -b, --bits=[7...] :设置每个字(word)的位数

  • -s, --speed=FREQUENCY :设置时钟频率(单位 Hz)

  • -r, --spirdy={0,1} :设置 SPI READY 模式标志

  • -s, --wait :阻塞,保持文件描述符打开

  • -h, --help :查看帮助并退出

  • -v, --version :查看版本信息并退出

SPI 模式

模式 描述
mode 0 low iddle level, sample on leading edge.
mode 1 low iddle level, sample on trailing edge.
mode 2 high iddle level, sample on leading edge.
mode 3 high iddle level, sample on trailing edge.

相关命令:spi-pipe

示例

查询 /dev/spidev0.0 设备当前配置

spi-config --device=/dev/spidev0.0 -q

修改时钟频率为1MHz

spi-config --device=/dev/spidev0.0 --speed=1000000

设置配置并保持设备开启

spi-config --wait -d /dev/spidev0.0 -s 1000000 & PID=$!

注:$! 是 Shell 最后运行的后台进程的 PID

关闭之前打开的设备

kill $PID
Was this article helpful?
5 out of 5 stars

1 rating

5 Stars 100%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
Please Share Your Feedback
How Can We Improve This Article?
文章目录