Teensy 4 serial issues

donperryjm

Well-known member
Hello,

I've noticed something that I can't seem to find my way around.

On my teensy 3.5 and 3.2, I have code that is written for serial comm. between teensy and windows (bidrectional).
Those work fine, and I've been unable to cause a problem or throw and error. Flawless.

on the T4, however, serial comm is very buggy. Data is read ok most times but the real problem seems to be when T4 is receiving data from windows.

All devices are ran at 250000 baud rate.
Noting in the code changed.

Is there a usual suspect in the cause of this? What can be done?
 
Just to clarify that is USB Serial? Or is it UART Serial going through an adapter to get into the PC?

Does it repro with a minimal sketch that could be posted? Or is it in a complex sketch doing a lot of other things?

What does the data from the PC look like as far as byte transfer rate? Is it intermittent bytes or continuous bytes in bursts or ongoing?

What version of TeensyDuino is in use?
 
thanks. Teensy 1.56

USB port on the teensy via usb cable to PC
using Serial.Print/Readuntil

I can reproduce it with simple sketch. Give me some time...

... and I found the problem while doing so.
In my sketch i have before the serial code NoInterrupts() and then Interrupts() after the block of serial code.

I'm not sure what why it worked on the T3 but you know the saying "if it aint broken, don't fix it"
So those two lines removed and the T4 worked flawlessly so far.

Any ideas why the T3 would digest that code but not the T4?
 
Last edited:
Any ideas why the T3 would digest that code but not the T4?

I'm sure by now you know how this forum works. You're asking for blind guessing. Our general community expectation is that you'll show a complete program with these sorts of questions. Asking this without showing a program just wastes everyone's time, which isn't the way to make a good first impression (step #1 of asking people on the internet for tech help).

But for blind guesses...

1: Maybe your program somehow depends on the slower CPU speed or some other subtle aspect of the older boards.

2: Maybe you've found a previously unknown bug in the Teensy 4 USB serial receive code.

If you show a complete program and way to reproduce the problem, I'll give it a try. But if you don't get any useful answer here, know it was because you didn't show what you're really doing when the problem occurs.
 
Paul, defragster, thank you for responding. It's difficult to post code sometimes based on what exactly it is I'm working on and where the problem is. I understand it's easier to say "there, there is your problem" once you see the code.
The system I'm working on now is an automation based solution that involves communicating via windows app over serial to the teensy (bidirectional).



My question therefore was to find out if there is a difference between the implementation in Serial between T3 and T4 devices, or if something is happening in T4 at the HW level - i didn't find anything of such other than the speed of the T4. So i was checking to see If there was something I should be aware of.

I haven't been able to reproduce the problem in the small attached sketch/windows app I created.

Now for the code. I'm sending about 380 bytes to the T4 in this snippet. The nointerrupts was to stop the interrupts from firing off during the update process.
adding the nointerrupts to the code caused it to freeze. I'm also doing an eeprom update during this operation.

https://www.mediafire.com/file/9mgopnm1m3cfrs5/serial_Test.zip/file

I'm unable to upload to your site, so i had to externally link it.

To invoke the bug uncomment the nointerrupt/interrupt lines.
 
T_4.x has smaller FIFO's than the #1 and #2 on T_3.x's

Interrupts are required to pull the characters from the UART hardware before they are lost.

If disabled too long that happens.

EEPROM writes also disable interrupts out of necessity.
 
T_4.x has smaller FIFO's than the #1 and #2 on T_3.x's

Interrupts are required to pull the characters from the UART hardware before they are lost.

If disabled too long that happens.

EEPROM writes also disable interrupts out of necessity.

Opps - OP guessing wasn't clearly resolved and registered on reply ...

But, UART's are not in use? Using Serial USB shouldn't have that as a related problem ...
 
Now I'm confused. Are we talking of USB device serial, or hardware serial?


My question therefore was to find out if there is a difference between the implementation in Serial between T3 and T4 devices

Yes. The underlying hardware is completely different (both USB and UART) between Teensy 3 to Teensy 4. The software is meant to give the same API. Not sure how that knowledge is supposed to help, but there's an answer to your question.
 
Opps - OP guessing wasn't clearly resolved and registered on reply ...

But, UART's are not in use? Using Serial USB shouldn't have that as a related problem ...


Only comms I'm using is the Serial class from arduino library.
Is UART the tech that involves the hardware serial? Using the pins to communicate with another device? If so, no I'm using the USB device serial only (usb cable).

I have very limited understanding of the belly of these things. The sample I provided reproduced the error. The windows exe is in the folder called "bin" and if the teensy sketch provided is ran with the noninterrupt uncommented it will freeze.
 
Now I'm confused. Are we talking of USB device serial, or hardware serial?

Not sure how that knowledge is supposed to help, .

Obviously something is different if the same code works on T3 but doesn't on T4...
Why are you sounding so hostile? Thought you'd be happy someone found what could be a bug, but I'm just hoping it's poor implementation on my part.
Again, I'm not a hardcore embedded programmer like you. I'm merely a customer trying to make use of your product. Are you trying to help me or is being condescending
helping you?
 
