[beagleboard] ADC SPI beagleboard assistance

Hello everybody,
I am stuck and stumped on coding a script that will communicate with an ADC. I need to get data from the ADC, which is connected to the beagleboard via expansion header, but I am stuck on how to properly write the script. If there are any helpful and newb friendly samples or people willing to give me some guidance, I appreciate it.
More detail: I am using a beagleboard rev C4 and using an ads1118 ADC made by TI,running ubuntu kernel version 3.2.24



first of all: did you get SPI running on your beagleboard? did you try the spidev_test program (included in the linux kernel source tree under Documentation/spi/spidev_test.c).

spidev_test can be your starting point for another script that talks to the ADC.


Yes I got SPI working and ran an spi test. It worked properly


Great, now you have to carefully read the datasheet of your ADC and then try to modify spidev_test in order to send the correct sequence of byte to drive your ADC.

Another good starting point is here: http://armbedded.eu/node/318

There you will find another small program that explains how to talk spi. Moreover, it would be helpful if you have an oscilloscope. It enables you to “see” the bit on the wire and understand immediately what happens between your devices.

Okay so I looked at the spi code, and it seems like I have to adjust the transfer function to send the correct bytes to the ADC (as you stated).
I looked at the ADC spec sheet (http://www.ti.com/lit/ug/sbau184/sbau184.pdf) and I noticed for the proper Data Retrieval I had to send the most significant byte as 00 and the Least significant byte as 83. This hopefully runs continuous conversion made properly for the ADC.
I also used an evaluation board the chip came with to make sure the Figures in the spec sheet matched the oscilloscope readings:


Glad to hear this from you. I trying to do the exact same thing. My adc is an MCP3204 and I’m using a beagle bone right now.

Are you using beagle bone or beagle board?

Right now I am using a beagleboard Rev C4 and I am still working on the code, I haven’t got the code working yet.


Hello again. I am wondering if you have made any progress on ADC programming.

Uhmmm…I’m testing spi in general right now (still no adc connected) and there are some problems. For example, I can’t get the desired clock frequency even if I configure it explicitly. Moreover, the signal read by my scope looks strange. It should be a perfect square wave (being made of logical “0” and “1”) but the rightmost edge on the screen is “crooked” (not straight). So the edge doesn’t fall to 0 instantaneously but slowly.

Please read the complete story here. You will find also the little program I used to test spi. Maybe we could improve.

Best Regards!

I am a beginner of beaglebone can any one has a sample code for ADC and GPIO for it.
Help me Please

Hello again. I am wondering if you have made any progress on ADC programming.

Why don’t you look at the drivers in drivers/staging/iio

There are many examples of drivers using both SPI and I2C. Most of these drivers present the results as file entries in /sys/bus/iio/devices/…. so it will be easy to read the values from languages such as python, perl, scripts, etc.



– To join: http://beagleboard.org/discuss
To unsubscribe from this group, send email to:
Frequently asked questions: http://beagleboard.org/faq

So where do I exactly go to see these examples, because I just need to read data from the ADC, but I am too much of a newbie to figure that out.

If anybody can help me out, here is an update of what I have been doing:


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

static const char *device = “/dev/spidev3.0”;

ReadADCADS1118(int fd, float &voltage)
int ret;
uint8_t tx_buf[] = { 0x00, 0x83 };
uint8_t rx_buf[2];

struct spi_ioc_transfer tr;
uint8_t mode = SPI_MODE_3;
uint32_t spi_speed = 4000000;
unsigned long Volts;

fd = open(device, O_RDWR);
if (fd < 0)
pabort(“can’t open device”);

ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if (ret == -1)
pabort(“can’t set spi mode”);

tx_buf[0] = 0xFF;
spi_tr.tx_buf = (unsigned long)tx_buf;
if( ioctl(fd, SPI_IOC_MESSAGE(1), &spi_tr) < 0 )
pabort(“can’t open device”);

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



Dear Iroquois,
I am also using Beagleboad Rev C5 running on ubuntu kernel version 3.1.4-x6…I want to know how you enabled spi dev in expansion and did the spi test ?

Thanks in advance,