Skip to content
Snippets Groups Projects
Commit d7d0eb5d authored by Andrea Milluzzo's avatar Andrea Milluzzo
Browse files

test-lsm9ds1 compiles

parent 83df466e
No related branches found
No related tags found
No related merge requests found
...@@ -491,3 +491,11 @@ BinName: test-l3gd20 ...@@ -491,3 +491,11 @@ BinName: test-l3gd20
Include: %shared %spi Include: %shared %spi
Defines: Defines:
Main: drivers/test-l3gd20 Main: drivers/test-l3gd20
[test-lsm9ds1]
Type: test
BoardId: stm32f429zi_stm32f4discovery
BinName: test-lsm9ds1
Include: %shared %spi
Defines:
Main: drivers/test-lsm9ds1
\ No newline at end of file
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <miosix.h> #include <miosix.h>
#include "drivers/spi/SPIDriver.h" #include "drivers/spi/SPIDriver.h"
#include "Sensor.h" #include "../Sensor.h"
using miosix::GpioPin; using miosix::GpioPin;
...@@ -158,9 +158,9 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen ...@@ -158,9 +158,9 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen
//FIFO setup: FIFO enabled in continous mode, decimation OFF, temperature on FIFO ON. //FIFO setup: FIFO enabled in continous mode, decimation OFF, temperature on FIFO ON.
if(fifo_enabled) if(fifo_enabled)
{ {
spi.write(regMapXLG::FIFO_CTRL, FIFO_CTRL_VAL | fifo_watermark); //FIFO continous mode + fifo watermark threshold setup spi.write(regMapXLG::FIFO_CTRL, (FIFO_CTRL_VAL|fifo_watermark)); //FIFO continous mode + fifo watermark threshold setup
spi.write(regMapXLG::INT1_CTRL, INT1_CTRL_VAL); //interrupt on FIFO treshold spi.write(regMapXLG::INT1_CTRL, INT1_CTRL_VAL); //interrupt on FIFO treshold
spi.write(regMapXLG::CTRL_REG9, CTRL_REG9_VAL | 0x02); //DRDY_mask_bit ON, I2C OFF, FIFO ON spi.write(regMapXLG::CTRL_REG9, (CTRL_REG9_VAL|0x02)); //DRDY_mask_bit ON, I2C OFF, FIFO ON
} }
else else
spi.write(regMapXLG::CTRL_REG9, CTRL_REG9_VAL); //DRDY_mask_bit ON, I2C OFF, FIFO OFF spi.write(regMapXLG::CTRL_REG9, CTRL_REG9_VAL); //DRDY_mask_bit ON, I2C OFF, FIFO OFF
...@@ -182,7 +182,7 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen ...@@ -182,7 +182,7 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen
if(spi.read(regMapXLG::CTRL_REG8)!=CTRL_REG8_VAL) return false; if(spi.read(regMapXLG::CTRL_REG8)!=CTRL_REG8_VAL) return false;
if(fifo_enabled) if(fifo_enabled)
{ {
if(spi.read(regMapXLG::FIFO_CTRL) != FIFO_CTRL_VAL | fifo_watermark) return false; if(spi.read(regMapXLG::FIFO_CTRL) != (FIFO_CTRL_VAL|fifo_watermark)) return false;
if(spi.read(regMapXLG::INT1_CTRL) != INT1_CTRL_VAL) return false; if(spi.read(regMapXLG::INT1_CTRL) != INT1_CTRL_VAL) return false;
if(spi.read(regMapXLG::CTRL_REG9) != (CTRL_REG9_VAL| 0x02)) return false; if(spi.read(regMapXLG::CTRL_REG9) != (CTRL_REG9_VAL| 0x02)) return false;
} }
...@@ -269,6 +269,7 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen ...@@ -269,6 +269,7 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen
int16_t temp = tempData[0] | tempData[1] << 8; int16_t temp = tempData[0] | tempData[1] << 8;
mLastTemp = tempZero + temp / tempSensistivity; //25°C + TEMP/S devo castare a float "temp"? mLastTemp = tempZero + temp / tempSensistivity; //25°C + TEMP/S devo castare a float "temp"?
return true;
} }
private: private:
......
/**
* test LSM9DS1 axel + gyro
* Copyright (c) 2020 Skyward Experimental Rocketry
* Authors: Andrea Milluzzo
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "drivers/spi/SPIDriver.h"
#include "sensors/LSM9DS1/LSM9DS1_AxelGyro.h"
using namespace miosix;
typedef Gpio<GPIOA_BASE, 5> GpioSck; //questi sono i pin SPI per f407_discovery
typedef Gpio<GPIOA_BASE, 6> GpioMiso;
typedef Gpio<GPIOA_BASE, 7> GpioMosi;
static const bool FIFO_ENABLED = false;
Vec3 adata, gdata;
//SPI
SPIBus bus(SPI1);
SPIBusConfig cfg;
GpioPin cs(GPIOE_BASE, 7);
int main(){
cfg.br = SPIBaudRate::DIV_64; //max 10MHz
{
FastInterruptDisableLock dLock;
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; //SPI1 ENABLE
GpioSck::mode(Mode::ALTERNATE);
GpioMiso::mode(Mode::ALTERNATE);
GpioMosi::mode(Mode::ALTERNATE);
cs.mode(Mode::OUTPUT);
GpioSck::alternateFunction(5);
GpioMiso::alternateFunction(5);
GpioMosi::alternateFunction(5);
}
cs.high();
LSM9DS1_XLG lsm9ds1(
bus,
cs,
LSM9DS1_XLG::AxelFSR::FS_8,
LSM9DS1_XLG::GyroFSR::FS_245,
LSM9DS1_XLG::ODR::ODR_952
);
while(!lsm9ds1.init()){}
Thread::sleep(500);
long long first_tick = miosix::getTick();
for(;;)
{
long long tick = miosix::getTick();
lsm9ds1.onSimpleUpdate();
adata = *(lsm9ds1.accelDataPtr());
gdata = *(lsm9ds1.gyroDataPtr());
printf("TIMESTAMP:%.3f\taxel:%.3f,%.3f,%.3f\tgyro:%.3f,%.3f,%.3f",
tick-first_tick,
adata.getX(), adata.getY(), adata.getZ(),
gdata.getX(), gdata.getY(), gdata.getZ());
Thread::sleep(500);
}
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment