We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Problems with SpiDev in C



  • Hello,

    I'm reading A/D data over the HW SPI using SpiDev driver.

    This is the datasheet of the A/D chip im reading from

    https://www.ti.com/lit/ds/symlink/ads7866.pdf?HQS=dis-dk-null-digikeymode-dsf-pf-null-wwe&ts=1668659017378&ref_url=https%3A%2F%2Fwww.ti.com%2Fgeneral%2Fdocs%2Fsuppproductinfo.tsp%3FdistId%3D10%26gotoUrl%3Dhttps%3A%2F%2Fwww.ti.com%2Flit%2Fgpn%2Fads7866

    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.

    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.

    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?

    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; // <<<<<<<<<<< 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);

Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.