Teensy slave MISO output is always 0x00 using TSPISlave library

Status
Not open for further replies.

KishoreK31

New member
Hey all,


EDIT: It seems to be a problem with my Teensy. I tried the same code on another one. It works. :)




I have been trying to sending some data from Teensy 3.2 to Rasp Pi 4B with Teensy as slave using SPI. I used @tonton81's library. I can send out data from RaspPi and read it in Teensy. However, my main purpose behind doing all this is to push some sensor data that Teensy collects, to RaspPi. Therefore, Teensy writing to RaspPi is what is more important to me and that isn't happening. I used a logic analyser and the MISO pins at the RaspPi is 0x00 always. {Note: MOSI and MISO in this post are all referred to RaspPi. MOSI of Rasp pi is connected to MISO of Teensy and vice versa}. Here are the codes I used at both Master and slave side, along with logic analyser output.

Master code: RPi

Code:
import time
import spidev

spi = spidev.SpiDev()
spi.open(0, 1)
spi.max_speed_hz = 100000 #(100 kHz)
spi.mode = 0
print("Beginning bit sweep")

spi.xfer2([0x20])  # Clear LEDs
while(1):
    time.sleep(3)
    spi.xfer2([0x01,0x03])
    # test = spi.readbytes(2)
    # print(test)

Slave code: (mostly similar to @tonton8's example in his library. But I'm using 8 bits instead of his 16 bit example)

Code:
#include "TSPISlave.h"

uint8_t miso = 12;
uint8_t mosi = 11;
uint8_t sck = 13;
uint8_t cs = 10;
uint8_t spimode = 8;
TSPISlave mySPI = TSPISlave(SPI, miso, mosi, sck, cs, spimode);

void setup() {
  Serial.begin(115200);
  mySPI.onReceive(myFunc);
}

void loop() {
  delay(1000);
  Serial.println(millis());
}

void myFunc() {
  Serial.println("START: ");
  uint8_t arr[2] = { 0x11, 0x22 };
  uint8_t i = 0;
  while ( mySPI.active() ) {
    if (mySPI.available()) {
      mySPI.pushr(arr[i++]);
      Serial.print("Value: 0x");
      Serial.println(mySPI.popr(), HEX);
    }
  }
  Serial.println("END");
}

Logic Analyser output: https://imgur.com/9hrZwOR
Teensy's Serial output: https://imgur.com/fSjOBXo
 
Last edited:
Check to make sure the MISO and MOSI pins are not reversed, try swapping them around and testing it again

On some teensies, the labels are reversed for MISO and MOSI when in slave mode
 
Status
Not open for further replies.
Back
Top