The mediafire link did not work for me, probably due to ad blocking installed on my browser. Not planning to spend time on this unless the code and process to reproduce the problem is here on this forum.


It's difficult to post code sometimes based on what exactly it is I'm working on and where the problem is.

For the sort of help we usually give here on this forum, I really do not believe it is too much for you to trim away all the secret stuff from your commercial project and show just a minimal program which demonstrates the problem in a reproducible way. Yes, that is extra work. But consider that we are spending time to investigate the cause on your specific problem. Please, stop wasting everyone's time.
 
Why are you sounding so hostile?

Look, you've started several threads on this forum, every time with messages back and forth before you reluctantly show enough info for us to actually help. I'm personally frustrated that you keep doing this.

By now you know how this forum works. We do help, probably much more than most other places. But we expect you to show code to reproduce this sort of problem. Every page has "Forum Rule" at the top in red.
 
The mediafire link did not work for me, probably due to ad blocking installed on my browser. Not planning to spend time on this unless the code and process to reproduce the problem is here on this forum.




For the sort of help we usually give here on this forum, I really do not believe it is too much for you to trim away all the secret stuff from your commercial project and show just a minimal program which demonstrates the problem in a reproducible way. Yes, that is extra work. But consider that we are spending time to investigate the cause on your specific problem. Please, stop wasting everyone's time.

I did that, it's by the mediafire link. I have adblocker and the link is no problem to get to. I had problems uploading the zip on your forum. If that's too much to do, then it's ok.
defragster already helped and I already worked around using the nointerrupt in the code that caused the freeze. But for the others and advancement of the framework, I'll try to upload it again. Maybe the forum was blocking the zip because of DLL/executable or something inside.

The first code is to be complied by .NET:

Code:
//C# console PC test appusing System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace serialT4TestWin
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
          
                Console.WriteLine("Enter com port (number only):");
                var comport = "COM" + Console.ReadLine();
                var test = new SerialTest(comport);
            while (true)
            {
                Console.WriteLine("Enter T to test serial");
                var command = Console.ReadLine();
                if (command == "t")
                {
                    test.sendSerialTest();
                }
            }

        }

        public class SerialTest
        {
            SerialPort port;
            string COMPORT;
            public SerialTest(string comport)
            {
                COMPORT = comport;
            }
            public void sendSerialTest()
            {
                int baud = 115200;

                if (port == null || !port.IsOpen)
                {
                    port = new SerialPort(COMPORT, baud, Parity.None, 8, StopBits.One);
                    port.ReadTimeout = 2000;
                    port.WriteTimeout = 2000;
                    port.ReceivedBytesThreshold = 1;
                    port.Open();
                }
                for (int i = 0; i < 100; i++)
                {
                    port.Write("88|");
                    char c = (char)port.ReadChar();
                    Console.WriteLine(c);
                }
            }
           
            

             
        }
    }
}

//teensy sketch:
Code:
/*
 Name:		T4SerialTest.ino
 Created:	4/15/2022 12:20:28 PM
 Author:	Donperry
*/
#include <EEPROM.h>
#include <EEPROManything.h>
// the setup function runs once when you press reset or power the board
struct TestDatastruct {

	short   testTable0[22][15] = {
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },

	};
	short   testTable1[22][15] = {
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },

	};
	short   testTable2[22][15] = {
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },

	};
	short   testTable3[22][15] = {
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },

	};

};
TestDatastruct struc;
void setup() {
	pinMode(13, OUTPUT);
	 Serial.begin(115200);
	 attachInterrupt(9, dummyHandler, CHANGE);
	 struc =  TestDatastruct();
}

// the loop function runs over and over again until power down or reset


elapsedMicros updateCheckTimer;
void loop() {

	if (updateCheckTimer > 50) //check for data every 50ms
		if (Serial.available()) //then we have update to read from stream
		{
			 noInterrupts();
			updateCheckTimer = 0; //reset the counter
			for (int i = 0; i < 100; i++)
			{
				String data = Serial.readStringUntil('|');
				if (data >= 0 || data <= 10000)
				{
					digitalWrite(13, !digitalRead(13));
				}
				Serial.print("R");
				//EEPROM.put(0, struc);
			}
			interrupts();
		}
}

void dummyHandler()
{

}
 
Last edited by a moderator:
p#13 sketch has EEPROM write commented out and a pin #9 interrupt that calls a void function, may not be triggered? Not sure if the void _isr() might be cascading in multiple triggers with no code to allow the fast Core to see the slow I/O channel register the fact that the interrupt was serviced - may need a _dsb?

If it is just a matter of the noInterrupts() a simple example should prove that out, similar to p#13 sketch?

TyQt/TyCommander can send a file out over USB - that would allow PC testing without building the .NET app.

What is the reason to use noInterrupts() while reading the Serial data?

Is the input to Teensy from PC just 100 copies of: "88|"
 
I am not sure finding out why faulty code might work on T3.x and not T4 is worth any time. It is most likely due to speed and when Serial available becomes true.

But here is a code review that my help with some other issues ( or not ):

Code:
elapsed[B]Micros[/B] updateCheckTimer;
void loop() {

	if (updateCheckTimer > 50) //check for data every 50ms  [COLOR="#FF0000"]This is every 50 micro seconds[/COLOR]
		if (Serial.available()) //then we have update to read from stream
		{
			 noInterrupts();
			updateCheckTimer = 0; //reset the counter
			for (int i = 0; i < 100; i++)
			{
				String data = Serial.readStringUntil('|');
				if (data >= 0 || data <= 10000)    [COLOR="#FF0000"]I first though this should be && instead of ||.
  I think it is nonsensical to compare strings to numbers.  It won't work as expected. [/COLOR]
				{
					digitalWrite(13, !digitalRead(13));
				}
				Serial.print("R");
				//EEPROM.put(0, struc);
			}
			interrupts();
		}
}
 
I am not sure finding out why faulty code might work on T3.x and not T4 is worth any time. It is most likely due to speed and when Serial available becomes true.

But here is a code review that my help with some other issues ( or not ):

...

I wondered about those items as well ... but didn't seem germane to the issue.
> .available() can be checked as often as desired 50 us or ms ... but yes the comment disagrees with the code
> The data String compared to a value would just skip the change on pin #13. Yes it should be &&, as written if the compare were valid it would never fail as it is either >= than 0 OR <= than 10,000
 
Please understand that the code was hurried trying a bunch of things to reproduce the problem. From the actual interrupt to testing the eeprom saving a file size about the same size as the data I use in the actual project.



I made changes to the code

Code:
/*
 Name:		T4SerialTest.ino
 Created:	4/15/2022 12:20:28 PM
 Author:	Donperry
*/
#include <EEPROM.h>
#include <EEPROManything.h>
// the setup function runs once when you press reset or power the board
struct TestDatastruct {

	short   testTable0[22][15] = {
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },

	};
	short   testTable1[22][15] = {
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },

	};
	short   testTable2[22][15] = {
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },

	};
	short   testTable3[22][15] = {
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },
	  {0,100,100, 100, 65, 100, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 75, 100, 100, 100,100,100,100,100,100,100 },
	  {100,100,100, 100, 100, 100, 85, 100, 100,100,100,100,100,100,100 },
	  {28,100,100, 100, 100, 100, 100, 95, 100,100,100,100,100,100,100 },
	  {100,38,100, 100, 100, 100, 100, 100, 0,100,100,100,100,100,100 },
	  {100,100,48, 100, 100, 100, 100, 100, 100,5,100,100,100,100,100 },
	  {100,100,100, 58, 100, 100, 100, 100, 100,100,15,100,100,100,100 },
	  {100,100,100, 100, 68, 100, 100, 100, 100,100,100,25,100,100,100 },
	  {100,100,100, 100, 100, 78, 100, 100, 100,100,100,100,35,100,100 },
	  {100,100,100, 100, 100, 100, 88, 100, 100,100,100,100,100,45,100 },
	  {100,100,100, 100, 100, 100, 100, 98, 100,100,100,100,100,100,55 },

	};

};
TestDatastruct struc;
void setup() {
	pinMode(13, OUTPUT);
	 Serial.begin(115200);
	 attachInterrupt(9, dummyHandler, CHANGE);
	 struc =  TestDatastruct();
}

// the loop function runs over and over again until power down or reset


 void loop() {

	 
 
	  //check for data every 50ms
		if (Serial.available()) //then we have update to read from stream
		{
		 
			for (int i = 0; i < 100; i++)
			{
				noInterrupts();
				int data = Serial.readStringUntil('|').toInt();
				if (data >= 0 || data <= 10000)
				{
					digitalWrite(13, !digitalRead(13));
				}
				Serial.print("R");
				 EEPROM.put(0, struc);
				 interrupts();
			}
		}
}

void dummyHandler()
{

}
 
I am not sure finding out why faulty code might work on T3.x and not T4 is worth any time. It is most likely due to speed and when Serial available becomes true.

But here is a code review that my help with some other issues ( or not ):
please see latest sketch.
 
Do not use Serial.readStringUntil() between noInterrupts() and interrupts().

While interrupts are disabled, Serial can't respond to incoming data.

This could cause problems on either Teensy 3 or Teensy 4. But with Teensy 4 the CPU is so much faster, and the yield() stuff which runs between calls to loop() was rewritten to be more efficient, so a lot less time is spent on Teensy 4 running the rest of your program which doesn't wait. The USB communication is also much faster (480 vs 12 Mbit/sec) so the underlying timing of interrupts is vastly different.

As a general guideline, you should probably not call any function while interrupts are disabled. Usually interrupt disable should only be used to read & write volatile variables which are shared with the interrupt function. You should always turn interrupts back on as soon as you're done accessing those variables. Never call functions like Serial or delay() which depend on interrupts while you've disabled interrupts!
 
Back
Top