1

A colleague of mine gave me a device that is able to send data via I2C. He has already been able to receive this data on the Arduino via the following library/Function https://www.arduino.cc/en/Reference/WireRequestFrom

However if i try to read out the bus on the raspberry pi (raspbian), I'm only able to receive the first 5 values when using "i2cdump" or "i2cget". Afterwards there is a delay about 1 second when executing "i2cget" and I receive a "Error: Read failed".

enter image description here

Does anybody have experience with I2C Read Errors or have a clue about what the cause could be?

About the Setup: Raspbian Jessy, I2C switched on via the raspi-config menu. No further Changes.

6
  • Does the device support that method of reading? What does the datasheet say?
    – joan
    Commented Apr 30, 2016 at 12:33
  • Its custom made - so there is no data sheet. The only thing i know is that it works with the arduino library (It is a At-tiny 85 with the library arduino.cc/en/reference/wire)
    – hypnomaki
    Commented Apr 30, 2016 at 12:37
  • I don't see how anyone can help then. If you don't know how to properly read the device it's all guess work. I suggest you port the Arduino code and use that as a basis.
    – joan
    Commented Apr 30, 2016 at 12:38
  • so i2c != i2c then? I was told that this should work flawlessly since its "all the same". Which kind of data/specs would you like me to search for? Why should porting the Code work when using the Raspbi OnBoard Tools for testing/debugging the I2C bus don't even work?
    – hypnomaki
    Commented Apr 30, 2016 at 12:49
  • Well does it work flawlessly? I suggest you read up on I2C and look at a few datasheets for I2C devices. I don't know of an I2C device which doesn't have a datasheet to explain its usage.
    – joan
    Commented Apr 30, 2016 at 12:57

2 Answers 2

1

Here's a small C program which reads the temperature register from a DS7505 I²C slave. Tweak it for your chip.

$ gcc -std=c99   -c -o ds7505-readtemp.o ds7505-readtemp.c
$ gcc -o ds7505-readtemp ds7505-readtemp.o
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <inttypes.h>
#include <linux/i2c-dev.h>

int main(int argc, char* argv[]) {
    struct i2c_msg i2c_msgs[2];
    struct i2c_rdwr_ioctl_data i2c_transfer;
    unsigned int address;
    uint8_t rdata[2];
    int fd;

    /* Parse arguments. */
    if (argc != 3) {
        fprintf(stderr, "USAGE: ds7505-readtemp <i2c-dev> <i2c slave address>\n");
        return 127;
    }   
    sscanf(argv[2], "0x%x", &address);
    if (address < 0x08 || address > 0x77) {
        fprintf(stderr, "ds7505-readtemp: i2c slave address has to be in the range 0x08..0x77.\n");
        return 127;
    }

    /* Open I2C device. */
    fd = open(argv[1], O_RDWR);
    if (fd < 0) {
        perror("ds7505-readtemp: i2c device open");
        return 2;
    }

    /* Select register to read. */
    i2c_msgs[0].addr   = address;
    i2c_msgs[0].flags  = 0;
    i2c_msgs[0].len    = 1;
    i2c_msgs[0].buf    = "\x00";

    i2c_msgs[1].addr   = address;
    i2c_msgs[1].flags  = I2C_M_RD;
    i2c_msgs[1].len    = 2;
    i2c_msgs[1].buf    = (char*)&rdata;

    i2c_transfer.msgs  = i2c_msgs;
    i2c_transfer.nmsgs = 2;

    if (ioctl(fd, I2C_RDWR, &i2c_transfer) < 0) {
        perror("ds7505-readtemp: i2c temperature read");
        return 2;
    };

    /* Print result. */
    printf("%.4f\n", ((float)((int16_t) (rdata[0] << 8 | rdata[1]))) / 256);

    /* Finish. */
    close(fd);
    return 0;
}
0

so i2c != i2c then?

No, i2c == i2c in very much the same sense that USB == USB.

However, unlike USB, I2C devices are seldom if ever "plug and play" which is what you seem to be expecting.

I was told that this should work flawlessly since its "all the same".

Without knowing the context of that statement it is hard to say whether you were accidentally misled, but either you or the person who told you this is confused.

There is always the chance that it might work out that way, but there is no particular reason to believe that it "will flawlessly".

recieve this data on the Arduino via the following library/Function

i2cdump is essentially a diagnostic/debugging/reverse engineering tool.

If you were using an equivalent "usbdump" program, you could use that to get information about a USB mouse that is attached. However, you could not use it to actually make the mouse work as a mouse, at least not without piping it through something else.

Its custom made - so there is no data sheet.

It does not seem to me that the At-tiny 85 is "custom made" unless you mean by Atmel, the manufacturer (coincidentally, also of the AVR that is the heart of the Arduino...), and yes there is a datasheet.

If you want to read data from this you will have to write code to do so or find some that has been written already.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.