This is my first time trying to use spi with the teensy.
I connected my ICM 20948 to my teensy 3.2 (i know there is an i2c code onine, but i need to use spi) and am using a Voltage Translater because the ICM uses 1.8V instead of 3.3. I used a zener diode and resistor to lower the voltage to 1.8. Through the shifter, i connected SDI to DIN(12), SCLK to SCK(13), SDO to DOUT(12), and nCS to CS(10). I am trying to get the information from address 0 (Who_am_I) and it should return 0xEA. Unfortunately, I am getting a value of 255. I have provided code below. Any suggestions on how troubleshot and fix it? Thanks!
I connected my ICM 20948 to my teensy 3.2 (i know there is an i2c code onine, but i need to use spi) and am using a Voltage Translater because the ICM uses 1.8V instead of 3.3. I used a zener diode and resistor to lower the voltage to 1.8. Through the shifter, i connected SDI to DIN(12), SCLK to SCK(13), SDO to DOUT(12), and nCS to CS(10). I am trying to get the information from address 0 (Who_am_I) and it should return 0xEA. Unfortunately, I am getting a value of 255. I have provided code below. Any suggestions on how troubleshot and fix it? Thanks!
Code:
#include <SPI.h> // include the new SPI library:
const int slaveSelectPin = 20;
SPISettings settingsA(7000000000, MSBFIRST, SPI_MODE0);
const int WHO = 0x00;
const byte READ = 0b10000000; // SCP1000's read command
const byte WRITE = 0b00000000; // SCP1000's write command
void setup() {
Serial.begin(115200);
// initialize SPI:
SPI.begin();
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
delay(100);
}
void loop() {
// put your main code here, to run repeatedly
byte inByte = 0;
byte dataToSend = READ;
unsigned int result = 0;
digitalWrite(slaveSelectPin, LOW);
SPI.transfer(dataToSend);
result = SPI.transfer(0x00);
digitalWrite(slaveSelectPin, HIGH);
//Serial.println("Value: " + result);
Serial.println(result);
}
Last edited by a moderator: