xyControl
0.1
Quadrotor Flight Controller on AVR Basis
|
Configuring and reading an LSM303DLHC Magnetometer. More...
Files | |
file | mag.h |
LSM303DLHC Magnetometer API Header. | |
file | mag.c |
LSM303DLHC Magnetometer API Implementation. | |
Macros | |
#define | MAGREG_CRB 0x01 |
Magnetometer Gain Register. More... | |
#define | MAGREG_MR 0x02 |
Magnetometer Mode Register. More... | |
#define | MAGREG_XH 0x03 |
First Magnetometer Output Register. More... | |
Enumerations | |
enum | MagRange { r1g3 = 1, r1g9 = 2, r2g5 = 3, r4g0 = 4, r4g7 = 5, r5g6 = 6, r8g1 = 7 } |
Magnetometer Range options. More... | |
Functions | |
Error | magInit (MagRange r) |
Initialize the Magnetometer. More... | |
Error | magRead (Vector3f *v) |
Read from the Magnetometer. More... | |
Error | magWriteRegister (uint8_t reg, uint8_t val) |
Write a Magnetometer Register. More... | |
Variables | |
MagRange | magRange |
Stored range to scale returned values. More... | |
Configuring and reading an LSM303DLHC Magnetometer.
#define MAGREG_CRB 0x01 |
#define MAGREG_MR 0x02 |
#define MAGREG_XH 0x03 |
enum MagRange |
Initialize the Magnetometer.
Call before magRead(). I2C should already be initialized!
r | MagRange to use. |
Definition at line 77 of file mag.c.
References ARGUMENT_ERROR, magRange, MAGREG_CRB, MAGREG_MR, magWriteRegister(), and SUCCESS.
Read from the Magnetometer.
Magnetometer should already be initialized!
v | Vector3f for the read values |
Definition at line 90 of file mag.c.
References ARGUMENT_ERROR, MAG_ADDRESS, magRange, MAGREG_XH, r1g3, r1g9, r2g5, r4g0, r4g7, r5g6, r8g1, SUCCESS, TWI_NO_ANSWER, TWI_READ, TWI_WRITE, TWI_WRITE_ERROR, twiReadAck(), twiReadNak(), twiRepStart(), twiStart(), twiWrite(), Vector3f::x, Vector3f::y, and Vector3f::z.
Error magWriteRegister | ( | uint8_t | reg, |
uint8_t | val | ||
) |
Write a Magnetometer Register.
I2C should aready be initialized!
reg | Register Address |
val | New Value |
Definition at line 63 of file mag.c.
References MAG_ADDRESS, SUCCESS, TWI_NO_ANSWER, TWI_WRITE, TWI_WRITE_ERROR, twiStart(), twiStop(), and twiWrite().
Referenced by magInit().