cancel
Showing results for 
Search instead for 
Did you mean: 

Reading any register from IIS3DWB sensor only yields 11111111

xl
Associate
Hello,
I have run into an unexpected problem when trying to read registers from the IIS3DWB sensor. The setup is attached in the picture. I am using an Arduino Uno R3 and an STEVAL MKI208V1 board. The code is fairly simple so I am not sure what is going wrong when I try to read any of the registers via SPI.
 
#include <SPI.h>

const int chipSelectPin = 10;

void setup() {
  // put your setup code here, to run once:
  pinMode(chipSelectPin, OUTPUT);
  digitalWrite(chipSelectPin, HIGH);
 
  Serial.begin(9600);

  writeRegister(0x0D, 0x01); // Accelerometer data-ready interrupt on INT1
  writeRegister(0x15, 0x00); // 3-axis mode enabled
  writeRegister(0x10, 0xA0); // Enable accelerometer (ODR = 26.667 kHz, FS = +-2 g)
}

void loop() {
  uint8_t temp = readRegister(0x0F);
  Serial.println(temp, BIN);
  delay(1000);
}

uint8_t readRegister(uint8_t reg) {
  SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
  digitalWrite(chipSelectPin, LOW);

  SPI.transfer((reg & 0x7F) | 0x80);
  uint8_t temp = SPI.transfer(0);

  digitalWrite(chipSelectPin, HIGH);
  SPI.endTransaction();
 
  return temp;
}

void writeRegister(uint8_t reg, uint8_t value) {
  SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
  digitalWrite(chipSelectPin, LOW);
 
  SPI.transfer(reg & 0x7F);
  SPI.transfer(value);

  digitalWrite(chipSelectPin, HIGH);
  SPI.endTransaction();
}
 
Any help would be appreciated!
1 ACCEPTED SOLUTION

Accepted Solutions

@Federica Bossi 

It's okay. I managed to read the registers using a Raspberry Pi instead. Thanks!

View solution in original post

2 REPLIES 2
Federica Bossi
ST Employee

Hi @xl ,

Welcome to ST Community!

Can you share the schematic to understand how you connected the micro to the STEVAL MKI208V1?

Thanks

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

@Federica Bossi 

It's okay. I managed to read the registers using a Raspberry Pi instead. Thanks!