Pin usage: MOSI(D4), MISO(D5), SCK(D3), CS(D6), format(8, 3) Test OK.
Fork of LSM6DS3 by
Diff: LSM6DS3.cpp
- Revision:
- 2:c19d384b2896
- Parent:
- 1:cc2caaf5536c
- Child:
- 3:d5307f077753
--- a/LSM6DS3.cpp Tue Feb 23 07:26:58 2016 +0000 +++ b/LSM6DS3.cpp Tue Feb 23 08:48:56 2016 +0000 @@ -54,7 +54,7 @@ //================================= //****************************************************************************// -LSM6DS3Core::LSM6DS3Core( uint8_t busType, uint8_t inputArg) : commInterface(SPI_MODE), I2CAddress(0x6B), chipSelectPin(PB_6), spi(D11,D12,D13), i2c(D14,D15), cs((PinName)chipSelectPin) +LSM6DS3Core::LSM6DS3Core( uint8_t busType, uint8_t inputArg) : commInterface(SPI_MODE), I2CAddress(0x6B), spi_(SPI_MOSI,SPI_MISO,SPI_SCK), i2c_(I2C_SDA,I2C_SCL), cs_(SPI_CS) { commInterface = busType; if( commInterface == I2C_MODE ) { @@ -82,9 +82,9 @@ //DigitalOut cs((PinName)chipSelectPin); // Maximum SPI frequency is 10MHz, could divide by 2 here: - spi.frequency(5000000); + spi_.frequency(5000000); // Data is read and written MSb first. - spi.format(8,0); + spi_.format(8,0); // Data is captured on rising edge of clock (CPHA = 0) // Base value of the clock is HIGH (CPOL = 1) @@ -103,7 +103,7 @@ //SPI.format(8,0);//8 bits mode0 // initalize the data ready and chip select pins: - cs = 1; + cs_ = 1; break; default: break; @@ -172,11 +172,11 @@ case SPI_MODE: // take the chip select low to select the device: - cs = 0; + cs_ = 0; // send the device the register you want to read: - spi.write(offset | 0x80); //Ored with "read request" bit + spi_.write(offset | 0x80); //Ored with "read request" bit while ( i < length ) { // slave may send less than requested - c = spi.write(0x00); // receive a byte as character + c = spi_.write(0x00); // receive a byte as character if( c == 0xFF ) { //May have problem tempFFCounter++; @@ -190,7 +190,7 @@ returnError = IMU_ALL_ONES_WARNING; } // take the chip select high to de-select: - cs = 1; //digitalWrite(chipSelectPin, HIGH); + cs_ = 1; //digitalWrite(chipSelectPin, HIGH); break; default: @@ -213,7 +213,7 @@ { //Return value uint8_t result; - uint8_t numBytes = 1; + //uint8_t numBytes = 1; status_t returnError = IMU_SUCCESS; switch (commInterface) { @@ -233,13 +233,13 @@ case SPI_MODE: // take the chip select low to select the device: - cs = 0; //digitalWrite(chipSelectPin, LOW); + cs_ = 0; //digitalWrite(chipSelectPin, LOW); // send the device the register you want to read: - spi.write(offset | 0x80); //Ored with "read request" bit + spi_.write(offset | 0x80); //Ored with "read request" bit // send a value of 0 to read the first byte returned: - result = spi.write(0x00); + result = spi_.write(0x00); // take the chip select high to de-select: - cs = 1; //digitalWrite(chipSelectPin, HIGH); + cs_ = 1; //digitalWrite(chipSelectPin, HIGH); if( result == 0xFF ) { //we've recieved all ones, report @@ -299,14 +299,14 @@ case SPI_MODE: // take the chip select low to select the device: - cs = 0; //digitalWrite(chipSelectPin, LOW); + cs_ = 0; //digitalWrite(chipSelectPin, LOW); // send the device the register you want to read: - spi.write(offset); + spi_.write(offset); // send a value of 0 to read the first byte returned: - spi.write(dataToWrite); + spi_.write(dataToWrite); // decrement the number of bytes left to read: // take the chip select high to de-select: - cs = 1;//digitalWrite(chipSelectPin, HIGH); + cs_ = 1;//digitalWrite(chipSelectPin, HIGH); break; //No way to check error on this write (Except to read back but that's not reliable)