Go Down

Topic: Problem interfacing UM7 and Genuino 101 using SPI (Read 259 times) previous topic - next topic

crazyFrg

Hello,

I'm trying to read the 3 dimensional accelerations measured by the UM7 (the datasheet can be found there: https://www.redshiftlabs.com.au/sensors/um7-lt ) using a Genuino 101 and SPI. I also attached a picture of my wiring.

The connection seems to work as I don't get any error message but the issue is that it returns only zeroes for the three accelerations. I have no idea what the cause of the problem is. Thank you for any help.

Here is my current code:


Code: [Select]
/*
  Circuit:
  MOSI: pin 11
  MISO: pin 12
  SCK: pin 13
  SS/CS: pin 7
  Vin: 5V
  Gnd: Gnd
*/

// the sensor communicates using SPI, so include the library:
#include <SPI.h>

//Sensor's memory register addresses:
const int XACCEL = 0x65;  //Register containing the actual measured acceleration in m/s/s after calibration has been applied
const int YACCEL = 0x66;
const int ZACCEL = 0x67;
const byte READ = 0b00000000;     // UM7's read command
const byte WRITE = 0b00000001;   // UM7's write command

// pins used for the connection with the sensor
// the other you need are controlled by the SPI library):
const int chipSelectPin = 7;

void setup() {
  Serial.begin(9600); // initialize Serial communication
  while (!Serial) ;   // wait for serial port to connect.

  // start the SPI library:
  SPI.begin();

  // initalize the chip select pin:
  pinMode(chipSelectPin, OUTPUT);

  // is any configuration of the chip required?
}

void loop() {
  delay(200);
  //Read the acceleration data
  float Xaccel = readRegister(XACCEL, 4);
  float Yaccel = readRegister(YACCEL, 4);
  float Zaccel = readRegister(ZACCEL, 4);
  
  // display it:
  Serial.print(" Accel (unit)");
  Serial.print(" X=");
  Serial.print(Xaccel);
  Serial.print(" Y=");
  Serial.print(Yaccel);
  Serial.print(" Z=");
  Serial.println(Zaccel);

  delay(100);
}

//Read from register of the UM7:
unsigned int readRegister(byte thisRegister, int bytesToRead ) {
  
  byte inByte = 0;           // incoming byte from the SPI
  unsigned int result = 0;   // result to return
  //Serial.print(thisRegister, BIN);

  // take the chip select low to select the device:
  digitalWrite(chipSelectPin, LOW);

  // a read operation is performed by writing the control byte 0x00 to the MOSI line
  SPI.transfer(0x00);
  delayMicroseconds(5);
  // followed by the address of the register to be read
  SPI.transfer(thisRegister);
  delayMicroseconds(5);
  
  // send a value of 0 to read the first byte returned:
  result = SPI.transfer(0x00);
  delayMicroseconds(5);
  Serial.println(result);
  // decrement the number of bytes left to read:
  bytesToRead--;
  // if you still have another byte to read:
  if (bytesToRead > 0) {
    // shift the first byte left, then get the second byte:
    result = result << 8;
    inByte = SPI.transfer(0x00);
    delayMicroseconds(5);
    Serial.println(inByte, BIN);
    // combine the byte you just got with the previous one:
    result = result | inByte;
    // decrement the number of bytes left to read:
    bytesToRead--;
  }
  // take the chip select high to de-select:
  digitalWrite(chipSelectPin, HIGH);
  // return the result:
  return(result);
}

pylon

Quote
The connection seems to work as I don't get any error message but the issue is that it returns only zeroes for the three accelerations.
The SPI interface cannot detect a missing device as there is no acknowledgement of the data from the slave.

My guess is a wiring problem. Also the 101 has level shifters for all pins to have 5V level but your sensor accepts only 3.3V according to the datasheet. You may have fried the sensor already.

crazyFrg

Thanks for the answer, I double checked the wiring and reduced the voltage, still no success.

Is there a way to check if the sensor is fried?

pylon

Quote
Is there a way to check if the sensor is fried?
Check the reaction using a logic analyzer. As your sensor seems to have an ARM processor for the calculations the chance that it survived the 5V is not really high. But as the sensor is quite expensive it might be worth a try to send it a simple command and check for any reaction.

crazyFrg

#4
Jul 17, 2019, 05:14 pm Last Edit: Jul 17, 2019, 05:15 pm by crazyFrg
I didn't know what to send it to receive a reaction so I plug the MAIN IO HEADER into this USB Expansion Board (https://www.redshiftlabs.com.au/usb-expansion-board) to connect it to my PC using the Redshift Serial Interface and I obtained the acceleration data so I assume it isn't fried...

Unless I damaged the IO EXPANSION HEADER which I was previously connected to, if that's even possible?

pylon

As far as I can see that uses the UART interface to the sensor. It might be possible that you just fried the SPI pins of the sensor controller. If it's OK for you to use the UART interface you may use that one with your 101 but also there: use level converters for all connections!

Go Up