Self test boot program for testing icarus sensors
Dependencies: BLE_API mbed nRF51822
Fork of BLE_UARTConsole by
MPU9250Sensor.cpp
- Committer:
- smigielski
- Date:
- 2015-04-05
- Revision:
- 13:ef0ce8fa871f
- Parent:
- 11:70359785c2a7
- Child:
- 14:cb369746225d
File content as of revision 13:ef0ce8fa871f:
#include "MPU9250Sensor.h" #include "mbed.h" #ifndef LOG #define LOG(...) do printf(__VA_ARGS__); while (0) #endif MPU9250Sensor::MPU9250Sensor(SPI& spi_,DigitalOut& cs_,void (*debug_)(const char* format, ...)) : BaseSensor(debug_), spi(spi_), cs(cs_) { cs = UP; //To prevent switching into I2C mode when using SPI, the I2C interface should be disabled by setting the I2C_IF_DIS //configuration bit. Setting this bit should be performed immediately after waiting for the time specified by the //“Start-Up Time for Register Read/Write” in Section 6.3. } char* MPU9250Sensor::getSimpleName() { return "MPU9250"; } uint32_t MPU9250Sensor::verifyIntegrity(uint32_t* errorResult) { LOG("Start verfication of MPU9250 Sensor"); uint32_t errors = 0; //who am I register value is 0x71 uint8_t sensorId = readRegister(MPU9250_WHOAMI); if (sensorId !=0x71){ errorResult[errors++] = ERROR_WRONG_DEVICE_ID; LOG("Wrong sensorId: %X",sensorId); } //check status registry uint8_t status = readRegister(MPU9250_I2C_MST_STATUS); //indicate that SEU error was detetcted if (status & (1 << 7)){ errorResult[errors++] = ERROR_SEU_ERROR_DETECT; LOG("SEU error detected: %X",status); } //check that chip is in awaken state if (!(status & (1 << 6))){ errorResult[errors++] = ERROR_DEVICE_SLEEPING; LOG("Chip not awaken: %X",status); } //perform self test errors+=selfTest(&errorResult[errors]); return errors; } uint32_t MPU9250Sensor::selfTest(uint32_t* errorResult){ uint32_t errors = 0; return errors; } void MPU9250Sensor::getSensorDetails(sensor_t* sensorDetails) { } uint8_t MPU9250Sensor::readRegister( uint8_t reg){ cs = DOWN; spi.write(reg| MPU9250_READ_FLAG); uint8_t val = spi.write(0x00); cs = UP; return val; } // //void MPU9250Sensor::writeRegister( uint8_t reg, uint8_t cmd ){ // cs->write(DOWN); // spi->write(reg); // spi->write(cmd); // cs->write(UP); //}