Linux - Embedded & Single-board computerThis forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The first 1,5 Bytes of tx contain the measurement request and the converter writes the result into the last 1,5 Bytes of rx. All works well.
Unfortunately, the whole thing is way too slow. It blocks for 6,6ms on my board, which is not what i want. Is there a possibility to speed the call up or at least do it asynchronously, so that the application can do something useful in the mean time (Apart from spawning an additional thread)?
Hi, check <linux kernel source directory>/Documentation/spi/spi_summary. I worked with SPI some years ago and it worked very well, but I don't remember the details right now.
The documentation you suggested describes how to build an SPI driver. Am I supposed to write my own driver? I have never done that before... Do you expect a large performance advantage over the userspace API?
I'm sorry, that document is just where I had found out CPOL and CPHA values, but I guess it's the only reference I wrote down back then.
Here are some fragments of the code I wrote years ago.
Initialization:
Code:
int spidev_fd;
uint8_t spi_tx_buf,
spi_mode,
spi_bpw;
uint8_t spi_rx_buf = 0;
uint16_t spi_delay_us = 0; // if nonzero, how long to delay after the last bit transfer before optionally deselecting
// the device before the next transfer
uint32_t spi_speed;
static const char * spi_device = "/dev/spidev0.0";
// open SPI device
spidev_fd = open(spi_device, O_RDWR);
// set SPI mode
spi_mode |= SPI_CPHA;
ret = ioctl(spidev_fd, SPI_IOC_WR_MODE, &spi_mode);
ret = ioctl(spidev_fd, SPI_IOC_RD_MODE, &spi_mode);
// set number of bits per word
spi_bpw = 8;
ret = ioctl(spidev_fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bpw);
ret = ioctl(spidev_fd, SPI_IOC_RD_BITS_PER_WORD, &spi_bpw);
// set max speed (in Hz)
spi_speed = 500 * 1000;
ret = ioctl(spidev_fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed);
ret = ioctl(spidev_fd, SPI_IOC_RD_MAX_SPEED_HZ, &spi_speed);
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.