Teensy 3.5 SPI master and Slave, what library to use, how.

Garug

Well-known member
I am experimenting a bit with Canon EF protocol and use Teensy 3.5 as it tolerates 5 V directly.

Idea is to connect SPI 0 to camera and SPI 1 to lens, and as first step just pass through the SPI messages both directions, later on monitor them, and control the lens etc. The electrical connections I basically have ready, now need to establish the SW side of it.

The problem is SPI.h does not support slave, in this case SPI 0. do I need to use the tonton81/SPI_MSTransfer_T4 or is there way to make the SPI.h to support both slave and master? if not is the tonton81/SPI_MSTransfer_T4 the right library to use.

The code would be someting like this, bit having problems compiling it


#include <SPI.h>
#include "SPI_MSTransfer_T4.h"
#include "SPI_MSTransfer_MASTER.h"
// Define SPI1 master and SPI0 slave
SPI_MSTransfer_T4<&SPI, 0x1234> spi0slave;
SPI_MSTransfer_MASTER<&SPI, 10, 0x1234> spi1master;
void setup() {
Serial.begin(9600);
// Initialize SPI1 as Master
spi1master.begin();
spi1master.setMOSI(0);
spi1master.setMISO(1);
spi1master.setSCK(32);
spi1master.setCS(6); // Dummy CS pin, required by the library
// Initialize SPI0 as Slave
spi0slave.begin();
spi0slave.setMOSI(11);
spi0slave.setMISO(12);
spi0slave.setSCK(13);
spi0slave.setCS(10); // Dummy CS pin, required by the library
Serial.println("Setup Complete");
}
void loop() {
// Forward data from SPI0 to SPI1
if (spi0slave.available()) {
uint8_t dataFromSPI0 = spi0slave.transfer(0x00); // Read data from SPI0
spi1master.transfer(dataFromSPI0); // Write data to SPI1
}
// Forward data from SPI1 to SPI0
uint8_t dataFromSPI1 = spi1master.transfer(0x00); // Read data from SPI1
spi0slave.transfer(dataFromSPI1); // Write data to SPI0
}
I am trying to use the tonton81/SPI_MSTransfer_T4 from same directory than the code, so that might be the problem, do not want to instal any libraries that are not natively supported.
 
Back
Top