Today I worked on the I2C interface to the IR sensors. I started by soldering some pin headers on our new level translators that came in from Sparkfun.


I found a tutorial online that explains I2C on the BeagleBoard. You can find it here. Using what I found there, I located the correct pins on the expansion header to communicate with I2C. I then connected my logic analyzer to those pins and ran a few test commands to make sure I had the correct pins.

After I had the correct pins, I made some wires to connect a translator to the BeagleBoard I2C lines. On the low side of the translator I have a 1.8V rail from the BeagleBoard and on the high side I have a 5V supply. I can read the I2c with my Logic on both sides of the translator, so it is working as intended.

I figured out the power supply connections and jumper configurations for the ADC board and hooked it up on the 5V side of the I2C bus. I used both the ADC Eval Board and the ADC ADS7828 datasheets to find this information. The command I used on the BeagleBoard to check if the ADC was reachable was:
$i2cdetect -r 2
Which showed me that the ADC board was visible at 0x4b on the i2c2 bus from the BeagleBoard.

I then used code pieced together from the tutorial I found to communicate with the I2C bus to talk with my ADC and get data from it. Here is the code:
//#include
//#include These libraries are not really necessary
#include
#include
#include
#include
#include
#include #include
#include
#include
#include
int main(void) {
int file;
char filename[40];
const char *buffer;
int addr = 0x4b;//0b00101001; // The I2C address of the ADC
sprintf(filename,"/dev/i2c-2");
if ((file = open(filename,O_RDWR)) < 0) {
printf("Failed to open the bus.");
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
if (ioctl(file,I2C_SLAVE,addr) < 0) {
printf("Failed to acquire bus access and/or talk to slave.\n");
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
char buf[10] = {0};
float data;
char channel;
int i;
for(i = 0; i // Using I2C Read
if (read(file,buf,2) != 2) {
/* ERROR HANDLING: i2c transaction failed */
printf("Failed to read from the i2c bus.\n");
buffer = strerror(errno);
printf(buffer);
printf("\n\n");
} else {
data = (float)((buf[0] & 0b00001111)< data = data/4096*5;
channel = ((buf[0] & 0b00110000)>>4);
printf("Channel %02d Data: %04f\n",channel,data);
}
}
//unsigned char reg = 0x10; // Device register to access
//buf[0] = reg;
buf[0] = 0b10001000;
if (write(file,buf,1) != 1) {
/* ERROR HANDLING: i2c transaction failed */
printf("Failed to write to the i2c bus.\n");
buffer = strerror(errno);
printf(buffer);
printf("\n\n");
}
}
