Reading from SPI

Status
Not open for further replies.

MarkTed

New member
Hey, I'm having trouble reading from the SPI1 port of the teensy 4.1. I am able to write using the SPI1 port, and the data I am trying to read is present on the MISO1 pin (41) of the teensy when I use an oscilloscope, but I am unable to read that data into a variable in my code for some reason.

Code:
void PLLSend(int regData, int chipNum)
{
  int byte1;
  int byte2;
  int byte3;

  byte byte4;
  byte byte5;
  byte byte6;

  byte1 = regData / 65536;
  byte2 = regData % 65536;
  byte3 = byte2 % 256;
  byte2 = byte2 / 256;

  switch (chipNum)
  {
    case 1:
      digitalWrite(30, LOW);
      digitalWrite(29, LOW);
      digitalWrite(28, LOW);
      //delayMicroseconds(2);
      break;
    case 2:
      digitalWrite(30, LOW);
      digitalWrite(29, LOW);
      digitalWrite(28, HIGH);
      delayMicroseconds(1);
      break;
    case 3:
      digitalWrite(30, LOW);
      digitalWrite(29, HIGH);
      digitalWrite(28, LOW);
      delayMicroseconds(1);
      break;
    case 4:
      digitalWrite(30, LOW);
      digitalWrite(29, HIGH);
      digitalWrite(28, HIGH);
      delayMicroseconds(1);
      break;
    case 5:
      digitalWrite(30, HIGH);
      digitalWrite(29, LOW);
      digitalWrite(28, LOW);
      delayMicroseconds(2);
      break;
    case 6:
      digitalWrite(30, HIGH);
      digitalWrite(29, LOW);
      digitalWrite(28, HIGH);
      delayMicroseconds(1);
      break;
    case 7:
      digitalWrite(30, HIGH);
      digitalWrite(29, HIGH);
      digitalWrite(28, LOW);
      delayMicroseconds(1);
      break;
    case 8:
      digitalWrite(30, HIGH);
      digitalWrite(29, HIGH);
      digitalWrite(28, HIGH);
      delayMicroseconds(2);
      break;
  }
  SPI1.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
  digitalWrite(40, HIGH);
  byte4 = SPI1.transfer(byte1);
  byte5 = SPI1.transfer(byte2);
  byte6 = SPI1.transfer(byte3);
  digitalWrite(40, LOW); //Deselecting Chip
  SPI1.endTransaction();

  //Serial.print(byte4);
  //Serial.print(byte5);
  //Serial.print(byte6);
}
The first section is used for splitting the 24 bit data being passed into three 8 bit chunks that I can send with "SPI1.transfer". The switch statement is for setting the CS spin for one of 8 chips using a 3 to 8 arbiter chip. The very last section is my SPI code which should work as far as I'm aware, but I get noting using the "Serial.print" functions. It just shows me that data being read is all zeros.

Any help would be appreciated. Thank you!
 
Last edited by a moderator:
Thank you for the fast response! I'm not completely sure where my pin 41 assumption came from, but I have edited the hardware to match the proper pin assignments and still have the same issue.
 
Status
Not open for further replies.
Back
Top