LSM303DLH
Posted: Mon Feb 11, 2013 1:41 am
Hi guys,
I'm trying to interface (in C) with an LSM303DLH sensor with the I2C functions.
I need to use I2COUT to write to reg address 0x20 value 0x27 at i2c
address 0x30 (to start with) and I2CIN to read from the sensor. I've
been using an LSM303DLH library written in C++ using mbed.h as a
guide, but I just can't get my head around how the I2COUT and ITCIN
functions take the parameters. I'm new to C and ARM, I'm afraid.
Here's the section of code I'm talking about:
[From the library]
const int addr_acc = 0x30;
CTRL_REG1_A = 0x20, //in enum REG_ADDRS
...
char reg_v;
reg_v = 0;
reg_v |= 0x01 << 5; /* Normal mode */
reg_v |= 0x07; /* X/Y/Z axis enable on the accelerometer. */
write_reg(addr_acc,CTRL_REG1_A,reg_v);
reg_v = 0;
read_reg(addr_acc,CTRL_REG1_A,®_v); //not sure why it's read at this point
...
read_reg_short(addr_acc, OUT_X_A, &a_x); //just pulling the values back
read_reg_short(addr_acc, OUT_Y_A, &a_y);
read_reg_short(addr_acc, OUT_Z_A, &a_z);
[My code, cribbed from Csample.c]
shortMessage[0] = CTRL_REG1_A;
shortMessage[1] = reg_v;
present = I2COUT (SDA, SCL, addr_acc, 9, shortMessage); // address,
followed by data
...
I2CIN(SDA, SCL, addr_acc, -1, -1, -1, -1, -1, 8, shortResponse);
How do you write to, and then read specific registers using
I2COUT/I2CIN? I'm assuming it's some configuration of shortMessage
for I2COUT and the ints in I2CIN's parameters. I'm sorry, I really
don't want to waste people's time - I can see the documentation on I2C
on the support pages - but I just don't understand it.
Also, I've been reading through this group and it's pretty amazing to
see the level of support it's given. Kudos!
Alex
I'm trying to interface (in C) with an LSM303DLH sensor with the I2C functions.
I need to use I2COUT to write to reg address 0x20 value 0x27 at i2c
address 0x30 (to start with) and I2CIN to read from the sensor. I've
been using an LSM303DLH library written in C++ using mbed.h as a
guide, but I just can't get my head around how the I2COUT and ITCIN
functions take the parameters. I'm new to C and ARM, I'm afraid.
Here's the section of code I'm talking about:
[From the library]
const int addr_acc = 0x30;
CTRL_REG1_A = 0x20, //in enum REG_ADDRS
...
char reg_v;
reg_v = 0;
reg_v |= 0x01 << 5; /* Normal mode */
reg_v |= 0x07; /* X/Y/Z axis enable on the accelerometer. */
write_reg(addr_acc,CTRL_REG1_A,reg_v);
reg_v = 0;
read_reg(addr_acc,CTRL_REG1_A,®_v); //not sure why it's read at this point
...
read_reg_short(addr_acc, OUT_X_A, &a_x); //just pulling the values back
read_reg_short(addr_acc, OUT_Y_A, &a_y);
read_reg_short(addr_acc, OUT_Z_A, &a_z);
[My code, cribbed from Csample.c]
shortMessage[0] = CTRL_REG1_A;
shortMessage[1] = reg_v;
present = I2COUT (SDA, SCL, addr_acc, 9, shortMessage); // address,
followed by data
...
I2CIN(SDA, SCL, addr_acc, -1, -1, -1, -1, -1, 8, shortResponse);
How do you write to, and then read specific registers using
I2COUT/I2CIN? I'm assuming it's some configuration of shortMessage
for I2COUT and the ints in I2CIN's parameters. I'm sorry, I really
don't want to waste people's time - I can see the documentation on I2C
on the support pages - but I just don't understand it.
Also, I've been reading through this group and it's pretty amazing to
see the level of support it's given. Kudos!
Alex