Guest User

Untitled

a guest
Jun 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <sys/ioctl.h>
  2. #include <linux/spi/spidev.h>
  3.  
  4. int fd;
  5. unsigned char buf[8192]; // Nice if this is page aligned
  6. unsigned char cmd[2];
  7. struct spi_ioc_txr xfer[3]; //struct is 32 bytes x3
  8. int status;
  9.  
  10. fd = open('/dev/spidev<bus>.<device>', O_RDWR)
  11. // handle error if fd < 0
  12.  
  13. memset - buf, cmd, xfer
  14. cmd[0] = address >> 4;
  15. cmd[1] = (address << 4) & 0xff;
  16. if(read_command) {
  17. cmd[1] |= 1 << 3;
  18. } // else write command
  19. xfer[0].tx_buf = (unsigned long)cmd;
  20. xfer[0].len = 2
  21. xfer[0].speed_hz = 20000000; // 20,000,000 20MHz
  22.  
  23. xfer[1].rx_buf = (unsigned long)buf;
  24. xfer[1].len = 4096;
  25. xfer[1].speed_hz = 20000000;
  26. xfer[2].rx_buf = (unsigned long)(buf + 4096);
  27. xfer[2].len = 4096;
  28. xfer[2].speed_hz = 20000000;
  29.  
  30. status = ioctl(fd, SPI_IOC_MESSAGE(3), xfer);
  31. // error if < 0
  32. // data now in xfer as bytes
  33.  
  34. $ sudo rmmod spidev
  35. $ sudo modprobe spidev bufsiz=8192
  36.  
  37. $ echo "options spidev bufsiz=8192" | sudo tee /etc/modprobe.d/spidev.conf
Add Comment
Please, Sign In to add comment