Problem with serial1 or serial with Teensy 4.1 but no problem with Teensy 3.5

Bking

Member
Hi,
Teensy is connected with Processing software.
In Processing I read data from serial1 and I send other data to serial.
It works fine with Teensy 3.5
I do the same thing with Teensy 4.1, but it doesn't work.
After ports displayed, I have an error message

[0] "/dev/cu.Bluetooth-Incoming-Port"
[1] "/dev/cu.usbmodem116574201"
[2] "/dev/cu.usbserial-0001"
[3] "/dev/tty.Bluetooth-Incoming-Port"
[4] "/dev/tty.usbmodem116574201"
[5] "/dev/tty.usbserial-0001"
Error, disabling serialEvent() for /dev/cu.usbmodem116574201
null

According to this error message the data of serialEvent() would come from serial1 and not from serial. :confused:

In teensy I set
serial "dev/cu.usbmodem116574201" is to send data to the Teensy 4.1
serial1 "/dev/cu.usbserial-0001" is to read from the UART connected to the Teensy 4.1

with this bauds
Serial.begin (115200);
Serial1.begin (100000);

Here the program from Processing

import processing.serial.*;
Serial encoderReceiveUSBport101; // The serial1 port. I read data from serial1 in serialEvent sending
Serial teensyport; // serial port. I send data to teensy with serial

int [] formerFrameCountFromSerialEvent =new int[6]; //;
int formeFrame;
int encodeur[]= new int[6]; //
int dataTosendToSerial[] = new int [6]; //

public void settings() {
size(600, 600, P3D);
}


void setup() {
frameRate(15);
for (int i = 0; i < 6; i++) {
dataTosendToSerial= 0;
}
fill(255, 0, 0, 50);
frameRate(15);

printArray(Serial.list()); // print serial port
println("Start port setup");
setPort();

}

void draw() {

if (frameCount ==5) noLoop();
if (frameCount >=5) { printArray(encodeur);}


if (frameCount >= 15 ){
println ( frameCount);

for (int i = 0; i < 6; i++) {
dataTosendToSerial-= 100;
}
println("send actual datas");
send24DatasToTeensy6motors(10, -3, -3, -1);
}
else println("send before datas");

}


void setPort() {

String[] ports = Serial.list();

//*************** TEENSY connected with serial
teensyport = new Serial(this, ports[1], 115200);//

//*************** TEENSY connected with serial1
encoderReceiveUSBport101 = new Serial(this,ports[2], 1000000); //

// Read bytes into a buffer until you get a linefeed (ASCII 10):
encoderReceiveUSBport101.bufferUntil('\n');
}

void send24DatasToTeensy6motors(int accelerationRatio, int driver0_On_Off, int computeData, int eraseProcessingData) { // dataMarkedToTeensyArevoir

String dataFromMode;
dataFromMode ="<"

+ dataTosendToSerial[5]+ ","+ dataTosendToSerial[4]+ ","+ dataTosendToSerial[3]+","+ dataTosendToSerial[2]+ ","
+ dataTosendToSerial[1]+ ","+ dataTosendToSerial[0] + "," //
+0+","+0+","+0+","+0+","

+ accelerationRatio +","+ driver0_On_Off +","+ computeData +","+ eraseProcessingData + ","

+0+","+0+","+0+","+0+","+0+","+0+","


+0+","+0+","+0+","+0+">";

teensyport.write(dataFromMode);
}

// serialEvent method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():


void serialEvent(Serial encoderReceiveUSBport101) {

String myEncodeur = encoderReceiveUSBport101.readStringUntil('\n');

myEncodeur = trim(myEncodeur);

int values[] = int(split(myEncodeur, ',')); // dispatch receive datas splited with ,


if (values.length == 6) {// encodeur de 0 a 4000
encodeur[0] = (int) map (values[0], 0, 4000, 0, 800)%800;
encodeur[1] = (int) map (values[1], 0, 4000, 0, 800)%800;
encodeur[2] = (int) map (values[2], 0, 4000, 0, 800)%800;
encodeur[3] = (int) map (values[3], 0, 4000, 0, 800)%800;
encodeur[4] = (int) map (values[4], 0, 4000, 0, 800)%800;
encodeur[5] = (int) map (values[5], 0, 4000, 0, 800)%800;
}
}

Thanks for helping
 
Note: I don't use processing so not sure what their capabilities are. Sort of hard to read the above as the code is not in code tags (# button in toolbar)

There are a couple of major differences of the USB Serial of the T3.x versus T4.x

The T3.x uses USB Full speed which is 12MBS whereas the T4.x runs using High speed (480MBS) which is a whole lot faster.
And the packets size with T3.x is 64 bytes and with T4.x 512 bytes.

N
 
tell me the way to change T4.x 512 bytes as 64 bytes?

Edit usb.c in the teensy4 folder. Look for this line:

Code:
	//USB1_PORTSC1 |= USB_PORTSC1_PFSC; // force 12 Mbit/sec

If you uncomment this line, the USB device port on Teensy 4.x will run at only 12 Mbit/sec, which uses 64 byte packet size.


EDIT: however, I believe this is unlikely to solve the problem, as the serial driver will allow you to read smaller amounts even when it has received larger packets.
 
Last edited:
EDIT: however, I believe this is unlikely to solve the problem, as the serial driver will allow you to read smaller amounts even when it has received larger packets.

You should have right, but I would like to know how can I change packet of 64 in 16.
I had a similar problem a long time ago, and changing packet has fixed the bug

You told me to change
NVIC_SET_PRIORITY(IRQ_UART0_STATUS, 64); // I don't remember if it was originally 64

with

NVIC_SET_PRIORITY(IRQ_UART0_STATUS, 16);

to change a priority....

Can I do the same thing ? In which folder and file is this line ?

Thank again.



`
 
Back
Top