GlobLib
HAL and API libraries for MCUs and hardware.
lsm9ds1.h
Go to the documentation of this file.
1 
56 #ifndef LSM9DS1_H_
57 #define LSM9DS1_H_
58 #include <stdio.h>
59 
60 #define LSM9DS1_DEFAULT_MAG_SCALE LSM9DS1_MAG_8
61 #define LSM9DS1_DEFAULT_GYR_SCALE LSM9DS1_GYR_500
62 #define LSM9DS1_DEFAULT_ACC_SCALE LSM9DS1_ACC_4
63 #define LSM9DS1_DATA_RANGE 32767.0f
64 #define LSM9DS1_GX 0
65 #define LSM9DS1_M 1
66 
67 //Accel/Gyro Registers
68 #define LSM9DS1_ACT_THS 0x04
69 #define LSM9DS1_ACT_DUR 0x05
70 #define LSM9DS1_INT_GEN_CFG_XL 0x06
71 #define LSM9DS1_INT_GEN_THS_X_XL 0x07
72 #define LSM9DS1_INT_GEN_THS_Y_XL 0x08
73 #define LSM9DS1_INT_GEN_THS_Z_XL 0x09
74 #define LSM9DS1_INT_GEN_DUR_XL 0x0A
75 #define LSM9DS1_REFERENCE_G 0x0B
76 #define LSM9DS1_INT1_CTRL 0x0C
77 #define LSM9DS1_INT2_CTRL 0x0D
78 #define LSM9DS1_WHO_AM_I_XG 0x0F
79 #define LSM9DS1_CTRL_REG1_G 0x10
80 #define LSM9DS1_CTRL_REG2_G 0x11
81 #define LSM9DS1_CTRL_REG3_G 0x12
82 #define LSM9DS1_ORIENT_CFG_G 0x13
83 #define LSM9DS1_INT_GEN_SRC_G 0x14
84 #define LSM9DS1_OUT_TEMP_L 0x15
85 #define LSM9DS1_OUT_TEMP_H 0x16
86 #define LSM9DS1_STATUS_REG_0 0x17
87 #define LSM9DS1_OUT_X_L_G 0x18
88 #define LSM9DS1_OUT_X_H_G 0x19
89 #define LSM9DS1_OUT_Y_L_G 0x1A
90 #define LSM9DS1_OUT_Y_H_G 0x1B
91 #define LSM9DS1_OUT_Z_L_G 0x1C
92 #define LSM9DS1_OUT_Z_H_G 0x1D
93 #define LSM9DS1_CTRL_REG4 0x1E
94 #define LSM9DS1_CTRL_REG5_XL 0x1F
95 #define LSM9DS1_CTRL_REG6_XL 0x20
96 #define LSM9DS1_CTRL_REG7_XL 0x21
97 #define LSM9DS1_CTRL_REG8 0x22
98 #define LSM9DS1_CTRL_REG9 0x23
99 #define LSM9DS1_CTRL_REG10 0x24
100 #define LSM9DS1_INT_GEN_SRC_XL 0x26
101 #define LSM9DS1_STATUS_REG_1 0x27
102 #define LSM9DS1_OUT_X_L_XL 0x28
103 #define LSM9DS1_OUT_X_H_XL 0x29
104 #define LSM9DS1_OUT_Y_L_XL 0x2A
105 #define LSM9DS1_OUT_Y_H_XL 0x2B
106 #define LSM9DS1_OUT_Z_L_XL 0x2C
107 #define LSM9DS1_OUT_Z_H_XL 0x2D
108 #define LSM9DS1_FIFO_CTRL 0x2E
109 #define LSM9DS1_FIFO_SRC 0x2F
110 #define LSM9DS1_INT_GEN_CFG_G 0x30
111 #define LSM9DS1_INT_GEN_THS_XH_G 0x31
112 #define LSM9DS1_INT_GEN_THS_XL_G 0x32
113 #define LSM9DS1_INT_GEN_THS_YH_G 0x33
114 #define LSM9DS1_INT_GEN_THS_YL_G 0x34
115 #define LSM9DS1_INT_GEN_THS_ZH_G 0x35
116 #define LSM9DS1_INT_GEN_THS_ZL_G 0x36
117 #define LSM9DS1_INT_GEN_DUR_G 0x37
118 
119 //Magneto Registers
120 #define LSM9DS1_OFFSET_X_REG_L_M 0x05
121 #define LSM9DS1_OFFSET_X_REG_H_M 0x06
122 #define LSM9DS1_OFFSET_Y_REG_L_M 0x07
123 #define LSM9DS1_OFFSET_Y_REG_H_M 0x08
124 #define LSM9DS1_OFFSET_Z_REG_L_M 0x09
125 #define LSM9DS1_OFFSET_Z_REG_H_M 0x0A
126 #define LSM9DS1_WHO_AM_I_M 0x0F
127 #define LSM9DS1_CTRL_REG1_M 0x20
128 #define LSM9DS1_CTRL_REG2_M 0x21
129 #define LSM9DS1_CTRL_REG3_M 0x22
130 #define LSM9DS1_CTRL_REG4_M 0x23
131 #define LSM9DS1_CTRL_REG5_M 0x24
132 #define LSM9DS1_STATUS_REG_M 0x27
133 #define LSM9DS1_OUT_X_L_M 0x28
134 #define LSM9DS1_OUT_X_H_M 0x29
135 #define LSM9DS1_OUT_Y_L_M 0x2A
136 #define LSM9DS1_OUT_Y_H_M 0x2B
137 #define LSM9DS1_OUT_Z_L_M 0x2C
138 #define LSM9DS1_OUT_Z_H_M 0x2D
139 #define LSM9DS1_INT_CFG_M 0x30
140 #define LSM9DS1_INT_SRC_M 0x31
141 #define LSM9DS1_INT_THS_L_M 0x32
142 #define LSM9DS1_INT_THS_H_M 0x33
143 
150 typedef struct{
151 
152  uint8_t port;
153  uint32_t gx_pin;
154  uint16_t gx_port;
155  uint32_t m_pin;
156  uint16_t m_port;
157  uint8_t cs_pol;
158 }LSM9DS1;
159 
163 typedef enum{
164 
169 
171 
175 typedef enum{
176 
181 
183 
187 typedef enum{
188 
192 
194 
206 void LSM9DS1_setup(LSM9DS1 *target, uint8_t spiPort,uint16_t gx_port,
207  uint32_t gx_pin, uint16_t m_port, uint32_t m_pin, uint8_t cs_pol);
216 uint8_t LSM9DS1_magReady(LSM9DS1 *target);
225 void LSM9DS1_getMag(LSM9DS1 *target,int16_t *data);
234 uint8_t LSM9DS1_gyrReady(LSM9DS1 *target);
243 void LSM9DS1_getGyr(LSM9DS1 *target,int16_t *data);
252 uint8_t LSM9DS1_accReady(LSM9DS1 *target);
261 void LSM9DS1_getAcc(LSM9DS1 *target,int16_t *data);
270 uint8_t LSM9DS1_tempReady(LSM9DS1 *target);
278 float LSM9DS1_getTemp(LSM9DS1 *target);
285 uint8_t LSM9DS1_gxWAI(LSM9DS1 *target);
292 uint8_t LSM9DS1_mWAI(LSM9DS1 *target);
298 void LSM9DS1_setMagScale(LSM9DS1 *target, lsm9ds1_magScale scale);
304 void LSM9DS1_setAccScale(LSM9DS1 *target, lsm9ds1_accScale scale);
310 void LSM9DS1_setGyrScale(LSM9DS1 *target, lsm9ds1_gyrScale scale);
316 uint8_t LSM9DS1_getMagScale(LSM9DS1 *target);
322 uint8_t LSM9DS1_getAccScale(LSM9DS1 *target);
328 uint16_t LSM9DS1_getGyrScale(LSM9DS1 *target);
336 void LSM9DS1_writeByte(LSM9DS1 *target, uint8_t component, uint8_t address, uint8_t data);
345 uint16_t LSM9DS1_readByte(LSM9DS1 *target, uint8_t component,uint8_t address);
346 
349 #endif
350 
uint16_t LSM9DS1_getGyrScale(LSM9DS1 *target)
Get the scale of the gyroscope.
Definition: lsm9ds1.c:304
void LSM9DS1_getMag(LSM9DS1 *target, int16_t *data)
Get the latest magnometer readings.
Definition: lsm9ds1.c:342
void LSM9DS1_setAccScale(LSM9DS1 *target, lsm9ds1_accScale scale)
Set the scale of the accelerometer.
Definition: lsm9ds1.c:153
uint32_t m_pin
The pin used for mag SPI chip select.
Definition: lsm9ds1.h:155
lsm9ds1_gyrScale
Available gyroscope ranges.
Definition: lsm9ds1.h:187
uint16_t LSM9DS1_readByte(LSM9DS1 *target, uint8_t component, uint8_t address)
Read a single byte from the device&#39;s register.
Definition: lsm9ds1.c:446
void LSM9DS1_writeByte(LSM9DS1 *target, uint8_t component, uint8_t address, uint8_t data)
Write a single byte to the device&#39;s register.
Definition: lsm9ds1.c:432
float LSM9DS1_getTemp(LSM9DS1 *target)
Get the latest accelerometer readings.
Definition: lsm9ds1.c:408
uint8_t LSM9DS1_gxWAI(LSM9DS1 *target)
Read the value for the gyro/accel who am I register.
Definition: lsm9ds1.c:420
+-2000 degrees / second range
Definition: lsm9ds1.h:191
uint16_t m_port
The port used for mag SPI chip select.
Definition: lsm9ds1.h:156
uint8_t port
The port the device is connected to.
Definition: lsm9ds1.h:152
Data structure containing variables specific to individual slave devices.
Definition: lsm9ds1.h:150
lsm9ds1_accScale
Available accelerometer ranges.
Definition: lsm9ds1.h:175
+-2G range
Definition: lsm9ds1.h:177
uint8_t LSM9DS1_getMagScale(LSM9DS1 *target)
Get the scale of the magnetometer.
Definition: lsm9ds1.c:235
uint8_t LSM9DS1_tempReady(LSM9DS1 *target)
Check if the temperature module has new data available.
Definition: lsm9ds1.c:399
lsm9ds1_magScale
Available magnetometer ranges.
Definition: lsm9ds1.h:163
+-4G range
Definition: lsm9ds1.h:178
uint8_t LSM9DS1_mWAI(LSM9DS1 *target)
Read the value for the magnetometer who am I register.
Definition: lsm9ds1.c:426
+-16 Gauss range
Definition: lsm9ds1.h:168
uint8_t LSM9DS1_gyrReady(LSM9DS1 *target)
Check if the gyroscope has new data available.
Definition: lsm9ds1.c:355
void LSM9DS1_setGyrScale(LSM9DS1 *target, lsm9ds1_gyrScale scale)
Set the scale of the gyroscope.
Definition: lsm9ds1.c:198
+-8 Gauss range
Definition: lsm9ds1.h:166
+-16G range
Definition: lsm9ds1.h:180
+-500 degrees / second range
Definition: lsm9ds1.h:190
uint8_t cs_pol
The polary of the SPI chip select line.
Definition: lsm9ds1.h:157
uint8_t LSM9DS1_getAccScale(LSM9DS1 *target)
Get the scale of the accelerometer.
Definition: lsm9ds1.c:270
+-245 degrees / second range
Definition: lsm9ds1.h:189
void LSM9DS1_setup(LSM9DS1 *target, uint8_t spiPort, uint16_t gx_port, uint32_t gx_pin, uint16_t m_port, uint32_t m_pin, uint8_t cs_pol)
Initalizes the slave device and populates data structure variable.
Definition: lsm9ds1.c:32
void LSM9DS1_getAcc(LSM9DS1 *target, int16_t *data)
Get the latest accelerometer readings.
Definition: lsm9ds1.c:386
uint16_t gx_port
The port used for gyro/accel SPI chip select.
Definition: lsm9ds1.h:154
void LSM9DS1_getGyr(LSM9DS1 *target, int16_t *data)
Get the latest gyroscope readings.
Definition: lsm9ds1.c:364
+-12 Gauss range
Definition: lsm9ds1.h:167
uint8_t LSM9DS1_accReady(LSM9DS1 *target)
Check if the accelerometer has new data available.
Definition: lsm9ds1.c:377
uint32_t gx_pin
The pin used for gyro/accel SPI chip select.
Definition: lsm9ds1.h:153
+-4 Gauss range
Definition: lsm9ds1.h:165
uint8_t LSM9DS1_magReady(LSM9DS1 *target)
Check if the magnetometer has new data available.
Definition: lsm9ds1.c:333
+-8G range
Definition: lsm9ds1.h:179
void LSM9DS1_setMagScale(LSM9DS1 *target, lsm9ds1_magScale scale)
Set the scale of the magnetometer.
Definition: lsm9ds1.c:106