Go Down

Topic: >Working, with library!< Interfacing ADS1213 22-bit ADC (Read 16 times) previous topic - next topic


Murdock's library is obviously wrong.  If you try to use the set clock function, it does not operate at 2 MHz.  It operates at 8 MHz which is the wrong timing for ADC.


Great that you have taken the time to look through the code and seem to have found a bug, but please elaborate. I cannot find a fault in the code.

Datasheet pages 22 and 23 list the desired serial clock frequency, which is a maximum of 1/10th the clock speed. I try to achieve that by using delayMicroseconds() to delay the write and read code. The whole code takes a bit longer in reality but this method makes sure that the code is never faster than the ADS1213.

This code (from the initalization routine) calculates the desired delay in microseconds for half a clock cycle (the cycle is delayed twice: once for clock high, once for clock low):
int _tscaler = (clockspdMHz)*10;
byte _SCLKdelay = 5*10/_tscaler+1;

clockspdMHz is a float which is given in the initialization routine. If you give 2.0, _tscaler will be 20. _SCLKdelay will then be 3, giving a maximum SCLK frequency of 166kHz.

So I don't see what you mean, it doesn't run at 8MHz. If you use the ATMega's built-in SPI (= TWI) hardware, then it runs at 8MHz standard. My code doesn't use that.


I realize this is an old thread at this point and I hope some are still following it as I have a question about interfacing with an ADS1211.  After reading through several posts including this one, I am trying to use the library Murdock posted on Apr 19, 2011 (ADS1213) to log data from a geophone.  I've read through the spec sheet for the ADS1211 several times and think I have a beginners handle on how it works. 

I followed the wiring diagram from the first post on this thread, including using the arduino's internal timer but all I get out is a bunch of 0's.  I also tried to follow nadabro's post (http://arduino.cc/forum/index.php?topic=73149.0) as he is working with the same sensors and ADC.  Is there anyhting that I might be missing?  I would like to use the internal clock instead of an external crystal if possible but if that is my problem please let me know.

I'm sure you need more information to help me so please let me know what you need.  Right now my code is the example code for switching channels in the library (I like to start with the examples until I understand them enough to change them for my needs).  Thanks for any help you can provide.


Hi dkolbay, the latest version of the library (compatible with Arduino 1.0) is here (from the march 28th 2012 post up there ^).

With these kind of problems, it's always wise to take a step back in order to analyze the problem, then determine the simplest test possible, and then try to get it working.

Yours is obviously not working correctly or it wouldn't be spewing out zeroes. There can be problems somewhere in the communication, but the most obvious problem is that the clock signal (not serial clock) you are feeding to the ADS1211 is not correct. But let's first devise a simple test, as your sketch right now involves multiple write and read operations, too many opportunities for errors.

The simplest test would involve as few operations as possible and as simple feedback as possible. This could be 1) writing to the command register that Vbias must be on, making Vbias output some voltage and 2) reading this voltage with an analog Arduino pin. You can make a sketch to do this test and make it output a victorious message when the test succeeds.

If you want to feed a clock signal to the ADS1211, you'll have to configure one of Arduino's timers to do so. Timers are quite simple pieces of hardware, they simply count and when they reach a number, they do something. You can read all about it in the Atmega328's datasheet (it might seem overwhelming but keep in mind that timers are very simple devices, albeit with many configuration options). What you want is to 1) take a timer that controls a port that is not used by the library and 2) make it produce a square wave (thus output 0v and 5v with equal periods).

So if you have the test sketch that outputs a square wave to the ADS1211's clock input, writes to the command register and sets the Vbias high, and then reads the Vbias voltage on an analog Arduino pin, you can hook everything up and start testing. If it still doesn't work, you only have a few things to check. If it does work, hooray, and you can start expanding the code to fit your needs.

I dug in my sketches folders and found some code to output a square wave on a pin using a timer, I use it for producing tones with a speaker. The .h file (it's just a C file, you can open it with the Arduino IDE) contains the functions that set the timer and set tones. The .ino file houses an example sketch. It does a lot of direct register manipulation using bit math. The constants like "TCCR2A" that you see in the code are defined in the avr/io.h file (Arduino includes it automatically I believe), they are simply bits of code that write or read a register (in the "TCCR2A" case) or define where a port bit is in the register with a number between 0 and 7 (in the "OC2A" case), and _BV(n) is function that shifts a binary 1 n places to the left (1<<n).

I hope this helps you solve the problem, and if not, come back here with some more details.


May 15, 2013, 10:35 pm Last Edit: May 16, 2013, 12:47 am by MrInternet Reason: 1
Hey Murdock,

I've also been trying to use the library and the wiring diagram that you provided in the original post.  The library I'm using is the one from March 28th, 2012 so I know it's compatible with Arduino 1.0 software.  The problem I am having is that the code seems to get stuck on the constructor portion of the code and I've found that it starts to fail at the point when defining the high/low instructions for the data ready portion.  

I believe be code is something like while(!(PIND & _BV(_DRDY)));  - don't have the code in front of me as I'm typing this so typing from memory.  I've measured the voltage coming out of the data ready pin and its low until the serial monitor is brought up and then it jumps up to high which I assume is fine.  I'm not sure why the constructor is failing at that particular point and was wondering if maybe it has to do with where the data ready pin is located?  I've set the data ready pin to 4 on the arduino so I know that it falls between the constraints you have in the constructor and can't for the life of me figure out why it won't go past this point in the constructor.  Any help would be greatly appreciated.

Some basic information:
- wired it to the same wiring diagram you provided earlier with the crystal in being located on pin 3
- data ready pin 4
- IO pin 10
- Sout pin 12
- Sclk pin 13
- CS pin 8
- Running the standard deviation example you provided running into noninverting channel 1 and grounded the inverting channel 1
- "Debugged" by using the pin 13 LED to turn on and just went through section by section.
- haven't gotten to the rest of the code thou because the constructor is failing right now and therefore can't go beyond that point.

Go Up