This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS8686S: Unable to read data from the ADS8686S

Part Number: ADS8686S
Other Parts Discussed in Thread: AM625,

Tool/software:

Hi,

i am trying to read data from the ADS8686S using SPIdev0.0 in my AM625 board.we are using ADS8686S-EVM.

 I have connected the SER/BYTE/PAR pin to Logic high(3.3V) and DB9 to logic low(Gnd) to select the Serial interface mode. DB4 is connected to the GND to select the 1 wire Mode.

below is my test code where i am trying to read data from a register.

#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>

#define SPI_DEVICE "/dev/spidev0.0"  // SPI device path (change according to your setup)

int main() {
    int fd;
    unsigned char tx_buffer[2] = { 0x20, 0x00 };  // Example TX buffer (send 4 bytes of 0x00)
    unsigned char rx_buffer[2] = { 0 };  // RX buffer to store received data
    struct spi_ioc_transfer transfer = {
        .tx_buf = (unsigned long)tx_buffer,
        .rx_buf = (unsigned long)rx_buffer,
        .len = sizeof(tx_buffer),
        .delay_usecs = 0,
        .speed_hz = 10000000,  // SPI clock speed in Hz (adjust as needed)
        .bits_per_word = 8,
    };

    // Open SPI device
    fd = open(SPI_DEVICE, O_RDWR);
    if (fd < 0) {
        perror("Error opening SPI device");
        return -1;
    }

    // Perform SPI transfer
    if (ioctl(fd, SPI_IOC_MESSAGE(1), &transfer) < 0) {
        perror("Error in SPI_IOC_MESSAGE");
        return -1;
    }

    // Perform SPI transfer
    if (ioctl(fd, SPI_IOC_MESSAGE(1), &transfer) < 0) {
        perror("Error in SPI_IOC_MESSAGE");
        return -1;
    }

    // Display received data (optional)
    printf("Received data:");
    for (int i = 0; i < sizeof(rx_buffer); i++) {
        printf(" 0x%02X", rx_buffer[i]);
    }
    printf("\n");

    // Perform SPI transfer
    if (ioctl(fd, SPI_IOC_MESSAGE(1), &transfer) < 0) {
        perror("Error in SPI_IOC_MESSAGE");
        return -1;
    }

    // Display received data (optional)
    printf("Received data:");
    for (int i = 0; i < sizeof(rx_buffer); i++) {
        printf(" 0x%02X", rx_buffer[i]);
    }
    printf("\n");

    // Close SPI device
    close(fd);

    return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#include <linux/spi/spi.h>

#define SPI_DEVICE "/dev/spidev0.0" // SPI device node

int main() {
    int spi_fd;
    uint16_t reg_address = 0x0400;
    uint16_t tx_buffer[1] = {0x2000}; // Transmit buffer
    uint16_t rx_buffer[1] = { 0x0000}; // Receive buffer

    // Open SPI device
    spi_fd = open(SPI_DEVICE, O_RDWR);
    if (spi_fd < 0) {
        perror("Error opening SPI device");
        return 1;
    }

    // SPI mode (0, 1, 2, or 3)
    uint8_t mode = SPI_MODE_0;

    // Set SPI mode
    if (ioctl(spi_fd, SPI_IOC_WR_MODE, &mode) < 0) {
        perror("Error setting SPI mode");
        return 1;
    }

    // Set SPI mode
    if (ioctl(spi_fd, SPI_IOC_RD_MODE, &mode) < 0) {
        perror("Error setting SPI mode");
        return 1;
    }

    uint8_t bits_per_word = 16;

    if (ioctl(spi_fd, SPI_IOC_WR_BITS_PER_WORD, &bits_per_word) < 0) {
        perror("Error setting SPI bits per word");
        return -1;
    }

    if (ioctl(spi_fd, SPI_IOC_RD_BITS_PER_WORD, &bits_per_word) < 0) {
        perror("Error setting SPI bits per word");
        return -1;
    }


    // SPI clock speed (Hz)
    uint32_t speed_hz = 40000000; // 15MHz

    // Set SPI clock speed
    if (ioctl(spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed_hz) < 0) {
        perror("Error setting SPI clock speed");
        return 1;
    }

    // Set SPI clock speed
    if (ioctl(spi_fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed_hz) < 0) {
        perror("Error setting SPI clock speed");
        return 1;
    }



    // Populate tx_buffer with data to be sent (if necessary)
    //     // Read data from SPI device
    if (write(spi_fd, tx_buffer, 2) != sizeof(tx_buffer)) {
        perror("Error reading from SPI device");
        return 1;
    }


    // Read data from SPI device
    if (read(spi_fd, rx_buffer, 2) != sizeof(rx_buffer)) {
        perror("Error reading from SPI device");
        return 1;
    }

    // Read data from SPI device
    if (read(spi_fd, rx_buffer, 2) != sizeof(rx_buffer)) {
        perror("Errostatic ssize_t");
        return 1;
    }


    // Print received data
    printf("Received data: ");
    for (int i = 0; i < sizeof(rx_buffer); i++) {
        printf("%02x ", rx_buffer[i]);
    }
    printf("\n");

    // Close SPI device
    close(spi_fd);

    return 0;
}

i have tried the both methods, but i am always getting 0 in rx_buffer.

Kindly check this issue.

  • Hi naveenkumar,

    Can you please post a schematic snippet that shows the connections to the ADS8686S as well as o'scope or logic analyzer plots that show your control lines?  The functions help, but a picture is worth a thousand lines of code...