Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/ioctl.h>
- #include <linux/spi/spidev.h>
- int fd;
- unsigned char buf[8192]; // Nice if this is page aligned
- unsigned char cmd[2];
- struct spi_ioc_txr xfer[3]; //struct is 32 bytes x3
- int status;
- fd = open('/dev/spidev<bus>.<device>', O_RDWR)
- // handle error if fd < 0
- memset - buf, cmd, xfer
- cmd[0] = address >> 4;
- cmd[1] = (address << 4) & 0xff;
- if(read_command) {
- cmd[1] |= 1 << 3;
- } // else write command
- xfer[0].tx_buf = (unsigned long)cmd;
- xfer[0].len = 2
- xfer[0].speed_hz = 20000000; // 20,000,000 20MHz
- xfer[1].rx_buf = (unsigned long)buf;
- xfer[1].len = 4096;
- xfer[1].speed_hz = 20000000;
- xfer[2].rx_buf = (unsigned long)(buf + 4096);
- xfer[2].len = 4096;
- xfer[2].speed_hz = 20000000;
- status = ioctl(fd, SPI_IOC_MESSAGE(3), xfer);
- // error if < 0
- // data now in xfer as bytes
- $ sudo rmmod spidev
- $ sudo modprobe spidev bufsiz=8192
- $ echo "options spidev bufsiz=8192" | sudo tee /etc/modprobe.d/spidev.conf
Add Comment
Please, Sign In to add comment