diff --git a/Development/Software/Controller API/LSM9DS0.cpp b/Development/Software/Controller API/LSM9DS0.cpp index 3c74b141502a38e74387d71e28c0f4007a294278..08610ebfbe3ce091137fa29ce5c40c9babe8ba8c 100644 --- a/Development/Software/Controller API/LSM9DS0.cpp +++ b/Development/Software/Controller API/LSM9DS0.cpp @@ -15,8 +15,8 @@ LSM9DS0::LSM9DS0() { mraa_init(); // set the SPI channels - SPI_1 = mraa_spi_init(1); - SPI_2 = mraa_spi_init(0); + SPI_1 = mraa_spi_init(0); + SPI_2 = mraa_spi_init(1); // set the frequency ( 10Mhz ) mraa_spi_frequency(SPI_1, 10000000); @@ -111,7 +111,7 @@ void LSM9DS0::write_G(uint8_t address, uint8_t data) { * Input : Address to read from * Returns : Results from chip */ -uint8_t read_XM(uint8_t address) { +uint8_t LSM9DS0::read_XM(uint8_t address) { // lets set the first two bits to 0 address = address & 0x3F; @@ -137,7 +137,7 @@ uint8_t read_XM(uint8_t address) { * * Input : Address to write to, data to write */ -void write_XM(uint8_t address, uint8_t data) { +void LSM9DS0::write_XM(uint8_t address, uint8_t data) { // lets set the first two bits to 0 address = address & 0x3F; @@ -175,6 +175,10 @@ uint8_t LSM9DS0::read(mraa_spi_context SPI, uint8_t address) { send_data = send_data | 0x8000; send_data = send_data & 0xBFFF; + // spi_write_word causes us to need to swap the top and bottom bytes + send_data = ( send_data >> 8 ) & 0x00FF; + send_data = send_data | ( ( send_data << 8 ) & 0xFF00 ); + // send the data down the channel and get the result uint8_t result = mraa_spi_write_word(SPI, send_data); @@ -198,6 +202,10 @@ void LSM9DS0::write(mraa_spi_context SPI, uint8_t address, uint8_t data) { // add the data to be sent send_data = send_data | data; + // spi_write_word causes us to need to swap the top and bottom bytes + send_data = ( send_data >> 8 ) & 0x00FF; + send_data = send_data | ( ( send_data << 8 ) & 0xFF00 ); + // send the data down the channel mraa_spi_write_word(SPI, send_data); }