Skip to main content
Visitor II
December 6, 2023
Solved

Reading any register from IIS3DWB sensor only yields 11111111

  • December 6, 2023
  • 1 reply
  • 1673 views
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!
    This topic has been closed for replies.
    Best answer by xl

    @Federica Bossi 

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

    1 reply

    Technical Moderator
    December 12, 2023

    Hi @xl ,

    Welcome to ST Community!

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

    Thanks

    xlAuthorAnswer
    Visitor II
    December 13, 2023

    @Federica Bossi 

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