AnsweredAssumed Answered

AD7193: SPI communication problems with a Raspberry Pi as SPI master

Question asked by DRies on Aug 26, 2013
Latest reply on Sep 3, 2013 by ChrisD.Rama

Hi there,


I am trying to interface a AD7193 (on a Digilent PmodAD5) with a Raspberry Pi running raspbian linux. I am using C and the spidev linux kernel interface for SPI.


I ran into several problems:


1: Resetting (sending 40 1's) does not seem to work by sending 0xFF, 0xFF, 0xFF, 0xFF, 0xFF. By manually putting the SPI pins into GPIO mode and bit-banging 40 1's, it worked. Looking at the communication with a scope revealed that the spidev driver seems to to pull down MOSI between bytes. Is it correct, that this prevents the AD7193 from resetting? There are no SCLK edges during the time MOSI is low.


2.: I can read registers after resetting the device, but it only seems to work during the first SPI transfer. Any ideas on why that could be the case? For example reading the device identifier once works, but the second time doesn't:


uint8_t tx1[] = { 0x60, 0x00 };
transfer(fd, tx1, 2);

uint8_t tx2[] = { 0x60, 0x00 };
transfer(fd, tx2, 2);


results in:

read ID reg:
spi MISO:


read ID reg again:
spi MISO:



where transfer() is defined as:

static void transfer(int fd, uint8_t * tx, int nobytes)
        int ret;

        uint8_t rx[nobytes];// = {0, };
        int i;


        struct spi_ioc_transfer tr = {
                .tx_buf = (unsigned long)tx,
                .rx_buf = (unsigned long)rx,
                .len = nobytes,
                .delay_usecs = delay,
                .speed_hz = speed,
                .bits_per_word = bits,


        ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
        if (ret < 1)
                pabort("can't send spi message");


        printf("spi MISO:");
        for (ret = 0; ret < nobytes; ret++) {
                if (!(ret % 6))
                printf("%.2X ", rx[ret]);


I cannot yet create nice scope pictures, maybe tomorrow I will get my hands on a better scope...


I would much appreciate any help here.