Hi guys,
I'm trying to communicate with a relatively simple sensor but after many attempts I don't even know how to get an "ack" out of it. I've tried going through tutorials and sketches for a while now to no avail.
I'll post my code then post the datasheet of the communications portion.
How do I build and send the start command? Am I reading the data back correctly?
[update] Using an Uno.
Any help is MUCH appreciated. Thanks.
My Code:
/*
Circuit:
CSB: pin 10
MOSI: pin 11
MISO: pin 12
SCK: pin 13
*/
// inslude the SPI library:
#include <SPI.h>
const int chipSelectPin = 10;
void setup() {
Serial.begin(115200);
// start the SPI library:
SPI.begin();
SPI.setBitOrder(LSBFIRST);
SPI.setDataMode(SPI_MODE2);
SPI.setClockDivider(SPI_CLOCK_DIV4);
// initalize the data ready and chip select pins:
pinMode(chipSelectPin, OUTPUT);
digitalWrite(chipSelectPin, LOW);
// give the sensor time to set up:
delay(1000);
}
void loop(){
startMeasuring();
delay(1000);
}
void startMeasuring(){
byte cmd = 0x80;
byte len = 0x0001;
byte fcs = 0x81;
//Trying to get either to work
Serial.println(SPI.transfer(cmd));
Serial.println(SPI.transfer(len));
Serial.println(SPI.transfer(fcs));
Serial.println(SPI.transfer(cmd & len & fcs));
}
Datasheet: