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


    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.