Project: SPI_MSTransfer

Well, most of the day was trying to scratch my way through a cinderblock wall with LC. I continued reading the datasheet and...... who said the SPI bus was 12MHz? Remember you made me switch to SPI0 because you had problems? and then when I started having problems, we all went nuts? :D I added the notes to the new slave update.
It turns out, SPI0 slave is calculated by bus speed (24MHz) divided by 4 which is 6MHz. SPI1 is calculated by SYStem clock, which is 48MHz/4 == 12MHz

Code:
[ATTACH]13853._xfImport[/ATTACH]


From the datasheet:
3.9.2.1
SPI instantiation information
The number of SPI modules on this device is: two
The supported data length is: 16-bit
SPI1 includes a 4-deep FIFO of 16-bit entries.
SPI0 is clocked on the bus clock. That is, the SPI0 module clock is connected to the chip-
level bus clock.
SPI1 is clocked from the system clock. That is, the SPI1 module clock is connected to the
chip-level system clock. SPI1 is therefore disabled in Partial Stop Mode.
The SPI supports DMA request and can operate in VLPS mode. When the SPI is
operating in VLPS mode, it will operate as a slave.
SPI can wake the MCU from VLPS mode upon reception of SPI data in slave mode.

You can check the slave timings & info in the NXP datasheet:
https://www.nxp.com/docs/en/data-sheet/KL26P64M48SF5.pdf

Table 33 and 34 of page 40: "SPI slave mode timing"
 
It turns out, SPI0 slave is calculated by bus speed (24MHz) divided by 4 which is 6MHz. SPI1 is calculated by SYStem clock, which is 48MHz/4 == 12MHz
So that is what the whole issue boiled down to - you kind of hinted at it when you kept saying it was a timing issue.
 
The NXP document made that pretty clear when I saw the timing tables (I couldn't find them on the pjrc datasheet for the same chip, only section 3.9.2.1 from pjrc datasheet which mentioned what busses they use)

as you see, at 11mhz, we got 480Hz f&f's :)
Code:
30562.00, #, #, #, #, #, #, #, #, #,2762188,9 [480 ,0
30572.00, #, #, #, #, #, #, #, #, #,2762189,9 [480 ,0
30582.00, #, #, #, #, #, #, #, #, #,2762190,9 [480 ,0
30592.00, #, #, #, #, #, #, #, #, #,2762191,9 [480 ,0
30602.00, #, #, #, #, #, #, #, #, #,2762192,9 [480 ,0
30612.00, #, #, #, #, #, #, #, #, #,2762193,9 [480 ,0
30622.00, #, #, #, #, #, #, #, #, #,2762194,9 [480 ,0

Ignore the 9, every time I open up serial monitor it increments lol

Yes, library still supports both! always!
All slave ports of LC, 3.2, 3.5 and 3.6 are accessible

Oh, no, not same folder yet....
Been busy with the frequencies today...............................
BTW, as you seen, I was really flooding the LC today at 10MHz, no pauses, the console was scrolling so fast it started jumping pages intermittantly, it was going nuts, about 15 minutes later, USBSerial output died from the abuse, but the led kept toggling :)

So, in the LC startup page, I mentioned 4MHz for SPI0 as a recommended speed, and 11MHz for the SPI1, so that.. we know. Guess LC it's a no brainer to use SPI1 now :)

Your lucky to squeeze >6mhz out of SPI0, but the hastle it invoked on trying to fix for frequencies not supported was rediculous lol :p 4mhz ran alot better

But like I said, at this point it's running all around 11MHz, there can't be an issue with the LC code now especially since its capable of running events and slave receptions in tight loops
 
Last edited:
Your lucky to squeeze >6mhz out of SPI0, but the hassle it invoked on trying to fix was ridiculous lol 4mhz ran alot better
Agree it was a hassle, but I think it was more because we didn't see the note on the different clocks for spi0 and spi1
 
Geez, I wonder if they did the same to the 3.x series

Oh yeah mike, you can do your tests as normal, theres been a bug fix with all the functions in sending responses back to master (even for 3x's), I corrected them all , they been reading one byte past the buffer (but the master ignored it as the one before it completed the CRC check). So this bug was actually ignored by the master for a long time lol...

hey I'm checking the NXP document for the T3.6 chip

http://cache.freescale.com/files/microcontrollers/doc/data_sheet/K64P144M120SF5.pdf
Page 56: Table 45. Slave mode DSPI timin
The maximum operating frequency is measured with non-continuous CS and SCK. When DSPI is configured with
continuous CS and SCK, there is a constraint that SPI clock should not be greater than 1/6 of bus clock, for example,
when bus clock is 60MHz, SPI clock should not be greater than 10MHz

*cringe* lol
 
Ok. Right now I have two speeds defined:
Code:
#define SPI_SPEED 10000000
#define GPIO2_SPI_SPD 4000000

Now if SPI1 is used:
Code:
#define SPI_SPEED 11000000
#define GPIO2_SPI_SPD 11000000

With lcmode(0,10)?
 
Yup, 11MHz all around, LCmode(0,10) yes, haha you still wanna squeeze 10mhz out of a 6mhz bus.... ok :p

Oh on top of that, for table 45, the slave frequency supposed to be 15MHz with the quote reference attached as well to the last post.... lol....., we're doing 26?27?30?? what?

oops sorry im on the K64 sheet, i got both documents open (sorry T3.5 users!) :p

EDIT, The K66 manual states SAME THING

Table 50, Page 63, "Table 50. Slave mode DSPI timing (full voltage range)" States that over a full voltage range the slave bus should be ran at 7.5MHz! wow :p

The datasheet doesnt mention anything higher than 15MHz for slave mode, unless in master mode --> 30MHz is capable...... this includes both K64 & K66 documents
 
Last edited:
Hate to disappoint you but I am currently squeezing 11Mhz out of a 6Mhz bus with GPIO2 at 4Mhz and LCmode(10,10).

LCmode(0,10) - doesn't work at 11/4Mhz

LCmode(10,10) - no good at 11/11 or 11/8 but does work at 11/6. This is with 1sec slave transfers, 100ms LED togs/println and 10ms F&F. If will give 2ms a shot and see what happens......

Ok with 2ms F&Fs on SPI0 with above config:
Code:
35194.00, #, #, #, #, #, #, #, #, #,65057,15 [480 ,0
35204.00  35205.00  35206.00  35207.00  35208.00  35209.00  35210.00  35211.00  35212.00  35213.00  
35214.00, #, #, #, #, #, #, #, #, #,65058,15 [480 ,0
35224.00, #, #, #, #, #, #, #, #, #,65059,15 [480 ,0
35234.00, #, #, #, #, #, #, #, #, #,65060,15 [480 ,0
35244.00, #, #, #, #, #, #, #, #, #,65061,15 [480 ,0
35254.00, #, #, #, #, #, #, #, #, #,65062,15 [480 ,0
35264.00, #, #, #, #, #, #, #, #, #,65063,15 [480 ,0
35274.00, #, #, #, #, #, #, #, #, #,65064,15 [480 ,0
Hello World!
35284.00, #, #, #, #, #, #, #, #, #,65065,15 [480 ,0
35294.00, #, #, #, #, #, #, #, #, #,65066,15 [480 ,0
35304.00, #, #, #, #, #, #, #, #, #,65067,15 [480 ,0
35314.00, #, #, #, #, #, #, #, #, #,65068,15 [480 ,0
35324.00, #, #, #, #, #, #, #, #, #,65069,15 [480 ,0
35334.00, #, #, #, #, #, #, #, #, #,65070,15 [480 ,0
35344.00, #, #, #, #, #, #, #, #, #,65071,15 [480 ,0
35354.00, #, #, #, #, #, #, #, #, #,65072,15 [480 ,0
35364.00, #, #, #, #, #, #, #, #, #,65073,15 [480 ,0
35374.00, #, #, #, #, #, #, #, #, #,65074,15 [480 ,0
35384.00, #, #, #, #, #, #, #, #, #,65075,15 [480 ,0
35394.00, #, #, #, #, #, #, #, #, #,65076,15 [480 ,0
35404.00, #, #, #, #, #, #, #, #, #,65077,15 [480 ,0
35414.00, #, #, #, #, #, #, #, #, #,65078,15 [480 ,0
35424.00, #, #, #, #, #, #, #, #, #,65079,15 [480 ,0
35434.00, #, #, #, #, #, #, #, #, #,65080,15 [480 ,0
35444.00, #, #, #, #, #, #, #, #, #,65081,15 [480 ,0
35454.00  35455.00  35456.00  35457.00  35458.00  35459.00  35460.00  35461.00  35462.00  35463.00  
35464.00, #, #, #, #, #, #, #, #, #,65082,15 [480 ,0
35474.00, #, #, #, #, #, #, #, #, #,65083,15 [480 ,0
35484.00, #, #, #, #, #, #, #, #, #,65084,15 [480 ,0
35494.00, #, #, #, #, #, #, #, #, #,65085,15 [480 ,0
35504.00, #, #, #, #, #, #, #, #, #,65086,15 [480 ,0
35514.00, #, #, #, #, #, #, #, #, #,65087,15 [480 ,0
35524.00, #, #, #, #, #, #, #, #, #,65088,15 [480 ,0
35534.00, #, #, #, #, #, #, #, #, #,65089,15 [480 ,0
35544.00, #, #, #, #, #, #, #, #, #,65090,15 [480 ,0
35554.00, #, #, #, #, #, #, #, #, #,65091,15 [480 ,0
35564.00, #, #, #, #, #, #, #, #, #,65092,15 [480 ,0
35574.00, #, #, #, #, #, #, #, #, #,65093,15 [480 ,0
35584.00, #, #, #, #, #, #, #, #, #,65094,15 [480 ,0
35594.00, #, #, #, #, #, #, #, #, #,65095,15 [480 ,0
35604.00, #, #, #, #, #, #, #, #, #,65096,15 [480 ,0
35614.00, #, #, #, #, #, #, #, #, #,65097,15 [480 ,0
35624.00, #, #, #, #, #, #, #, #, #,65098,15 [480 ,0
35634.00, #, #, #, #, #, #, #, #, #,65099,15 [480 ,0
35644.00, #, #, #, #, #, #, #, #, #,65100,15 [480 ,0
35654.00, #, #, #, #, #, #, #, #, #,65101,15 [480 ,0
35664.00, #, #, #, #, #, #, #, #, #,65102,15 [480 ,0
35674.00, #, #, #, #, #, #, #, #, #,65103,15 [480 ,0
35684.00, #, #, #, #, #, #, #, #, #,65104,15 [480 ,0
35694.00, #, #, #, #, #, #, #, #, #,65105,15 [480 ,0
35704.00  35705.00  35706.00  35707.00  35708.00  35709.00  35710.00  35711.00  35712.00  35713.00  
35714.00, #, #, #, #, #, #, #, #, #,65106,15 [480 ,0
35724.00, #, #, #, #, #, #, #, #, #,65107,15 [480 ,0

Yes I am a glutton for punishment - think if I were going to push SPI0 I would stick with 10/4....
 
Your still pushing SPI0 or jumping the bandwagon to SPI1? :)

We're basically testing out unsupported capabilities of the chip at this point lol

Ahh okay your still on SPI0 pushing 11MHz ok, thought my code was broken but it's just abuse :D

If it runs on SPI1 the code is fine and only limited by the bus of SPI0, and other chip discrepancies we don't know about :)
 
Your still pushing SPI0 or jumping the bandwagon to SPI1?
Right now testing SPI0, you know me, how long did it take me to get a T3.6 up and running :) Not to fret - I am planning to switch to SPI1 tomorrow - my eyes are getting crossed right now. Then I will see what I can break there :)

EDIT:
but it's just abuse
Of course that why its always my fault.
:)
 
I say we all boycott SPI0, LC's fault :)

What did we learn today?
1) That we exceeded 15MHz slave support on 3.x series
2) SPI1 is faster than SPI0 on LC, and Mike broke the speed limits
3) It's Mike's fault I switched to SPI0, library would have been running 11MHz long ago if I didn't rewire the bus to match his :p

Mike, you seen the LC menu on startup? :)

EDIT, according to NXP datasheet, slave mode for 3.2 suppose to be 6.25MHz(limited voltage range) to 12.5MHz(limited voltage range) slave mode , Mike you more than doubled that at 27 :p --> 3.2 master mode says 25MHz

EDIT: Still scrolling strong :)
Code:
3366.00, #, #, #, #, #, #, #, #, #,4936401,9 [480 ,0
3376.00, #, #, #, #, #, #, #, #, #,4936402,9 [480 ,0
3386.00, #, #, #, #, #, #, #, #, #,4936403,9 [480 ,0
3396.00, #, #, #, #, #, #, #, #, #,4936404,9 [480 ,0
3406.00, #, #, #, #, #, #, #, #, #,4936405,9 [480 ,0
3416.00, #, #, #, #, #, #, #, #, #,4936406,9 [480 ,0
3426.00, #, #, #, #, #, #, #, #, #,4936407,9 [480 ,0
3436.00, #, #, #, #, #, #, #, #, #,4936408,9 [480 ,0
3446.00, #, #, #, #, #, #, #, #, #,4936409,9 [480 ,0
3456.00, #, #, #, #, #, #, #, #, #,4936410,9 [480 ,0
3466.00, #, #, #, #, #, #, #, #, #,4936411,9 [480 ,0
3476.00, #, #, #, #, #, #, #, #, #,4936412,9 [480 ,0
3486.00, #, #, #, #, #, #, #, #, #,4936413,9 [480 ,0
3496.00, #, #, #, #, #, #, #, #, #,4936414,9 [480 ,0
3506.00, #, #, #, #, #, #, #, #, #,4936415,9 [480 ,0
 
Last edited:
Ok last post for the night. Switched to SPI1 and best I could do was
SPI = 11Mhz
GPIO2 = 8Mhz
LED Tog = 100ms
USBprint = 100ms
F&F = 2ms
LCmode = 10,10 (0,10 did not work)
Slave Transfers = 1sec


at GPIO2 = 10 LC keeps resetting.
 
lcmode 0,10, all inc gpio2 is 11mhz (here)

see:
Code:
#include <SPI.h>
#include <SPI_MSTransfer.h>
#include "A_ConfigDefines.h"

//#define SPI_SPEED 30500
#define SPI_SPEED [COLOR="#FF0000"][B]11000000[/B][/COLOR]
#define OT_CALC   100*(30000000/SPI_SPEED)

SPI_MSTransfer teensy_gpio = SPI_MSTransfer("Serial", SPI_MST_CS, &SPI_MST_BUS, SPI_SPEED ); // bad with default timeouts
SPI_MSTransfer teensy_gpio2 = SPI_MSTransfer("Serial", SPI_MST_CS, &SPI_MST_BUS, SPI_SPEED );
SPI_MSTransfer teensy_gpio3 = SPI_MSTransfer("Serial", SPI_MST_CS, &SPI_MST_BUS, SPI_SPEED );

void yield() {}

void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 2000 ) {}
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  teensy_gpio.debug(Serial);
  uint8_t moo = [COLOR="#FF0000"]10[/COLOR];
  teensy_gpio.LCmode(0, moo);
  teensy_gpio2.LCmode(0, moo);
  teensy_gpio3.LCmode(0, moo);
  //    teensy_gpio.LCmode(5,5);
  //    teensy_gpio2.LCmode(5,5);

  teensy_gpio2.onTransfer(myCallback);


#ifdef SPI_MST_SCK
  SPI_MST_BUS.setSCK( SPI_MST_SCK );
#endif
  SPI_MST_BUS.begin();
}

uint32_t OverTime = 0;
void loop() {
  static uint32_t _timer = millis();
  teensy_gpio2.events();

  static uint32_t _timer1 = millis();
  if ( millis() - _timer1 > 1000 ) {
    _timer1 = millis();
//  teensy_gpio2.events();

//  teensy_gpio3.println("Hello World!");
    teensy_gpio3.pinToggle(LED_BUILTIN); Serial.print("^LT"); delay(1);
  }


  if ( millis() - _timer >=[COLOR="#FF0000"] 2)[/COLOR] {
    _timer = millis();
    //_timer1 = micros();
    uint32_t _time = micros();

    uint16_t *buf;
    double MST_PrintVals[10];
    buf = (uint16_t *)MST_PrintVals;
    int ii = 0;
    static uint16_t __count = 0;
    static uint16_t __countB = 0;
    for ( uint32_t i = 0; i < sizeof(MST_PrintVals) / sizeof( MST_PrintVals[0]  ); i++ ) MST_PrintVals[i] = __count++;

    Serial.print("F&F (OT=");
    Serial.print( OverTime );
    Serial.print(")");

    Serial.print(" OT_CALC==");
    Serial.print(OT_CALC);
    Serial.print("  micros() _time==");
    _time = micros() - _time;
    if ( _time > OT_CALC ) OverTime++;

    __countB++;
    if ( __countB % 25 )
      teensy_gpio.transfer16((uint16_t *)MST_PrintVals, sizeof(MST_PrintVals) / 2, 60, 1); // DEBUGHACK output
    else
      teensy_gpio.transfer16((uint16_t *)MST_PrintVals, sizeof(MST_PrintVals) / 2, 55, 1);
    Serial.println(_time);

  }

}

void myCallback(uint16_t *buffer, uint16_t length, AsyncMST info) {
  Serial.print("PacketID: "); Serial.println(info.packetID);
  Serial.print("Length: "); Serial.println(length);
  for ( uint16_t i = 0; i < length; i++ ) {
    Serial.print(buffer[i], HEX); Serial.print(" ");
  }
  Serial.println();
}

slava:
Code:
#include <SPI_MSTransfer_Slave.h>

void setup() {
  slave.begin(SPI1);
  slave.onTransfer(myCallback);
}

void loop() {
  static uint32_t _timer1 = millis();
  static uint32_t _timer2 = millis();
  if ( millis() - _timer2 > [COLOR="#FF0000"][B]500 )[/B][/COLOR] {
    _timer2 = millis();
    uint16_t buf[20];
    for ( uint16_t i = 0; i < 20; i++ ) buf[i] = random(0x1000, 0xFFFF);
    slave.transfer16(buf, 20, random(1, 65534));
  }
  slave.events();
}

static uint16_t last_packetID = 0;
elapsedMillis TogClk;
uint32_t TogCnt = 0;
uint32_t FaFCnt = 0;
void myCallback(uint16_t *buffer, uint16_t length, AsyncMST info) {
  if ( 55 == info.packetID ) {
    if ( 40 != length ) {
      Serial.print("Bad Length: "); Serial.println(length); // If this shows then the SPI Passed array size is nor wrong
    }
    else if ( 0 != info.error ) {
      Serial.println("\nBad CRC: ");
    }
    else {
      double* MST_PrintVals;
      MST_PrintVals = (double *)buffer;

      for (int i = 0; i < 10; i++) {
        Serial.print(MST_PrintVals[i]); Serial.print("  ");
      }
      Serial.println();
    }
  }

  else if ( 60 == info.packetID ) {
    if ( 40 != length ) {
      Serial.print("Bad Length: "); Serial.println(length); // If this shows then the SPI Passed array size is nor wrong
    }
    else if ( 0 != info.error ) {
      Serial.println("\nBad CRC: ");
    }
    else {
      double* MST_PrintVals;
      MST_PrintVals = (double *)buffer;

      // This provides a terse output with error checked based on MASTER output to the 12 DOUBLE value Array
      {
        static uint16_t TogLast = 0;
        static uint16_t TogHz = 0;
        static uint16_t FaFHz = 0;
        static double LastVal = 100000;
        static uint32_t ChkErr = 0;
        static uint32_t CBcount = 0;
        //if ( digitalReadFast( LED_BUILTIN) != TogLast ) {
        //  TogLast = !TogLast;
        //  TogCnt++;
        //}
        if ( TogClk >= 1000 ) {
          TogClk -= 1000;
          TogHz = TogCnt;
          TogCnt = 0;
          FaFHz = FaFCnt;
          FaFCnt = 0;
        }
        if ( last_packetID != info.packetID ) {
          LastVal += 10;
          if ( LastVal > 65536 && LastVal < 100000 ) LastVal -= 65536;
        }
        elapsedMillis LastCB;
        double DiffMiss = 0;
        uint32_t ErrSeen = 0;
        CBcount++;
        FaFCnt++;
        for ( uint32_t ii = 0; ii < 10; ii++ ) {
          LastVal++;
          if ( 65536 == LastVal ) LastVal = 0;
          if ( LastCB > 10 || 100001 == LastVal || 100013 == LastVal ) LastVal = MST_PrintVals[ii];
          if ( LastVal != MST_PrintVals[ii] ) {
            DiffMiss = LastVal - MST_PrintVals[ii];
            ChkErr++;
            Serial.print("\nBad LASTVAL TEST INCREMENT <<<<<<<<<<<<<<<<<<<< DIFF OF> ");
            Serial.println( DiffMiss );
            LastVal = MST_PrintVals[ii];
            ErrSeen++;
          }
          if ( 0 != ErrSeen || 1 > ii ) {
            Serial.print( MST_PrintVals[ii] );
            Serial.print(",");
          }
          else {
            Serial.print(" #,");
          }
        }
        Serial.print( CBcount );
        Serial.print(",");
        Serial.print( ChkErr );
        Serial.print(" [");
        Serial.print( FaFHz );
        Serial.print(" ,");
        Serial.print( TogHz );
        Serial.println();
        LastCB = 0;
      }

    }
  }
  else {
    Serial.print("PacketID: ");
    Serial.println(info.packetID);
  }
  last_packetID = info.packetID;
}
slave still rolling:
Code:
51882.00, #, #, #, #, #, #, #, #, #,6539075,9 [480 ,0
51892.00, #, #, #, #, #, #, #, #, #,6539076,9 [480 ,0
51902.00, #, #, #, #, #, #, #, #, #,6539077,9 [480 ,0
51912.00, #, #, #, #, #, #, #, #, #,6539078,9 [480 ,0
51922.00, #, #, #, #, #, #, #, #, #,6539079,9 [480 ,0
51932.00, #, #, #, #, #, #, #, #, #,6539080,9 [480 ,0
51942.00, #, #, #, #, #, #, #, #, #,6539081,9 [480 ,0
51952.00  51953.00  51954.00  51955.00  51956.00  51957.00  51958.00  51959.00  51960.00  51961.00  
51962.00, #, #, #, #, #, #, #, #, #,6539082,9 [480 ,0
51972.00, #, #, #, #, #, #, #, #, #,6539083,9 [480 ,0
51982.00, #, #, #, #, #, #, #, #, #,6539084,9 [480 ,0
51992.00, #, #, #, #, #, #, #, #, #,6539085,9 [480 ,0
52002.00, #, #, #, #, #, #, #, #, #,6539086,9 [480 ,0
52012.00, #, #, #, #, #, #, #, #, #,6539087,9 [480 ,0
52022.00, #, #, #, #, #, #, #, #, #,6539088,9 [480 ,0
52032.00, #, #, #, #, #, #, #, #, #,6539089,9 [480 ,0
52042.00, #, #, #, #, #, #, #, #, #,6539090,9 [480 ,0
52052.00, #, #, #, #, #, #, #, #, #,6539091,9 [480 ,0
52062.00, #, #, #, #, #, #, #, #, #,6539092,9 [480 ,0
52072.00, #, #, #, #, #, #, #, #, #,6539093,9 [480 ,0
52082.00, #, #, #, #, #, #, #, #, #,6539094,9 [480 ,0
52092.00, #, #, #, #, #, #, #, #, #,6539095,9 [480 ,0
52102.00, #, #, #, #, #, #, #, #, #,6539096,9 [480 ,0
52112.00, #, #, #, #, #, #, #, #, #,6539097,9 [480 ,0
52122.00, #, #, #, #, #, #, #, #, #,6539098,9 [480 ,0
52132.00, #, #, #, #, #, #, #, #, #,6539099,9 [480 ,0
52142.00, #, #, #, #, #, #, #, #, #,6539100,9 [480 ,0
52152.00, #, #, #, #, #, #, #, #, #,6539101,9 [480 ,0
52162.00, #, #, #, #, #, #, #, #, #,6539102,9 [480 ,0
52172.00, #, #, #, #, #, #, #, #, #,6539103,9 [480 ,0
52182.00, #, #, #, #, #, #, #, #, #,6539104,9 [480 ,0
52192.00, #, #, #, #, #, #, #, #, #,6539105,9 [480 ,0
 
11MHZ works here with your settings

SPI = 11Mhz YUP
GPIO2 = 8Mhz (mine 11)
LED Tog = 100ms (MATCHED)
USBprint = 100ms (MATCHED)
F&F = 2ms (SAME)
LCmode = 10,10 (0,10 did not work) (0,10 here)
Slave Transfers = 1sec (500ms)

Rolling like crazy, works fine :)

EDIT, changed 11MHz to 10MHz, still running fine here

Make sure your using both the new master and slave sketches when uploading to master and slave from 11MHzLC.zip #1776 post

Its a good idea we opened up alt SPI ports, otherwise we’d be having a slow one on LC :p
 
Reloaded master and slave libraries, reflashed the sketches. Made my settings match yours and no go - would hang and then eventually get a few bad crc's and bad vals. If I change lc_mode to 10,10 it would work but the lc would keep reseting. I know I got the new slave loaded because I see the new startup message.

EDIT: Tony, can you repost the master just in case. Something strange is going on and just want to make sure. As a suggestion can you put something in the master as a startup message - or pragma with version number?
 
Last edited:
Good morning :)
Code:
5152.00, #, #, #, #, #, #, #, #, #,16937931,2 [475 ,0
5162.00, #, #, #, #, #, #, #, #, #,16937932,2 [475 ,0
5172.00, #, #, #, #, #, #, #, #, #,16937933,2 [475 ,0
5182.00, #, #, #, #, #, #, #, #, #,16937934,2 [475 ,0
5192.00, #, #, #, #, #, #, #, #, #,16937935,2 [475 ,0
5202.00  5203.00  5204.00  5205.00  5206.00  5207.00  5208.00  5209.00  5210.00  5211.00  
5212.00, #, #, #, #, #, #, #, #, #,16937936,2 [475 ,0
5222.00, #, #, #, #, #, #, #, #, #,16937937,2 [475 ,0
5232.00, #, #, #, #, #, #, #, #, #,16937938,2 [475 ,0
5242.00, #, #, #, #, #, #, #, #, #,16937939,2 [475 ,0
5252.00, #, #, #, #, #, #, #, #, #,16937940,2 [475 ,0
5262.00, #, #, #, #, #, #, #, #, #,16937941,2 [475 ,0
5272.00, #, #, #, #, #, #, #, #, #,16937942,2 [475 ,0
5282.00, #, #, #, #, #, #, #, #, #,16937943,2 [475 ,0
5292.00, #, #, #, #, #, #, #, #, #,16937944,2 [475 ,0
5302.00, #, #, #, #, #, #, #, #, #,16937945,2 [475 ,0
5312.00, #, #, #, #, #, #, #, #, #,16937946,2 [475 ,0
5322.00, #, #, #, #, #, #, #, #, #,16937947,2 [475 ,0
5332.00, #, #, #, #, #, #, #, #, #,16937948,2 [475 ,0
 
Overnight master:
Code:
#include <SPI.h>
#include <SPI_MSTransfer.h>
#include "A_ConfigDefines.h"

//#define SPI_SPEED 30500
#define SPI_SPEED 11000000
#define OT_CALC   100*(30000000/SPI_SPEED)

SPI_MSTransfer teensy_gpio = SPI_MSTransfer("Serial", SPI_MST_CS, &SPI_MST_BUS, SPI_SPEED ); // bad with default timeouts
SPI_MSTransfer teensy_gpio2 = SPI_MSTransfer("Serial", SPI_MST_CS, &SPI_MST_BUS, SPI_SPEED );
SPI_MSTransfer teensy_gpio3 = SPI_MSTransfer("Serial", SPI_MST_CS, &SPI_MST_BUS, SPI_SPEED );

void yield() {}

void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 2000 ) {}
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  teensy_gpio.debug(Serial);
  uint8_t moo = 10;
  teensy_gpio.LCmode(0, moo);
  teensy_gpio2.LCmode(0, moo);
  teensy_gpio3.LCmode(0, moo);
  //    teensy_gpio.LCmode(5,5);
  //    teensy_gpio2.LCmode(5,5);

  teensy_gpio2.onTransfer(myCallback);


#ifdef SPI_MST_SCK
  SPI_MST_BUS.setSCK( SPI_MST_SCK );
#endif
  SPI_MST_BUS.begin();
}

uint32_t OverTime = 0;
void loop() {
  static uint32_t _timer = millis();
  teensy_gpio2.events();

  static uint32_t _timer1 = millis();
  if ( millis() - _timer1 > 100 ) {
    _timer1 = millis();
//  teensy_gpio2.events();

//  teensy_gpio3.println("Hello World!");
    teensy_gpio3.pinToggle(LED_BUILTIN); Serial.print("^LT"); delay(1);
  }


  if ( millis() - _timer >= 2) {
    _timer = millis();
    //_timer1 = micros();
    uint32_t _time = micros();

    uint16_t *buf;
    double MST_PrintVals[10];
    buf = (uint16_t *)MST_PrintVals;
    int ii = 0;
    static uint16_t __count = 0;
    static uint16_t __countB = 0;
    for ( uint32_t i = 0; i < sizeof(MST_PrintVals) / sizeof( MST_PrintVals[0]  ); i++ ) MST_PrintVals[i] = __count++;

    Serial.print("F&F (OT=");
    Serial.print( OverTime );
    Serial.print(")");

    Serial.print(" OT_CALC==");
    Serial.print(OT_CALC);
    Serial.print("  micros() _time==");
    _time = micros() - _time;
    if ( _time > OT_CALC ) OverTime++;

    __countB++;
    if ( __countB % 25 )
      teensy_gpio.transfer16((uint16_t *)MST_PrintVals, sizeof(MST_PrintVals) / 2, 60, 1); // DEBUGHACK output
    else
      teensy_gpio.transfer16((uint16_t *)MST_PrintVals, sizeof(MST_PrintVals) / 2, 55, 1);
    Serial.println(_time);

  }

}

void myCallback(uint16_t *buffer, uint16_t length, AsyncMST info) {
  Serial.print("PacketID: "); Serial.println(info.packetID);
  Serial.print("Length: "); Serial.println(length);
  for ( uint16_t i = 0; i < length; i++ ) {
    Serial.print(buffer[i], HEX); Serial.print(" ");
  }
  Serial.println();
}

Overnight Slave:
Code:
#include <SPI_MSTransfer_Slave.h>

void setup() {
  slave.begin(SPI1);
  slave.onTransfer(myCallback);
}

void loop() {
  static uint32_t _timer1 = millis();
  static uint32_t _timer2 = millis();
  if ( millis() - _timer2 > 500 ) {
    _timer2 = millis();
    uint16_t buf[20];
    for ( uint16_t i = 0; i < 20; i++ ) buf[i] = random(0x1000, 0xFFFF);
    slave.transfer16(buf, 20, random(1, 65534));
  }
  slave.events();
}

static uint16_t last_packetID = 0;
elapsedMillis TogClk;
uint32_t TogCnt = 0;
uint32_t FaFCnt = 0;
void myCallback(uint16_t *buffer, uint16_t length, AsyncMST info) {
  if ( 55 == info.packetID ) {
    if ( 40 != length ) {
      Serial.print("Bad Length: "); Serial.println(length); // If this shows then the SPI Passed array size is nor wrong
    }
    else if ( 0 != info.error ) {
      Serial.println("\nBad CRC: ");
    }
    else {
      double* MST_PrintVals;
      MST_PrintVals = (double *)buffer;

      for (int i = 0; i < 10; i++) {
        Serial.print(MST_PrintVals[i]); Serial.print("  ");
      }
      Serial.println();
    }
  }

  else if ( 60 == info.packetID ) {
    if ( 40 != length ) {
      Serial.print("Bad Length: "); Serial.println(length); // If this shows then the SPI Passed array size is nor wrong
    }
    else if ( 0 != info.error ) {
      Serial.println("\nBad CRC: ");
    }
    else {
      double* MST_PrintVals;
      MST_PrintVals = (double *)buffer;

      // This provides a terse output with error checked based on MASTER output to the 12 DOUBLE value Array
      {
        static uint16_t TogLast = 0;
        static uint16_t TogHz = 0;
        static uint16_t FaFHz = 0;
        static double LastVal = 100000;
        static uint32_t ChkErr = 0;
        static uint32_t CBcount = 0;
        //if ( digitalReadFast( LED_BUILTIN) != TogLast ) {
        //  TogLast = !TogLast;
        //  TogCnt++;
        //}
        if ( TogClk >= 1000 ) {
          TogClk -= 1000;
          TogHz = TogCnt;
          TogCnt = 0;
          FaFHz = FaFCnt;
          FaFCnt = 0;
        }
        if ( last_packetID != info.packetID ) {
          LastVal += 10;
          if ( LastVal > 65536 && LastVal < 100000 ) LastVal -= 65536;
        }
        elapsedMillis LastCB;
        double DiffMiss = 0;
        uint32_t ErrSeen = 0;
        CBcount++;
        FaFCnt++;
        for ( uint32_t ii = 0; ii < 10; ii++ ) {
          LastVal++;
          if ( 65536 == LastVal ) LastVal = 0;
          if ( LastCB > 10 || 100001 == LastVal || 100013 == LastVal ) LastVal = MST_PrintVals[ii];
          if ( LastVal != MST_PrintVals[ii] ) {
            DiffMiss = LastVal - MST_PrintVals[ii];
            ChkErr++;
            Serial.print("\nBad LASTVAL TEST INCREMENT <<<<<<<<<<<<<<<<<<<< DIFF OF> ");
            Serial.println( DiffMiss );
            LastVal = MST_PrintVals[ii];
            ErrSeen++;
          }
          if ( 0 != ErrSeen || 1 > ii ) {
            Serial.print( MST_PrintVals[ii] );
            Serial.print(",");
          }
          else {
            Serial.print(" #,");
          }
        }
        Serial.print( CBcount );
        Serial.print(",");
        Serial.print( ChkErr );
        Serial.print(" [");
        Serial.print( FaFHz );
        Serial.print(" ,");
        Serial.print( TogHz );
        Serial.println();
        LastCB = 0;
      }

    }
  }
  else {
    Serial.print("PacketID: ");
    Serial.println(info.packetID);
  }
  last_packetID = info.packetID;
}

LED still blinking happily, scrolling is smooth :)
 
Morning Tony. Still can't get SPI1 working to your specs. EDIT: Have no idea why - reloaded everything and copied the files again :( Its like SPI0 and SPI1 are crossed.
 
Hmm, yesturday I reflashed master no issue, now i reflashed slave with 11MHz file and the Serial output is not up to par, your right, wonder what i did...
only thing i did was update to beta5 last night hmm
brb

The console seems to be stuck, but led keeps blinking fine
 
Just tried 1.8.5 with beta2 and same thing so its not a IDE issue. Do you think theres a variation in chip to chip? Will have to eventually solder up another LC just to test it.
 
Back
Top