[关闭]
@SiberiaBear 2016-04-02T10:07:49.000000Z 字数 912 阅读 2532

raspberryPi SPI module

raspberryPi

固定链接:https://www.zybuluo.com/SiberiaBear/note/48148


开启树莓派SPI模式

  1. sudo raspi-config

树莓派默认是不开启SPI的
查看/dev目录下是否有spidev0.0和spidev0.1

使用官方的spidev_test.c文件调试

1.下载spidev_test.c

  1. wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.10.y/Documentation/spi/spidev_test.c

2.gcc编译

  1. gcc -o spidev_test spidev_test.c

3.执行程序

  1. ./spidev_test -D /dev/spidev0.0

-D是其中一个参数,意为device to use,即选择设备spi0
还有其他好多参数,详见spidev_test.c程序

spidev_test.c程序解析

  1. stdint.h unistd.h stdio.h stdlib.h getopt.h fcntl.h sys/ioctl.h linux/types.h linux/spi/spidev.h
  1. #define ARRAY_SIZE(a)

这个宏用于动态测量需要传输的数据量长度。

  1. device mode bits speed delay
  1. void pabort(const char *s)
  2. void transfer(int fd)
  3. void print_usage(const char *prog)
  4. void parse_opts(int argc, char *argv[])
Created with Raphaël 2.1.2Main()parse_opts()fd = open(device, O_RDWR)ioctl(...)print()transfer(fd)close(fd)End
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注