Hi Richard,

Here is a code snippet that works for us:

int main(int argc, char *argv[]) {
int file;
int adapter_nr = 0; // was 3 for ARM
char filename[20];

int i2c_addr = 0x1E;
char buf[64];
char write_buf[2];
unsigned short x;
long m[3];

sprintf(filename, "/dev/i2c-%d", adapter_nr);
if ((file = open(filename, O_RDWR)) < 0) {
printf("ERRNO: %s\n", strerror(errno));
exit(1);
} else {
printf("%s\n",filename);
}

if (ioctl(file, I2C_SLAVE, i2c_addr) < 0) {
printf("ERRNO: %s\n", strerror(errno));
exit(1);
}

        // Write 0x18 to register 0x00
        write_buf[0] = 0;
write_buf[1] = 0x18; // 0001 1000
if (write(file, write_buf, 2) != 2) {
printf("I2C Send %x Failed\n", i2c_addr);
}// set pointer to Config Reg A
if (write(file, write_buf, 1) != 1) {
printf("I2C Send %x Failed\n", i2c_addr);
}// set pointer to Config Reg A
if (read(file, buf, 1) != 1) {
printf("I2C Read %x Failed\n", i2c_addr);
}
cout << "Configuration Register A: " << short(buf[0]) << 

        // Read a from register 0x03
        write_buf[0] = 3; //write the register pointer to 3
if (write(file, write_buf, 1) != 1) {
printf("I2C Send %x Failed\n", i2c_addr);
}
        if (read(file, buf, 1) != 1) {
printf("I2C Read %x Failed\n", i2c_addr);
} // read MSB

.....
}


Best,

Tyler

On Thu, Jun 24, 2010 at 7:58 AM, Richman1234 <richard.manley@navy.mil> wrote:

I've run into a problem trying to get my i2c communications up and running.
I am using the Gumstix overo fire with the tobi board.
below is the code I am using.
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>

int main (int argc, char **argv)
{
int device;
uint8_t data[1];

device = open("/dev/i2c-3", O_RDWR);
if (device < 0)
{
       perror("open");
       exit(1);
}

if (ioctl(device, I2C_SLAVE, 0x02) < 0)
{
       perror("ioctl (I2C_Slave)");
       goto DONE;
}

data[0] = 0x01;
if (write(device, &data, 1) != 1)
{
       perror("write!!!");
       goto DONE;
}

DONE:
close(device);
return 0;
}


When I run this on the Gumstix I get the error "Write!!! Input/output error"
I put a scope on the i2c-3 pins on the tobi and i can see the address of
0x02 being sent, but nothing for the data.

Any ideas?

Thanks


--
View this message in context: http://old.nabble.com/i2c-writing-errors-tp28983364p28983364.html
Sent from the Gumstix mailing list archive at Nabble.com.


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
gumstix-users mailing list
gumstix-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gumstix-users



--
Tyler Gore
617-505-4865(work)
503-860-0743 (cell)
--
This email message, including any attachments, is intended solely for
the use of the designated recipient(s) and may contain confidential,
privileged, and or proprietary information. Any unauthorized review,
use, disclosure or distribution is strictly prohibited.