Problem with AD7193 and SPI...

Hi, I’m trying to communicate with the AD7193:

but having no success - I can initialize the device by sending 40 1’s in a row as the docs describe, but I am unable to get more than one command from it, and it seems to hang afterwards. I’ve attached a screen cap from my logic analyzer, and I think everything in the SPI communications looks correct. In the screencap, I make the same request twice - the command is 0x60 which requests a read of the ID register (page 21 of the datasheet), and returns one byte, the top 4 bits are irrelevant, and the bottom 4 bits should contain 0010 (0x?2). I’ve tried two of the same AD7193 boards, and I’ve also tried an Uno and Mega, and they all show the same behavior, and return 0xA7 the first time, and are unresponsive until sending the 40 1’s in a row again.

The device runs Mode 3 (datasheet page 8/9), and I’ve tried their library which I converted to use the hardware SPI library Arduino comes with, I’ve tried the Arduino SPI library directly, and I’ve also tried SoftSPI, all with the same results.

Really at a loss here as to what the issue might be, so any help would be appreciated. Thanks!

I apologize for posting this to such an old thread but I couldn’t find the answer anywhere else and I finally figured this out. I’m hoping that anyone using an AD7193 might benefit. It’s a bit pricey (~$11) for an ADC so that’s probably why it doesn’t get more use.

There’s a header file and a C file out there that works almost out of the box, or seems to. It compiles well enough. You can get a value or two from the chip but then when you try to read data you get nothing. And it seems to do this with Arduino’s IDE but the same code with others works. The reason is that all through the header file they have #defines where they’re bit-shifting constants. This works a treat to let you use more English names for these values without having to refer to the datasheet all the time, and you can OR the values together and fill in a register really easily. The problem is that the compiler in the Arduino IDE is type casting those constants to ints and their real destination is an unsigned long. Many of the very important bits are out in the high teens and 20s. So casting them to ints and then shifting them just overflows the int and you get a big fat 0. The chip is then totally confused.

So the fix is to typecast all the bit shifting constants in the header file with uint32_t(). Then it works great. Took me a while to figure it out. Hopefully this header with the widely available C will let you use it. If I get time I’ll just pair them up and put a real library out there.

AD7193.h (12.2 KB)

1 Like