Has anyone had any luck using a master and slave from the same device? i.e. preferably using a teens4.1 SPI as master and SPI1 as slave? or vice versa?
I had it working with two teensy4.1 talking to each other over SPI but struggling to get it working on the same unit.
In this instance I am using SPI1 as the Master but as soon as uncomment
// mySPI.onReceive(myFunc);
// mySPI.begin();
It stops printing out the data being sent by the master
I had it working with two teensy4.1 talking to each other over SPI but struggling to get it working on the same unit.
In this instance I am using SPI1 as the Master but as soon as uncomment
// mySPI.onReceive(myFunc);
// mySPI.begin();
It stops printing out the data being sent by the master
Code:
#include "SPISlave_T4.h"
#include <SPI.h>
#define CS_SLAVE 0
#define CS_MASTER 10
#define DISP_CHANNEL_1 32
#define DISP_RETURN 19
#define SPI_MASTER SPI1
#define DATA 2
SPISlave_T4<&SPI, SPI_16_BITS> mySPI;
void myFunc()
{
Serial.println("START: ");
uint8_t arr[] = {3, 2, 8, 3, 10, 11, 33, 13, 14};
uint8_t i = 0;
while (mySPI.active())
{
if (mySPI.available())
{
if (i++ > sizeof(arr))
i = 0;
mySPI.pushr(arr[i]);
Serial.print("VALUE: ");
Serial.println(mySPI.popr());
}
}
Serial.println("END");
}
void setup()
{
// Serial
Serial.begin(115200); // Begin Serial
// Master SPI
pinMode(CS_MASTER, OUTPUT); // Set Master Chip Select as Output
digitalWrite(CS_MASTER, HIGH); // Set Master Chip Select High
SPI_MASTER.begin(); // Begin Master SPI
SPI_MASTER.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0)); // Begin Master SPI Transaction
// Display Pins
pinMode(DISP_RETURN, OUTPUT);
pinMode(DISP_CHANNEL_1, OUTPUT);
digitalWrite(DISP_RETURN, HIGH);
digitalWrite(DISP_CHANNEL_1, HIGH);
while (!Serial)
;
// mySPI.onReceive(myFunc);
// mySPI.begin();
}
void loop()
{
digitalWrite(CS_MASTER, LOW);
for (uint16_t i = 0; i < 50; i++)
Serial.println(SPI_MASTER.transfer16(i));
digitalWrite(CS_MASTER, HIGH);
delay(1000);
}