Skip to content
Snippets Groups Projects
Commit 61105b5e authored by Carhugar1's avatar Carhugar1
Browse files

Fixed LSM9DS0.

Used to send the words in the order bottom byte then top byte. Fixes were made in the software to fix the issues.

Fixes:
 - write has top and bottom byte swapping
 - read has top and bottom byte swapping
parent 19ee20ef
Branches master
No related tags found
No related merge requests found
...@@ -15,8 +15,8 @@ LSM9DS0::LSM9DS0() { ...@@ -15,8 +15,8 @@ LSM9DS0::LSM9DS0() {
mraa_init(); mraa_init();
// set the SPI channels // set the SPI channels
SPI_1 = mraa_spi_init(1); SPI_1 = mraa_spi_init(0);
SPI_2 = mraa_spi_init(0); SPI_2 = mraa_spi_init(1);
// set the frequency ( 10Mhz ) // set the frequency ( 10Mhz )
mraa_spi_frequency(SPI_1, 10000000); mraa_spi_frequency(SPI_1, 10000000);
...@@ -111,7 +111,7 @@ void LSM9DS0::write_G(uint8_t address, uint8_t data) { ...@@ -111,7 +111,7 @@ void LSM9DS0::write_G(uint8_t address, uint8_t data) {
* Input : Address to read from * Input : Address to read from
* Returns : Results from chip * 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 // lets set the first two bits to 0
address = address & 0x3F; address = address & 0x3F;
...@@ -137,7 +137,7 @@ uint8_t read_XM(uint8_t address) { ...@@ -137,7 +137,7 @@ uint8_t read_XM(uint8_t address) {
* *
* Input : Address to write to, data to write * 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 // lets set the first two bits to 0
address = address & 0x3F; address = address & 0x3F;
...@@ -175,6 +175,10 @@ uint8_t LSM9DS0::read(mraa_spi_context SPI, uint8_t address) { ...@@ -175,6 +175,10 @@ uint8_t LSM9DS0::read(mraa_spi_context SPI, uint8_t address) {
send_data = send_data | 0x8000; send_data = send_data | 0x8000;
send_data = send_data & 0xBFFF; 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 // send the data down the channel and get the result
uint8_t result = mraa_spi_write_word(SPI, send_data); 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) { ...@@ -198,6 +202,10 @@ void LSM9DS0::write(mraa_spi_context SPI, uint8_t address, uint8_t data) {
// add the data to be sent // add the data to be sent
send_data = send_data | data; 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 // send the data down the channel
mraa_spi_write_word(SPI, send_data); mraa_spi_write_word(SPI, send_data);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment