LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This 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


Reply
  Search this Thread
Old 11-30-2020, 03:22 PM   #1
RogueWarrior65
Member
 
Registered: Aug 2010
Posts: 48

Rep: Reputation: 0
Question SPI Chip Select timing


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.
 
Old 12-01-2020, 11:05 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,289

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
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.
 
Old 12-02-2020, 08:51 AM   #3
RogueWarrior65
Member
 
Registered: Aug 2010
Posts: 48

Original Poster
Rep: Reputation: 0
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.
 
Old 12-02-2020, 01:25 PM   #4
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,289

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
Quote:
Originally Posted by RogueWarrior65 View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
U-boot does not recognize SPI flash chip MALDATA Linux - Embedded & Single-board computer 0 01-09-2020 08:44 PM
make the Slave select high and low alternately in Spi zhangz64 Programming 2 07-19-2013 06:00 PM
how to start timing and print the timing result on portions of java codes ?? alred Programming 2 05-15-2006 10:00 AM
how do I read a camera chip thru an internal usb chip reader? CPUFreak91 Linux - Newbie 2 07-20-2005 12:15 AM
Select() did not select my socket thvo Programming 1 05-08-2005 12:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 02:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration