K66 Beta Test

Status
Not open for further replies.
No it is the correct order. If I request 2.8M rate, and I am using a 60M bus, it would require a divider of 21.43 (as an integer calc it is a divide ratio of 21). However there is no divide ratio of 21, there is only 20 or 22. The algorithm errs on the lower ratio (higher freq) side as the throughput rate is severely limited at the high end (this could be done either way, either rounding up or down). So in this case it would choose 20, yielding a 3M setting. So requesting 2.8M in this case will yield a 3M rate.

That's all theoretical rates. On a logic analyzer the rates run a little slow IIRC due to overhead. And in a throughput sense it is much lower, especially at the high end. At high freq the throughput becomes dominated by the "gaps" between bytes, which are caused by peripheral and ISR processing latency (I2C traffic does not have an unbroken clock, there is usually a turnaround delay after the ACK cycle) . I don't have any logic analyzer plots yet to pair up against the settings.

From that description, I would say that the code is wrong and should be corrected/changed.
setClock() should set the raw i2c SCL clock rate on the bus.
All the specs in datasheeets for i2c bit rates are based on a maximum SCL clock bit rate not a desired/theoretical/measured actual data rate of user data transfers.
The data rate that the users application code "sees" is not what what is most important as there are several sources of overhead in i2c, some of which cannot be anticipated.
i..e start/stop signals, library overhead, and the slave can even do clock stretching to literally stop the clock or slow it down to any rate it wants.
For example, when an i2c slave device says it supports a 400000 clock, that means it can support a SCL clock rate of up to 400000, and so the Wire s/w needs to guarantee that the SCL clock rate does not ever exceed the requested SCL bit rate.
i.e. if the users application asks for a SCL bit rate of 400000, the master should never exceed 400000 hz on the SCL clock.
From the description of the way the code is currently working, a requested SCL bit rate can be exceeded, so the slave can end up being pushed beyond its specs, particularly when the sketch is asking to set the SCL clock rate to the slaves maximum clock rate and the s/w rounds to using the next higher clock available.
While it is likely that many slaves can be clocked at a rate beyond their specs, I think it is not a good practice to knowingly and intentionally do so.

Yeah, not being able to support a requested value does suck; however, whenever doing things like delays or clocks, the code should always error on the conservative side to ensure functional limits are not ever exceeded.
And that means when faced with having to use a something that is different than what was asked for, the code must always select using the more conservative choice.
So for delays and clock rates, it means using longer delays, or slower clocks.

It can't go the other way around as then the application never knows what to ask for that guarantees that the result is not exceeding a critical maximum rate or minimum delay.

My openGLCD library has to deal with same kind of issue as well.
There are places where small delays are needed to meet certain timing requirements.
There are certain environments, where the code may need a 140ns delay, but it isn't possible, so the code is forced to use delays that are longer, in some cases MUCH longer like 1us or even longer.
The longer needed delays means that performance takes a hit,
but that is the way it needs to work, so that the code always "just works" with no surprises or flakiness in any environment.
If doing it the other way, there are environments, where things stop working correctly, or get very flaky.

As a general rule,
I think code should first "just work" in all environments, then after that it is achieved, it can choose to optimize performance when possible.

So my very strong suggestion, is to make sure that the Wire code always selects a SCL clock rate that is the highest rate possible that never exceeds the requested rate.
Anything else, will eventually come back around with subtle issues/errors that can potentially be difficult to track down as they may only show up in very specific environments.

BTW, a logic analyzer is the only way to verify this kind of low level timing since it is the low level bit clock timing that matters.
For this measurement, a slave is not needed - and in fact should not be used, to ensure that no slave clock stretching is done during the measurements.

--- bill
 
Last edited:
I've checked and counted and reversed the wires at 3&4. As noted - I can pull the display off Wire1 and get a timeout - I still hang with Wire2?

I put this ONCE item in to stop the repeated calls during wait from spewing until the completion. I just edited that to confirm it just returns 1 forever on Wire2.

I think I may have seen this as well with Wire2, with BNO... sensor. It worked on Wire2, but I think it may not have worked if it was actually plugged in, when I started the test... Will try again with your updated library.
 
KurtE If you want to try with the scanner.ino I dropped - I hardcoded a single target on line 63.
Here is the Debug Spew version { View attachment i2c_t3.cpp } of i2c_t3.cpp I used. Interesting to see if you get the same.

Clarification - using my Scanner.ino:: without a device on I2C1/Wire1 it does stop at the same point - ONLY when there is no device on PINS_3_4.
However > When the SSD1306 is sitting on I2C_PINS_3_4 and no device is on Wire1 I2C_PINS_37_38 it returns after a timeout
Same Applies > when the SSD1306 is on I2C0 - the I2C1 device times out

There seems to be some bus crosstalk in software?

In doing that test - I just started smelling my 2nd SSD1306 and it was warm to touch.
I returned that device to Wire1 and Scanner works on it as does the AdaFruit sketch I'm using.
 
Right now, doing simple test with BNO055_Test program currently setup on pins 3,4 and works as far as I can tell. Note: this is the only two IO pins I have connected to anything. Will try to see if your stuff works later today or tomorrow.

Right now having fun with RC receiver...
 
Guys,
i2c debugging typically involves looking at the i2c signals with a logic analyzer, to look for signal issues and see the state of signals when the s/w starts to have issues.
With an analyzer tracing on all the busses as once, you could see things were happing on the wrong bus, or if SCK was out of spec, or NAK signals were misbehaving or missing.

It is trivial to do, and could quickly answer many questions.
When I'm debugging at this level, I also typically use a few i/o pins to be able to insert timing marks into the trace/capture.
You can compress lots of information into just a few signal lines by using highs/lows, or toggles.
Often it is the only way to fully debug stuff like this as trying to use output messages can change the timing so much that is affects the issue.


--- bill
 
Yep totally agree - I think you may notice that a good percentage of my messages talk about using Logic Analyzer!

But right now was just doing a verification that I2C works at all on the buses. Was thinking of trying out more on I2C soon. I don't think I still have many I2C devices sitting around. Although was thinking of trying out some Daventech sensors like SRF08 or SRF10 or CMP03, but I am guessing that they are 5v devices. Not sure if any of my level shifters are good for I2C...
 
Was playing with a hacked up version of PulsePositionInput, that instead of of handling the PPM modulation on the pin it handled a receiving simple RC signals, so you can plug in channels from your RC receiver, and decode it. I posted a zip file with sketch which includes the hacked up library in another thread:
https://forum.pjrc.com/threads/24627-Read-RC-Reciever-with-Teensy-3?p=108827&viewfull=1#post108827

So I plugged in the 8 channels into pin (5, 6, 9 , 10 , 20-23), and it appears like it is also working on beta board... (Have not tried on LC)...
Now just need to figure out how to configure the Turnigy 9x, to configure more stuff on more channels. Mainly just getting 4 channels for the two joysticks.

Sample output:
Code:
1: 5=1477 6=1478 9=1070 10=1483 20=1484 21=1483 22=1483 23=391 
1: 5=1477 6=1479 9=1071 10=1484 20=392 21=2576 22=1484 23=391 
1: 5=385 6=1478 9=1070 10=1483 20=390 21=2575 22=1484 23=1483 
1: 5=384 6=2571 9=1071 10=1485 20=391 21=2576 22=1484 23=1484 
1: 5=1477 6=2570 9=1070 10=1484 20=1484 21=1484 22=1484 23=1483 
1: 5=1480 6=2570 9=1070 10=1483 20=1483 21=1484 22=1484 23=1484
Assuming I continue on merging code in, will want to again see about values returned here.
 
Get the board today - testing some FFT

Some tests for a 32 point complex FFT, the code is very standard (got it from someone implementing a book algorithm having issues with the details) I can supply it if anybody wants it.
We can see that for double at 96MHz the K66 is 2.5 times faster, probably due to better cache and prefetch handling.
For float data the hardware floating point really makes a difference.
Raising the clock frequency for the K66 scales the results as could be expected.
All of this ran without any issues or needing any fixes so it feels real stable.

BoardClock (MHz)float (us)double (us)
Teensy 3.09617902690
Teensy 3.59668953
Teensy 3.519240479
Teensy 3.524033387
 
bill/KurtE - I haven't got that kind of hardware (or background) - just tried to setup a simple case to show what I can see. If it makes sense or can repro for somebody then I've done well - if not then I have something messed up on my end. Based on KurtE's function initial test (not yet with scanner?) I just tested I2C2 with I2C0 wired to my other device - I2C2 device went most warm again (under 120° as I can touch it) - unplugged it before I got thermometer after smelling it.

I'll get another I2C device setup to test with in case it is just some vagary in the SSD1306 that otherwise works. I was hoping I2C SSSD1306 was a common device nox771 may have. The onehorse I2C Bubble display is here but needs wires - his sample already uses Wire1.
BTW: even with the debug spew (11 lines per transaction) the scanner and Adafruit display work on Wire1 and just tested on 'Wire'.

For my K66 testing I took an adafruit Perma-Proto 'breadboard' and soldered pins and parallel rows of headers. This is the setup I used to chain Serial 5>4>3>2>1>USB - and there are 4 jumper wires on those serial pins that don't affect Wire or Wire1. To test I did pull that board and wire 3.3V/GND/3/4 direct to K66 and saw the same behavior.
 
Theres a bit of debug output, but it should be fairly clean

/Magnus


Code:
#include <math.h>
#define FFTSIZE 32

void fft(float * Rex, float * Imx) {
//Do FFT on test data and save as Rex[] and Imx[] (Smith Table 12.4)
unsigned aL;
unsigned aM =  unsigned(log(FFTSIZE) / log(2)); // = 10
unsigned aK = 0;
float TR, TI;
unsigned myI;
unsigned aJ = (FFTSIZE/2);
unsigned int i;

//1******************* * **
  for(i = 1; i <= (FFTSIZE-2); i++) {
    if( i < aJ) {
      TR = Rex[aJ];
      TI = Imx[aJ];
      Rex[aJ] = Rex[i];
      Imx[aJ] = Imx[i];
      Rex[i] = TR;
      Imx[i] = TI;
    }
    aK = FFTSIZE/2;
    while(aK <= aJ) {
      aJ = aJ - aK;
      aK = aK / 2;
    }
    aJ = aJ + aK;
  }
  //2*********************
  for (aL = 1; aL <= aM; aL++) // aL should go from 1 to 10 for 1024 file
  {
    //Serial.println(aL, DEC);
    unsigned Le = (1<<aL); // i.e. 2,4,8,...512
    unsigned Le2 = Le/2; // i.e. 1,2,4...256
    float Ur = 1; 
    float Ui = 0; 
    float Sr = cosf(M_PI/Le2);
    float Si = -sinf(M_PI/Le2); // note negative
    unsigned JM1 = 1;
    //3********************** 
    
  //for (int i=0;i<FFTSIZE;i++) {Serial.print(Rex[i]); Serial.print("+i"); Serial.println(Imx[i]);}
  //Serial.println();
  
    for( (JM1 = 0); JM1 < Le2; JM1++)
    {
      //4**********************
      for ((myI = JM1); (myI <= FFTSIZE-1); myI=(myI+Le))
      {
        unsigned myIp = myI + Le2;
        TR = Rex[myIp] * Ur - Imx[myIp] * Ui;
        TI = Rex[myIp] * Ui + Imx[myIp] * Ur;
        Rex[myIp] = Rex[myI] - TR;
        Imx[myIp] = Imx[myI] - TI;
        Rex[myI] = Rex[myI] + TR;
        Imx[myI] = Imx[myI] + TI;
      }
      //4********************** 
      TR = Ur;
      Ur = TR * Sr - Ui * Si;
      Ui = TR * Si + Ui * Sr;
    }
    //3**********************
  }
  //2 ********************
  //Serial.println("Finished first FFT ");  
}


void setup() {
  // put your setup code here, to run once:

}

float Rex[FFTSIZE];
float Imx[FFTSIZE];

elapsedMicros fftTime;

void loop() {
  // put your main code here, to run repeatedly: 
  for (int i=0;i<FFTSIZE;i++) {Rex[i]=cos((2*5*M_PI*i)/FFTSIZE);Imx[i]=0; /*sin((2*5*M_PI*i)/FFTSIZE);*/};
  for (int i=0;i<FFTSIZE;i++) {Serial.print(Rex[i]); Serial.print("+i"); Serial.println(Imx[i]);}
  Serial.println();
  fftTime = 0;
  fft((float *) Rex, (float *) Imx);
  Serial.println(fftTime);
  for (int i=0;i<FFTSIZE;i++) {Serial.print(Rex[i]); Serial.print("+i"); Serial.println(Imx[i]);}
  Serial.println();
  Serial.println();

  delay(5000);
}
 
@WMXZ: Is the SD-Code working or are there still problems ?

As far as I can tell, the actual GitHub version is running and I have no pending issues.
It uses dma, but all call are waiting for dma interrupt (similar to your sram code)

give it a try (I can not work on it except porting to spi, as I have no working K66 anymore)
 
bill/KurtE - I haven't got that kind of hardware (or background)
You can buy a USB logic analyzer starting at under $10 USD that can easily handle multiple i2c buses.
And then use some free open source s/w (sigrok) on it that decodes all the signals, so it isn't a big investment in terms of $
You really need test tools like this to play at this level.

BTW: even with the debug spew (11 lines per transaction) the scanner and Adafruit display work on Wire1 and just tested on 'Wire'.
But without looking at the actual i2c bus signals on an analyzer and/or scope, all you can say is that it appears to work not that it really does work.
(there is a difference)

@KurtE,
you may want to try a PCF8574 (not the PCF8574T), but the older PCF8574. The ones I have do some slight clock stretching so the net data transfer rate is slightly slower.
The point being that clock stretching is excersizing some additional paths through the parts i2c h/w.
It would also be useful to test with various pullup values to verify with some slower slew rates - like maybe with a 10k.
I currently don't have any i2c level shifters - or I'd do a quick test - I'm getting ready to order some but it will be a while before they show up.


--- bill
 
Last edited:
Ok, i'll play a bit with it.
A first test looks good :) - and runs fine @ 240MHz.

There are a lot of warnings because of #defines that are already in kinetis.h (and I found a bug in a #define in kinetis.h... will do a pullrequest.. )

Sorry about the warnings,
you may play with localKinetis.h that was necessary as TD 1.23b3 had not updated definitions.
what I did when compiling with latest core is to undefined multiple definitions.
maybe at same point one can a pull request to Paul's core. (Unfortunately my GitHub knowledge is limited, I never did a pull-request and had no need to do it, I only use sync, I guess it is easy, once I will have learned it)
 
@WMZ:

sometimes i get something like this:

Code:
6837638  101_RO~1.MP3  
9034631  102_BO~1.MP3
  7336363  103_ME~1.MP3
  6492484  104_DU~1.MP3
    41028  �T���.�E�
      320  �DU5C.$�
       74  HELLO10.TXT
     4096  TEST00.BIN
 805502976  �V����

Any idea ? It occurs @ 48MHZ Teensy , too...
 
Hi Guys,

As for $10 logic Analyzer, most of the ones I see up there on Ebay are counterfeit and many of them in the past either point the users to the Saleae website and/or they kept a copy from their website...

Personally I prefer legit ones and have two of them from https://www.saleae.com/ (An older 16, and their new 8).

However might at some point be fun to try out the Teensy Logic Analyzer: https://github.com/LAtimes2/TeensyLogicAnalyzer/

Bill, I actually will defer to nox771 on lots of the I2C testing as it is his library and as I mentioned I have not used I2C for very much. I have been playing with the BNO055, but have not done much with it yet, and when I use it in a robot, I may instead try to hook it up to main processor (either Odroid or UP board)... Note: It does do clock stretching, which is why it does not work on RPI in SPI mode.

Right now as per Paul's suggestion, trying to do random things, which is why I have been playing with the Pulse Position/FTM TImer code.

Nox771: But if there is something you would like tested out, let me know. Will look through my different Level converters. Right now using TXB0108 for the RC receiver signals.
 
Hi Guys,

As for $10 logic Analyzer ...

I concur. I considered a cloned unsupported ripoff - only up until I saw them for what they were. I have tried the LATimes LA - snapping samples and making sense of them would be an adventure. If I can get a simple repro nox771 will need to see it to fix it anyhow?
 
@WMZ:

sometimes i get something like this:

Code:
6837638  101_RO~1.MP3  
9034631  102_BO~1.MP3
  7336363  103_ME~1.MP3
  6492484  104_DU~1.MP3
    41028  �T���.�E�
      320  �DU5C.$�
       74  HELLO10.TXT
     4096  TEST00.BIN
 805502976  �V����

Any idea ? It occurs @ 48MHZ Teensy , too...

No I did not encounter this,
it seems to look like LFN.
Note: LFN is not enabled in config file, and may need some additional files.
will look tomorrow into ELM-Chan system to find out.
 
Hm, no, might not be important.. i managed to destroy the filesystem. did a re-format and copied the files back to the card (some gigabyte) - everything is ok now.
 
I wrote most of the following using the Adafruit driver code - then went to this modified version of SCANNER :: View attachment 7542

About your scanner code, this doesn't look right, your macro is probably evaluating to the first one in both cases:
Code:
#define [COLOR=#ff0000]Wire Wire1[/COLOR]
//#define [COLOR=#ff0000]Wire Wire2[/COLOR]

// Function prototypes
void print_scan_status(uint8_t target, bool all);
#define qBlink() (digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) ))

void setup()
{
    pinMode(LED_BUILTIN,OUTPUT);    // LED
    pinMode(12,INPUT_PULLUP);       // Control for Test1
    pinMode(11,INPUT_PULLUP);       // Control for Test2

    Serial.begin(115200);
  while (!Serial && (millis ()  <= 8000)) {
    delay(120); qBlink();
    delay(40);  qBlink();
  }
  Serial.println("Hello World");

    // Setup for Master mode, pins 18/19, external pullups, 400kHz
#if ([COLOR=#ff0000]WIRE == WIRE1[/COLOR])
    Wire.begin(I2C_MASTER, 0x00, I2C_PINS_37_38, I2C_PULLUP_EXT, I2C_RATE_400);
#else
    Wire.begin(I2C_MASTER, 0x00, I2C_PINS_3_4, I2C_PULLUP_EXT, I2C_RATE_400);
#endif
  Serial.println("Hello World wb");
}
Which if that's the case, is why Wire2 doesn't work. Can you just remove the #if and uncomment the appropriate begin() line and check?

Otherwise I'll need to get a diagram of your hookup to try and duplicate (just the basic hookup, what slave is on what bus, etc).
 
I see I was a bit sloppy with the case ... - but - looking at the debug spew you can see it does work. I should redo it and 3rd case for 'Wire'. WIRE1 and WIRE2 are not replaced - but WIRE will be to compare - and it is apparently case insensitive because I would have fixed it had I not seen this:

endTransmission currentPins I2C_PINS_3_4::0 // < this was the tested case and I print the enum value 0 for Wire2 pins
endTransmission bus::2

.versus.

endTransmission currentPins::not I2C_PINS_3_4 // < This is any other case, and these cases work
endTransmission bus::1

... busy day - will get another device powered up in a few hours

This code started in endTransmission
Code:
#define tprint(a, b) { Serial.print(a); Serial.println(b);}
uint8_t i2c_t3::endTransmission(struct i2cStruct* i2c, uint8_t bus, i2c_stop sendStop, uint32_t timeout)
{
	  if ( i2c->currentPins == I2C_PINS_3_4 ) {
		tprint("endTransmission currentPins I2C_PINS_3_4::", i2c->currentPins );
	  }
	else {
		tprint("endTransmission currentPins::", "not I2C_PINS_3_4" );
	}
	  
	  tprint("endTransmission bus::", bus );
 
Can you give a quick description/diagram of your setup. I can try to duplicate. I don't have the actual slaves you are testing, but I do have some Teensy devices I can run slave sketches on.

T3.5(Master)
-->Wire1 (0x3c slave)
-->Wire2 (??? slave)

Is this right?
 
Status
Not open for further replies.
Back
Top