Teensy 4.1 SPI Slave - No correct data reception

andrill

New member
Alright this is my first post on this forum. I'll try to provide sufficient details but have mercy.
So I am trying to make an Arduino UNO (master) and a Teensy 4.1 (slave) communicate via SPI. More specifically, the UNO sends the Teensy a byte every second whereafter the Teensy prints the byte to the Serial monitor (I intend this to be some sort of MVP for a bigger project to make sure the communication works fine). Since slave mode is not officially supported for the Teensy 4.1 I am trying to make it work using this library by tonton81 https://github.com/tonton81/SPISlave_T4 and a forum post by tjaekel https://forum.pjrc.com/index.php?threads/teensy-4-1-spi-slave-here-it-is.72792/.
Unfortunately, I am having some issues with the data transmission, namely the Rx buffers do not seem to be filled although the Receive Data Flag (SR) is set properly.

First my setup:
- The Arduino runs in master mode
- The Arduino uses SPI mode 0
- MSB first
- Data is transmitted at 500kHz

This can also be seen in the sketch for the Arduino:
C++:
#include <SPI.h>

#define SS_PIN 10

void setup() {
  pinMode(SS_PIN, OUTPUT);
  digitalWrite(SS_PIN, HIGH);
  SPI.begin();
  SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE0));
}

void loop() {
  digitalWrite(SS_PIN, LOW);
  delayMicroseconds(100);
  SPI.transfer(0x42);
  digitalWrite(SS_PIN, HIGH);
  delay(1000);
}

Wiring (UNO to Teensy), photo attached:
- Pin 13 to Pin 13 (SCK)
- Pin 11 to Pin 12 (MOSI, Note: According to tjaekel's post, the pins MOSI and MISO are swapped here)
- Pin 10 to Pin 10 (SS/CS)
- GND to GND


The problem:
As can be seen in the program (the code for the teensy including the library is attached) every time spiRxComplete is true the current
spiRxIdx should be printed to the Serial monitor. After that I expect the Teensy to print the already received bytes inside
spiRx. But for some reason the spiRxIdx always stays zero and this no bytes are printed. Still, after every transmission done by the Arduino the if-block executes (line 25) indicating that spiRxComplete is correctly set to true indicating further that RDF (SR) is set. So both the CLK and CS seem to be correctly received, only the MOSI line has some problems.


What I have already tried (without success):
- Changing the pin of the MOSI line on the teensy (although tjaekel's forum post specifies pin 12)
- Verified correct data transmission by the UNO using an oscilloscope (as can be seen in the pictures attached)
- Tried out different SPI modes (although the library hardcodes mode 0 from what I understand)
- Understand the library code (After a day of sitting behind the code and investigating into the i.MX RT1060X Processor Reference Manual I have already understood a lot more than before but I am certainly not experienced enough with low level programming to grasp every line of it. But I will certainly dig deeper!)


If somebody has an idea what could be wrong I would be very happy indeed!


Note: I have only marginally changed the code of the SPISlave_T4.tpp file so that the macro definitions for the register offsets use hex as in the reference manual because I consider that to be more readable when examining the code. But this should not change the behaviour at all (for safety I have even checked the whole setup with the original code).
 

Attachments

  • IMG_1559.jpg
    IMG_1559.jpg
    219.5 KB · Views: 51
  • IMG_1560.jpg
    IMG_1560.jpg
    227.3 KB · Views: 51
  • Teensy_SPIder.zip
    2.6 KB · Views: 96
  • IMG_1561.jpg
    IMG_1561.jpg
    336.8 KB · Views: 55
  • IMG_1564.jpg
    IMG_1564.jpg
    366.5 KB · Views: 90
  • IMG_1565.jpg
    IMG_1565.jpg
    345.1 KB · Views: 59
Correct me if I'm wrong but the Uno uses 5V? Do not connect 5V signals to the Teensy! It can only handle 3.3V and will be permanently damaged.
 
The T4 is absolutely _not_ 5V tolerant, 3.3V is the limit for all pins - this is clearly stated in the data for the device. You require level converters to talk to a 5V chip (if you haven't fried the T4 already).
 
Haha, awesome! I was sitting there hours on end but I forgot the most important aspect. After a few checks my Teensy seems to be fine despite the high voltage. Unfortunately, I haven't got a logic level converter at hand right now but I tried it with a simple voltage divider instead since I only need 1MHz max and it actually works! The Teensy successfully receives the data. I am a bit surprised that the high voltage caused the MCU to detect no data at all as I expected it do read at least something (frying the board in the process). But I won't complain. It works without any issues. Thanks a lot and the thread appears to be already finished here!
 
Back
Top