SPI issues with Teensy 3.2, Voltage Translator and IMU- recieves 255

Status
Not open for further replies.

operl

New member
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!

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:
The first thing I would probably do, is to try using your SPISettings to see if they help.

That is: I would add a call to: beginTransaction... Something like: SPI.beginTransaction(SPISettings(30000000, MSBFIRST, SPI_MODE0));
Note: the value you put above for 7000000000 will probably not work... maybe something like: 7000000 That number does not fit into a uint32_t value (which the clock field is)...
So again maybe the loop like:
Code:
void loop() {
  // put your main code here, to run repeatedly
  byte inByte = 0; 
  byte dataToSend = READ;
  unsigned int result = 0;
  SPI.beginTransaction(SPISettings(7000000, MSBFIRST, SPI_MODE0));
  digitalWrite(slaveSelectPin, LOW);
  SPI.transfer(dataToSend);
  result = SPI.transfer(0x00);
  digitalWrite(slaveSelectPin, HIGH);
  SPI.endTransaction();
  //Serial.println("Value: " + result);
  Serial.println(result);
}
 
that doesn't seem to work either. I found a mistake that the slave select pin should be 10 not 20. I'm still getting 255 though
 
Again with many things like this, it might help if you posted Photos and/or actual wiring diagrams, so maybe someone will see something obvious.

For example it has been a long time since I have used any of the TXBxxxx level shifters.

I don't remember how well they work with SPI and if you need to do anything special like use some external Pull up resisters are needed and if so what speed these chips will work at.

If I had the setup, I would probably hook up Logic Analyzer to the SPI pins and see what the state of things are, but...
 
imu-teensy.jpg Here it is.
 
Status
Not open for further replies.
Back
Top