I have seen alot of SPI slave questions, seeing as SPI_MST is more or less a protocol and controller in itself. I decided to write a user end library that's capable of running multiple SPI slave ports on Teensy 3.x and LC, for users interested in writing their own data handling in a simple interface. The functions provided allow ease of access for the user without divulging into specific registers, especially on the Teensy LC. The sketch will work on all T3.x/LC models without any other differences in the commands. I tried to make it as simple as I could for the user, and all SPI ports (SPI0,1,2) on T3/LC support independant 8 or 16 bit mode via constructor.
However unless anyone has better suggestions, I had no other idea but to use uint8_t's for the pins, perhaps enums would have been better?
Irregardless, this is where I am at:
I started working on this since yesturday and finally got the LC running on SPI0 and SPI1 before I finished off testing SPI1 and 2 of T3.5
The master has no library, you can send data to the slave as you wish.
while ( mySPI.active() ) allows the user to handle multiple bytes/words within the same transaction, an array is there as an example to shift out data for the master on sequential transfers
available() must be checked before read/writing the data
popr and pushr are used to read and write respectively the data once the available() is triggered
popr and pushr also handle the DL and DH registers of the LC so the user wouldn't need to worry about that, essentially making the sketch work accross all recent teensy boards
if anyone has constructor ideas or just to leave that as is, let me know, I should have a release uploaded later today. I tested all SPI busses on LC and T3.x before writing this post
T3.x connections:
MISO -> MISO
MOSI -> MOSI
LC connections:
MISO -> MOSI
MOSI -> MISO
Also on the LC, you should run your pushr() after the popr(), as LC uses same register for both, youll need to push the data last
https://github.com/tonton81/TSPISlave
EDIT, just posted the library, I will update the supported SPI pin list for each port in a few minutes
Tony
However unless anyone has better suggestions, I had no other idea but to use uint8_t's for the pins, perhaps enums would have been better?
Irregardless, this is where I am at:
Code:
#include "TSPISlave.h"
TSPISlave mySPI = TSPISlave(SPI2, 51, 52, 53, 43, 8); // MISO,MOSI,SCK,CS,8bit transfers
void setup() {
Serial.begin(115200);
mySPI.onReceive(myFunc); // callback for mySPI
}
void loop() {
delay(1000);
Serial.println(millis());
}
void myFunc() {
Serial.println("START: ");
uint16_t arr[2] = { 0x1111, 0x2222 };
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");
}
I started working on this since yesturday and finally got the LC running on SPI0 and SPI1 before I finished off testing SPI1 and 2 of T3.5
The master has no library, you can send data to the slave as you wish.
while ( mySPI.active() ) allows the user to handle multiple bytes/words within the same transaction, an array is there as an example to shift out data for the master on sequential transfers
available() must be checked before read/writing the data
popr and pushr are used to read and write respectively the data once the available() is triggered
popr and pushr also handle the DL and DH registers of the LC so the user wouldn't need to worry about that, essentially making the sketch work accross all recent teensy boards
if anyone has constructor ideas or just to leave that as is, let me know, I should have a release uploaded later today. I tested all SPI busses on LC and T3.x before writing this post
T3.x connections:
MISO -> MISO
MOSI -> MOSI
LC connections:
MISO -> MOSI
MOSI -> MISO
Also on the LC, you should run your pushr() after the popr(), as LC uses same register for both, youll need to push the data last
https://github.com/tonton81/TSPISlave
EDIT, just posted the library, I will update the supported SPI pin list for each port in a few minutes
Tony
Last edited: