<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problems with SpiDev in C]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I'm reading A/D data over the HW SPI using SpiDev driver.</p>
<p dir="auto">This is the datasheet of the A/D chip im reading from</p>
<p dir="auto"><a href="https://www.ti.com/lit/ds/symlink/ads7866.pdf?HQS=dis-dk-null-digikeymode-dsf-pf-null-wwe&amp;ts=1668659017378&amp;ref_url=https%253A%252F%252Fwww.ti.com%252Fgeneral%252Fdocs%252Fsuppproductinfo.tsp%253FdistId%253D10%2526gotoUrl%253Dhttps%253A%252F%252Fwww.ti.com%252Flit%252Fgpn%252Fads7866" rel="nofollow">https://www.ti.com/lit/ds/symlink/ads7866.pdf?HQS=dis-dk-null-digikeymode-dsf-pf-null-wwe&amp;ts=1668659017378&amp;ref_url=https%3A%2F%2Fwww.ti.com%2Fgeneral%2Fdocs%2Fsuppproductinfo.tsp%3FdistId%3D10%26gotoUrl%3Dhttps%3A%2F%2Fwww.ti.com%2Flit%2Fgpn%2Fads7866</a></p>
<p dir="auto">On page 9 you can see the SPI timing diagram, which seems to say the chip has only a read mode where you clock it and it sends back the A/D reading only, there is no need to write anything.</p>
<p dir="auto">Here is the SPiDrv read code below showing that we have to write 0x01 and 2 address bytes, and then read back the lengh of data. But the SPI A/D chip only requires reading data, there is no address to write, seems to violate the SPI HW protocol which has no requirement to write an address first.</p>
<p dir="auto">Has anybody had this problem if the driver forcing you to write a 2 byte address first and then reading back the length when the chip doesnt do that?</p>
<pre><code>char * spi_read(int add1,int add2,int nbytes,int file)
{
int status;

memset(buf, 0, sizeof buf);
memset(buf2, 0, sizeof buf2);

buf[0] = 0x01;
buf[1] = add1;
buf[2] = add2;

xfer[0].tx_buf = (unsigned long)buf;
xfer[0].len = 3; // &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; Length of  command to write

xfer[1].rx_buf = (unsigned long) buf2;
xfer[1].len = nbytes; /* Length of Data to read */

status = ioctl(file, SPI_IOC_MESSAGE(2), xfer);</code></pre>
]]></description><link>http://community.onion.io/topic/4904/problems-with-spidev-in-c</link><generator>RSS for Node</generator><lastBuildDate>Sun, 15 Nov 2026 09:17:23 GMT</lastBuildDate><atom:link href="http://community.onion.io/topic/4904.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 18 Nov 2022 13:50:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problems with SpiDev in C on Fri, 18 Nov 2022 14:41:47 GMT]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I'm reading A/D data over the HW SPI using SpiDev driver.</p>
<p dir="auto">This is the datasheet of the A/D chip im reading from</p>
<p dir="auto"><a href="https://www.ti.com/lit/ds/symlink/ads7866.pdf?HQS=dis-dk-null-digikeymode-dsf-pf-null-wwe&amp;ts=1668659017378&amp;ref_url=https%253A%252F%252Fwww.ti.com%252Fgeneral%252Fdocs%252Fsuppproductinfo.tsp%253FdistId%253D10%2526gotoUrl%253Dhttps%253A%252F%252Fwww.ti.com%252Flit%252Fgpn%252Fads7866" rel="nofollow">https://www.ti.com/lit/ds/symlink/ads7866.pdf?HQS=dis-dk-null-digikeymode-dsf-pf-null-wwe&amp;ts=1668659017378&amp;ref_url=https%3A%2F%2Fwww.ti.com%2Fgeneral%2Fdocs%2Fsuppproductinfo.tsp%3FdistId%3D10%26gotoUrl%3Dhttps%3A%2F%2Fwww.ti.com%2Flit%2Fgpn%2Fads7866</a></p>
<p dir="auto">On page 9 you can see the SPI timing diagram, which seems to say the chip has only a read mode where you clock it and it sends back the A/D reading only, there is no need to write anything.</p>
<p dir="auto">Here is the SPiDrv read code below showing that we have to write 0x01 and 2 address bytes, and then read back the lengh of data. But the SPI A/D chip only requires reading data, there is no address to write, seems to violate the SPI HW protocol which has no requirement to write an address first.</p>
<p dir="auto">Has anybody had this problem if the driver forcing you to write a 2 byte address first and then reading back the length when the chip doesnt do that?</p>
<pre><code>char * spi_read(int add1,int add2,int nbytes,int file)
{
int status;

memset(buf, 0, sizeof buf);
memset(buf2, 0, sizeof buf2);

buf[0] = 0x01;
buf[1] = add1;
buf[2] = add2;

xfer[0].tx_buf = (unsigned long)buf;
xfer[0].len = 3; // &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; Length of  command to write

xfer[1].rx_buf = (unsigned long) buf2;
xfer[1].len = nbytes; /* Length of Data to read */

status = ioctl(file, SPI_IOC_MESSAGE(2), xfer);</code></pre>
]]></description><link>http://community.onion.io/post/24967</link><guid isPermaLink="true">http://community.onion.io/post/24967</guid><dc:creator><![CDATA[nsmith]]></dc:creator><pubDate>Fri, 18 Nov 2022 14:41:47 GMT</pubDate></item></channel></rss>