how to read from i2c device with 2 byte internal address register

This is a discussion on how to read from i2c device with 2 byte internal address register within the Networking/Device Communication forums, part of the General Programming Boards category; Hi all, I want to read data from my ADXL345 accelerometer. I have connect this I2C device to I2C-USB convertor ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    2

    how to read from i2c device with 2 byte internal address register

    Hi all,
    I want to read data from my ADXL345 accelerometer. I have connect this I2C device to I2C-USB convertor module and then connect them to my PC through a USB cable.

    I have write the following code to read but it always return 255.
    Code:
    byte[] result = new byte[4];
    mySerialPort.Write(new byte[] { 0x56, 0x53, 0x33,0x32,2 }, 0, 5);
    mySerialPort.Read(result, 0, 2);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,847
    Returns 255 where?

    ADXL345 | 3-Axis, 2 g/4 g/8 g/16 g Digital Accelerometer | MEMS Inertial Sensors | MEMS and Sensors | Analog Devices
    According to this, it returns THREE 16-bit numbers per sample, you allocate space for TWO 16-bit numbers and read only ONE 16-bit number.

    > mySerialPort.Read(result, 0, 2);
    I'm guessing this also returns a status (success, fail, number of bytes read).
    Perhaps you should pay attention to this as well, rather than just assuming it works.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    2
    Hi Salem and thanks for your immediate reply,I am too beginner in programming for this kind of devices.I have read the documentation of it but i could not found that how does it work. Please describe for me the steps of reading from this I2C device through an I2C-USB module?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,847
    Please read the whole bunch of tutorials, examples, and program samples which are available on the manufacturer website for your controller board.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. address of register variable
    By siperi in forum C Programming
    Replies: 15
    Last Post: 11-08-2010, 02:26 PM
  2. Device Register Access
    By jacob12 in forum C Programming
    Replies: 35
    Last Post: 10-14-2008, 11:51 AM
  3. Internal IP address program
    By John87412897 in forum Networking/Device Communication
    Replies: 4
    Last Post: 08-19-2008, 05:57 AM
  4. moving byte pointed to by contents of a register into another register. dos debug.
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-18-2003, 06:48 PM
  5. write() function - no such device or address
    By threahdead in forum Linux Programming
    Replies: 3
    Last Post: 03-30-2003, 05:05 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21