Arduino 2560 and CHR-UM6 SPI Code (Working)

Hi Everyone,

I spent a lot of time looking/trying to figure out how to use an Arduino and SPI to communicate with the UM6, the biggest problem is that a lot of people had a problem, then most likely got it working and never posted the code. Therefore here is my code (Works for reading acceleration Z in Newtons)

 
#define READ 0x00
#define WRITE 0x01
#define ss 53
#include<SPI.h>

signed int temp[4];


void setup(){
  SPI.begin();
  Serial.begin(9600);
  pinMode(ss,OUTPUT);
  digitalWrite(ss,HIGH);
  SPI.setDataMode(SPI_MODE0);  // CPOL = 0, CPHA = 0
  SPI.setClockDivider(SPI_CLOCK_DIV64); //t_clk = 4.00us
  SPI.setBitOrder(MSBFIRST);
}

void loop()
{
      
    digitalWrite(ss, LOW);
    delayMicroseconds(10);
    SPI.transfer(READ);
    SPI.transfer(0x5F);
    temp[3] = SPI.transfer(0x00);
    temp[2] = SPI.transfer(0x00);
    temp[1] = SPI.transfer(0x00);
    temp[0] = SPI.transfer(0x00);
    digitalWrite(ss, HIGH);
    int temp1 = temp[3];
    int temp2 = temp1 << 8;
    temp2 = temp2 + temp[2];
    float accel_z = temp2 * 0.000183105 * 9.81;
    Serial.println(accel_z);
  
}

Cheers,
Nick

Hello, Nick.

Thank you for posting your work. I hope it helps other people who had trouble with this.

-Jamee

You are the man Nick!!!
Cheers!