yeah i didnt release the t3.x yet as im still playing with the LC stuff in it
but in case of the T3.x compatibility you can add more ADCs and touch sensors to your T4 projects
SPI_MSTransfer_T4_FUNC void SPI_MSTransfer_T4_OPT::ifLC(uint16_t data) {
#if defined(KINETISL)
while ( !::digitalReadFast(10) && !(SLAVE_S & SPI_S_SPTEF) );
SLAVE_DH = data >> 8;
SLAVE_DL = data;
#endif
}
SLAVE_TDR = data[buffer_pos];
ifLC(SLAVE_TDR = data[buffer_pos]);
#define SLAVE_RDR (((uint16_t)(SLAVE_DH << 8)) | SLAVE_DL)
#define SLAVE_TDR(x) spiAddr[25] = (x)
#define SLAVE_TDR(x) spiAddr[13] = (x)
#define SLAVE_TDR(x) \
while ( !::digitalReadFast(10) && !(SLAVE_S & SPI_S_SPTEF) ); \
(SLAVE_DH = (uint8_t)((x) >> 8)); \
(SLAVE_DL = ((uint8_t)(x)));
SLAVE_TDR(0xA5A5);
ifLC(SLAVE_TDR = 0xA5A5);
Just added a processing function for master end, instead of having duplicated code in all transfers, they simply pass in a pre-made buffer to it, it does the transfers, and returns a crc pass as well as returned data; Also added analogRead/Write(and Resolution) support as well.
121506
0 Queues.
121507
7 0 82 0 1939 4223 A127 C293 0 4200 0 0 165 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 --> Length: 36
--> SlaveID: 4660
--> PacketID: 1001
0 Queues.
121507
0 Queues.
121508
#include "SPI.h"
#include "SPI_MSTransfer_MASTER.h"
SPI_MSTransfer_MASTER<&SPI, 10, 0x1234> mySPI1234;
SPI_MSTransfer_MASTER<&SPI, 10, 0x4567> mySPI4567;
//define a struct of various data types
typedef struct MYDATA_t {
int sats;
int hdop;
float lat;
float longit;
float alt;
float speed;
int course;
long date;
long time;
};
//define a struct joining MYDATA_t to an array of bytes to be stored
typedef union MYDATA4XFER_t {
MYDATA_t datastruct;
uint16_t Packet[sizeof(MYDATA_t)];
};
MYDATA4XFER_t mydata; //data to be written in memory
void setup() {
Serial.begin(115200);
SPI.begin();
pinMode(10, OUTPUT);
digitalWrite(10, 1);
mySPI1234.begin();
//mySPI4567.begin();
mySPI1234.onTransfer(myCB);
}
void loop() {
static uint32_t t = millis();
if ( millis() - t > 1000 ) {
Serial.println(millis());
Serial.print(mySPI1234.events()); Serial.println(" Queues.");
uint16_t buf[2] = { 0xBEEF, 0xD0D0 };
//uint16_t buf2[5] = { 0xBEEF, 0xF7, 0xF8, 0xF9, 0xDEAD };
mySPI1234.transfer16(buf, 2, 0x1000);
//mySPI1234.transfer16(buf2, 5, 0x8000);
}
}
void myCB(uint16_t *buffer, uint16_t length, AsyncMST info) {
if(info.packetID == 0x1001) {
for ( int i = 0; i < length; i++ ) {
Serial.print(buffer[i], HEX); Serial.print(" ");
}
Serial.print(" --> Length: "); Serial.println(length);
Serial.print(" --> SlaveID: "); Serial.println(info.slaveID);
Serial.print(" --> PacketID: "); Serial.println(info.packetID, HEX);
}
}
#include "SPI_MSTransfer_T4.h"
SPI_MSTransfer_T4<&SPI, 0x1234> mySPI;
#include "GPS.h"
//define a struct of various data types
typedef struct MYDATA_t {
int sats;
int hdop;
float lat;
float longit;
float alt;
float speed;
int course;
long date;
long time;
};
//define a struct joining MYDATA_t to an array of bytes to be stored
typedef union MYDATA4XFER_t {
MYDATA_t datastruct;
uint16_t Packet[sizeof(MYDATA_t)];
};
MYDATA4XFER_t mydata; //data to be written in memory
void setup() {
while (!Serial && (millis() < 5000))
; // wait for Arduino Serial Monitor
Serial.println("\n\nUSB Host Testing - Serial");
myusb.begin();
mySPI.begin();
mySPI.onTransfer(myCB);
Serial.print("Testing TinyGPS library v. ");
Serial.println(TinyGPS::library_version());
Serial.println("by Mikal Hart");
Serial.println();
Serial.println("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum");
Serial.println(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail");
Serial.println("-------------------------------------------------------------------------------------------------------------------------------------");
}
void loop() {
myusb.Task();
devices();
mySPI.events();
static uint32_t t = millis();
if ( millis() - t > 1000 ) {
Serial.print("millis: "); Serial.println(millis());
t = millis();
}
}
void myCB(uint16_t *buffer, uint16_t length, AsyncMST info) {
if (info.packetID == 0x1000) {
uint32_t arraySize = sizeof(MYDATA_t);
//Serial.print(arraySize); Serial.println(" Array Size.");
gps_data();
if(mydata.datastruct.sats > 0)
mySPI.transfer16(mydata.Packet, arraySize, 0x1001);
} else {
for ( int i = 0; i < length; i++ ) {
Serial.print(buffer[i], HEX); Serial.print(" ");
}
Serial.print(" --> Length: "); Serial.print(length);
Serial.print(" --> PacketID: "); Serial.println(info.packetID, HEX);
}
}
void gps_data() {
float flat, flon;
unsigned long age, chars = 0;
unsigned short sentences = 0, failed = 0;
static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
if (userial) {
mydata.datastruct.sats = gps.satellites();
print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
mydata.datastruct.hdop = gps.hdop();
print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
gps.f_get_position(&flat, &flon, &age);
mydata.datastruct.lat = flat; mydata.datastruct.longit = flon;
print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6);
print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
print_date(gps);
mydata.datastruct.alt = gps.f_altitude();
print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 7, 2);
mydata.datastruct.course = gps.f_course();
print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
mydata.datastruct.speed = gps.f_speed_mps();
print_float(gps.f_speed_mps(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0xFFFFFFFF : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? TinyGPS::GPS_INVALID_F_ANGLE : TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);
gps.stats(&chars, &sentences, &failed);
print_int(chars, 0xFFFFFFFF, 6);
print_int(sentences, 0xFFFFFFFF, 10);
print_int(failed, 0xFFFFFFFF, 9);
Serial.println();
//smartdelay(100);
}
}
Weird, works fine here, i changed on my slave to use 50 length random arrays and i set both master & 2 slaves to poll write at 10ms rates
Definitely do not use a blocking library like Adafruit_NeoPixel library if your project will be doing anything else while the LEDs update. You need a non-blocking library like OctoWS2811 or WS2812Serial.
If I am correct these libraries require the neopixels to be connected to a serial pin. But my project has neopixels connected to a digital pin is there a way to still make them work together with the spi communication?
// Usable pins:
// Teensy LC: 1, 4, 5, 24
// Teensy 3.2: 1, 5, 8, 10, 31 (overclock to 120 MHz for pin 8)
// Teensy 3.5: 1, 5, 8, 10, 26, 32, 33, 48
// Teensy 3.6: 1, 5, 8, 10, 26, 32, 33
// Teensy 4.0: 1, 8, 14, 17, 20, 24, 29, 39
// Teensy 4.1: 1, 8, 14, 17, 20, 24, 29, 35, 47, 53