21 extern uint16_t SPI_read(uint8_t,uint16_t,uint32_t,uint8_t,uint16_t);
22 extern void SPI_repeatRead(uint8_t,uint16_t,uint32_t,uint8_t,uint16_t,uint16_t*,uint16_t);
23 extern void SPI_write(uint8_t,uint16_t,uint32_t,uint8_t,uint16_t,uint16_t);
26 extern void delayms(uint32_t);
28 void lsm9ds1_magSetup(
LSM9DS1 *target);
29 void lsm9ds1_gyrSetup(
LSM9DS1 *target);
30 void lsm9ds1_accSetup(
LSM9DS1 *target);
33 uint32_t gx_pin,uint16_t m_port, uint32_t m_pin, uint8_t cs_pol){
38 target->
port = spiPort;
41 target->
m_pin = m_pin;
45 lsm9ds1_gyrSetup(target);
46 lsm9ds1_accSetup(target);
47 lsm9ds1_magSetup(target);
52 void lsm9ds1_accSetup(
LSM9DS1 *target){
63 void lsm9ds1_gyrSetup(
LSM9DS1 *target){
84 void lsm9ds1_magSetup(
LSM9DS1 *target){
109 regValue = SPI_read(target->
port,target->
m_port,
110 target->
m_pin,target->
cs_pol,LSM9DS1_CTRL_REG2_M | 0x80);
157 target->
gx_pin,target->
cs_pol,LSM9DS1_CTRL_REG6_XL | 0x80);
202 target->
gx_pin,target->
cs_pol,LSM9DS1_CTRL_REG1_G | 0x80);
238 regValue = SPI_read(target->
port,target->
m_port,
239 target->
m_pin,target->
cs_pol,LSM9DS1_CTRL_REG2_M | 0x80);
241 switch(regValue & 0x60){
274 target->
gx_pin,target->
cs_pol,LSM9DS1_CTRL_REG6_XL | 0x80);
276 switch(regValue & 0x18){
308 target->
gx_pin,target->
cs_pol,LSM9DS1_CTRL_REG1_G | 0x80);
310 switch(regValue & 0x18){
336 regValue = SPI_read(target->
port,target->
m_port,
337 target->
m_pin,target->
cs_pol,LSM9DS1_STATUS_REG_M | 0x80);
339 return (regValue & 0x08);
348 target->
m_pin,target->
cs_pol,LSM9DS1_OUT_X_L_M | 0xC0,newData,6);
350 data[0] = (newData[1] << 8) | newData[0];
351 data[1] = (newData[3] << 8) | newData[2];
352 data[2] = (newData[5] << 8) | newData[4];
359 target->
gx_pin,target->
cs_pol,LSM9DS1_STATUS_REG_0 | 0x80);
361 return (regValue & 0x02);
369 target->
gx_pin,target->
cs_pol,LSM9DS1_OUT_X_L_G | 0x80,newData,6);
371 data[0] = (newData[1] << 8) | newData[0];
372 data[1] = (newData[3] << 8) | newData[2];
373 data[2] = (newData[5] << 8) | newData[4];
381 target->
gx_pin,target->
cs_pol,LSM9DS1_STATUS_REG_0 | 0x80);
383 return (regValue & 0x01);
391 target->
gx_pin,target->
cs_pol,LSM9DS1_OUT_X_L_XL | 0x80,newData,6);
393 data[0] = (newData[1] << 8) | newData[0];
394 data[1] = (newData[3] << 8) | newData[2];
395 data[2] = (newData[5] << 8) | newData[4];
403 target->
gx_pin,target->
cs_pol,LSM9DS1_STATUS_REG_0 | 0x80);
405 return (regValue & 0x04);
413 target->
gx_pin,target->
cs_pol,LSM9DS1_OUT_TEMP_L | 0x80,newData,2);
416 return (((int16_t)((newData[1] << 8) | newData[0])/16.0f) + 25);
423 target->
gx_pin,target->
cs_pol,LSM9DS1_WHO_AM_I_M | 0x80);
429 target->
m_pin,target->
cs_pol,LSM9DS1_WHO_AM_I_XG | 0x80);
uint16_t LSM9DS1_getGyrScale(LSM9DS1 *target)
Get the scale of the gyroscope.
void LSM9DS1_getMag(LSM9DS1 *target, int16_t *data)
Get the latest magnometer readings.
void LSM9DS1_setAccScale(LSM9DS1 *target, lsm9ds1_accScale scale)
Set the scale of the accelerometer.
uint32_t m_pin
The pin used for mag SPI chip select.
lsm9ds1_gyrScale
Available gyroscope ranges.
uint16_t LSM9DS1_readByte(LSM9DS1 *target, uint8_t component, uint8_t address)
Read a single byte from the device's register.
void LSM9DS1_writeByte(LSM9DS1 *target, uint8_t component, uint8_t address, uint8_t data)
Write a single byte to the device's register.
float LSM9DS1_getTemp(LSM9DS1 *target)
Get the latest accelerometer readings.
uint8_t LSM9DS1_gxWAI(LSM9DS1 *target)
Read the value for the gyro/accel who am I register.
+-2000 degrees / second range
uint16_t m_port
The port used for mag SPI chip select.
uint8_t port
The port the device is connected to.
Data structure containing variables specific to individual slave devices.
lsm9ds1_accScale
Available accelerometer ranges.
uint8_t LSM9DS1_getMagScale(LSM9DS1 *target)
Get the scale of the magnetometer.
uint8_t LSM9DS1_tempReady(LSM9DS1 *target)
Check if the temperature module has new data available.
lsm9ds1_magScale
Available magnetometer ranges.
uint8_t LSM9DS1_mWAI(LSM9DS1 *target)
Read the value for the magnetometer who am I register.
uint8_t LSM9DS1_gyrReady(LSM9DS1 *target)
Check if the gyroscope has new data available.
void LSM9DS1_setGyrScale(LSM9DS1 *target, lsm9ds1_gyrScale scale)
Set the scale of the gyroscope.
+-500 degrees / second range
#define LSM9DS1_DEFAULT_GYR_SCALE
Default mag range set by LSM9DS1_setup()
uint8_t cs_pol
The polary of the SPI chip select line.
uint8_t LSM9DS1_getAccScale(LSM9DS1 *target)
Get the scale of the accelerometer.
+-245 degrees / second range
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.
#define LSM9DS1_DEFAULT_MAG_SCALE
Default mag range set by LSM9DS1_setup()
void LSM9DS1_getAcc(LSM9DS1 *target, int16_t *data)
Get the latest accelerometer readings.
uint16_t gx_port
The port used for gyro/accel SPI chip select.
void LSM9DS1_getGyr(LSM9DS1 *target, int16_t *data)
Get the latest gyroscope readings.
Header file for STMicroelectronics LSM9DS1 9DOF IMU.
#define LSM9DS1_DEFAULT_ACC_SCALE
Default mag range set by LSM9DS1_setup()
uint8_t LSM9DS1_accReady(LSM9DS1 *target)
Check if the accelerometer has new data available.
uint32_t gx_pin
The pin used for gyro/accel SPI chip select.
uint8_t LSM9DS1_magReady(LSM9DS1 *target)
Check if the magnetometer has new data available.
#define LSM9DS1_M
Used by read/write functions to select mag.
void LSM9DS1_setMagScale(LSM9DS1 *target, lsm9ds1_magScale scale)
Set the scale of the magnetometer.