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.
I’m working with the SPI interface and using the SPIDEV driver to talk to an ADC device. This device requires a one-byte write and a two-byte read. It can handle a clock speed of 1.8 MHz and a sample rate of 100 ksps.
It works but it’s running very slowly. I’ve connected a logic analyzer to the system and I can see that the system is wasting a lot of time between SPI transactions where the chip select line is held low.
At the start of the transaction, it sets the chip select line for about 20 microseconds before the system starts clocking out the write data. After it reads the two response bytes, it wastes about 65 microseconds before resetting the chip select line. Basically, no matter what I do, the transaction always seems to take ~100 microseconds thus cutting my ADC sampling rate by a factor of 10.
Is this a driver issue or a kernel SPI code issue or what?
Does anyone know where in the kernel code the chip select timing is being set?
100 microseconds seems like a pretty specific value.
Two other random variables are not being mentioned - the ADC settling time, and any config you may have done. You apparently have a clue what the circuit looks like, but we don't. Is there a schematic online?
As width increases, ADC settling time increases. Also, you need to isolate what's holding /CS down.
Allow me to clarify, the presence of the ADC device is incidental because I'm not actually using a device-specific driver. I'm using the generic spidev driver to talk to it directly. The device happens to be a Microchip MCP3204. The timings of that device are in the nanosecond realm.
Under the Linux kernel 4.9.11 that I'm using, it would appear that the only function that sets or clears the chip select line is in spi.c called spi_transfer_one_message(). There is a call to wait_for_completion_timeout() in there which might explain the delay in clearing the chip select line at the end of the transaction but not at the beginning.
Allow me to clarify, the presence of the ADC device is incidental because I'm not actually using a device-specific driver. I'm using the generic spidev driver to talk to it directly. The device happens to be a Microchip MCP3204. The timings of that device are in the nanosecond realm.
Under the Linux kernel 4.9.11 that I'm using, it would appear that the only function that sets or clears the chip select line is in spi.c called spi_transfer_one_message(). There is a call to wait_for_completion_timeout() in there which might explain the delay in clearing the chip select line at the end of the transaction but not at the beginning.
So like most hardware issues, it really seems to be a software issue.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.