SPI communication between Teensy 4.1 and arduino nano HELP!!!

EMBEDDEED

Member
So i have been trying to make SPI communication between nano and teensy when nano is master and teensy is slave but its not working i also tried multiple codes and such. I also tried SPI_MSTransfer_T4 library but with no luck. I tried to use code where arduino uno was communicating with another uno but i got error on line with this line : ISR (SPI_STC_vect) // SPI interrupt routine
I´ll be glad for any suggestion.
Thank you
 
Sounds like you tried to use a library designed only for Arduino Uno, though a link to the specific code used would lessen the guesswork.

This library with SPI slave support is made for Teensy 4:
 
Which SPI libraries did you use on the Nano and Teensy 4.1 respectively?
You may want to share your Nano code and Teensy code for others to have a look at.

Paul
 
Well for arduino i used <SPI.h> library and i used it for teensy as well but i tried also SPI_MSTransfer_T4 i tried several codes but for example this is the code for nano:

#include <SPI.h>

void setup() {
// Initialize SPI communication
SPI.begin();
// Set Slave Select pin as OUTPUT
pinMode(SS, OUTPUT);
// Select the Slave
digitalWrite(SS, LOW);
}

void loop() {
// Send 1 via SPI
SPI.transfer(1);
delay(1000); // Delay for stability
}
and this is for teensy:

#include <SPI.h>

void setup() {
Serial.begin(9600); // Initialize serial communication
// Set up SPI communication
SPI.begin();
}

void loop() {
// Check if data is available via SPI
if (SPI.available()) {
// Read data from SPI
int data = SPI.transfer(0);
// Print received data to serial monitor
Serial.println(data);
}
}
 
It helps if you put your code between code tags using the </> button. See below.
Your initial post said hat you were setting the Teensy as a Slave but you have not used the SPI_MSTransfer_T4.h library as mentioned above.
It would be useful if you could turn on verbose output for compile. This will show the libraries used by the compiler for each MCU. See below..
z.png

Code:
#include <SPI.h>

void setup() {
    // Initialize SPI communication
    SPI.begin();
    // Set Slave Select pin as OUTPUT
    pinMode(SS, OUTPUT);
    // Select the Slave
    digitalWrite(SS, LOW);
}

void loop() {
    // Send 1 via SPI
    SPI.transfer(1);
    delay(1000); // Delay for stability
}

and this is for teensy:

Code:
#include <SPI.h>

void setup() {
    Serial.begin(9600); // Initialize serial communication
    // Set up SPI communication
    SPI.begin();
}

void loop() {
    // Check if data is available via SPI
    if (SPI.available()) {
        // Read data from SPI
        int data = SPI.transfer(0);
        // Print received data to serial monitor
        Serial.println(data);
    }
}
 
I want to help more, but I really can't. With technical questions, there are really 3 levels.

#1 - Best case is enough information to reproduce the problem.

#2 - Not as good but still possible to answer is when enough info is given to at least see the problem and the steps performed to cause the problem

#3 - Little to no info beyond "doesn't work" pretty much means any help amounts to blind guessing

I hope you will consider showing us photos of how you connected the hardware, clear info with links to the code if you used examples without modification or exact copies of the code if you changed anything (for the code used on both boards), and screenshots or exact copies of whatever error message or other wrong behavior your eyes actually observed. Please, don't just say it didn't work. Show us what you actually tried and allow us to see with our own eyes the wrong result. Or best of all, give enough info so anyone with those boards could quickly wire them together exactly the same way you did and actually reproduce the exact same problem.
 
well i certainly can provide you with wiring, and for the code the one i send was the first one but like i wrote i also used the SPI_MSTransfer_T4.h but with this error it went throught and was uploaded. This was the error:

In file included from c:\Users\Pc\Documents\Arduino\libraries\SPI_MSTransfer_T4-main/SPI_MSTransfer_T4.h:143,
from C:\Users\Pc\Documents\Windows file\SPI_MSTransfer_T4-main\examples\SPI_MSTransfer_SLAVE\SPI_MSTransfer_SLAVE.ino:1:
c:\Users\Pc\Documents\Arduino\libraries\SPI_MSTransfer_T4-main/SPI_MSTransfer_T4.tpp: In function 'void spi0_slave_isr()':
c:\Users\Pc\Documents\Arduino\libraries\SPI_MSTransfer_T4-main/SPI_MSTransfer_T4.tpp:7:34: warning: 'this' pointer is null [-Wnonnull]
7 | _SPI0->SPI_MSTransfer_SLAVE_ISR();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
c:\Users\Pc\Documents\Arduino\libraries\SPI_MSTransfer_T4-main/SPI_MSTransfer_T4.tpp: In function 'void spi1_slave_isr()':
c:\Users\Pc\Documents\Arduino\libraries\SPI_MSTransfer_T4-main/SPI_MSTransfer_T4.tpp:7:34: warning: 'this' pointer is null [-Wnonnull]
7 | _SPI0->SPI_MSTransfer_SLAVE_ISR();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
c:\Users\Pc\Documents\Arduino\libraries\SPI_MSTransfer_T4-main/SPI_MSTransfer_T4.tpp: In function 'void spi2_slave_isr()':
c:\Users\Pc\Documents\Arduino\libraries\SPI_MSTransfer_T4-main/SPI_MSTransfer_T4.tpp:7:34: warning: 'this' pointer is null [-Wnonnull]

And for arduino i used the basic like i send but i also tried the MASTER code from SPI_MSTransfer_T4.h library on the arduino.
Last thing I tried was code from whis website: https://circuits4you.com/2019/01/03/arduino-spi-communication-example/
 

Attachments

  • 421692099_400772199169936_8106350419240672994_n.jpg
    421692099_400772199169936_8106350419240672994_n.jpg
    139.8 KB · Views: 54
Back
Top