zwarmapapa
Member
I'm trying to create a data transmission system between computers using lasers. To debug it I'm currently using wires instead of lasers.
The protocol is programmed in Java, all the micro controller has to do is to send the data from Serial to Serial1 and the data from Serial1 to Serial.
I previously used two Arduino Micro's which worked fine, except that it could only get speeds of up to 30 kilobytes per second. Because of that I bought two Teensy 3.1's , and now I'm facing a problem with them.
When I transmit a lot of data from the computer to the Teensy, the computer won't receive any bytes from the Teensy anymore. It only happends when I send non-stop data to the Teensy. When I send 4000 bytes and then stop sending anything for about 100ms or so, it will somewhat work again (it will still miss some read data during the sending of those 4000 bytes).
I don't quite know why it does this, to me it looks like the Serial and Serial1 are using the same buffers and that might be causing this problem.
Here is my Teensy code. I got two versions, I usually use the buffered one for performance reasons, I use the one bit per time one for debug purposes. During debugging, I also turned the baud rate down a bit, to be sure that that isn't causing any problems.
Buffered version:
One bit a time version:
You can download the Java application I've made here: https://dl.dropboxusercontent.com/u...nsmission/Data Transmission v1.10 - Debug.jar
Run it with this bat so you can see the debug information: https://dl.dropboxusercontent.com/u...nsmission/Data Transmission v1.10 - Debug.bat
You need to have two micro controllers connected with each other, the micro controllers can be connected to the same computer or to two different computers.
What you should notice is that everything goes fine, you can send text messages over the two, etc, until you send a file. When you send a file, the receiver will still work properly, but the sender won't receive any bytes anymore. It will only send packets, not receive anything.
When I debugged the serial.readBytes() function, it reads bytes under normal circumstances, but when it's sending a file, it will always return null or 0 bytes on the sender's side.
The result on the sender's side is something like this: (--> is sending, <-- is receiving)
The receiver's side works like normal and gives: (--> is sending, <-- is receiving)
I hope someone can help me out here.
The protocol is programmed in Java, all the micro controller has to do is to send the data from Serial to Serial1 and the data from Serial1 to Serial.
I previously used two Arduino Micro's which worked fine, except that it could only get speeds of up to 30 kilobytes per second. Because of that I bought two Teensy 3.1's , and now I'm facing a problem with them.
When I transmit a lot of data from the computer to the Teensy, the computer won't receive any bytes from the Teensy anymore. It only happends when I send non-stop data to the Teensy. When I send 4000 bytes and then stop sending anything for about 100ms or so, it will somewhat work again (it will still miss some read data during the sending of those 4000 bytes).
I don't quite know why it does this, to me it looks like the Serial and Serial1 are using the same buffers and that might be causing this problem.
Here is my Teensy code. I got two versions, I usually use the buffered one for performance reasons, I use the one bit per time one for debug purposes. During debugging, I also turned the baud rate down a bit, to be sure that that isn't causing any problems.
Buffered version:
Code:
#define SERIAL_BAUD_RATE 115200
#define BUFFER_SIZE 256
char buf[BUFFER_SIZE];
void setup()
{
Serial.begin( SERIAL_BAUD_RATE );
Serial1.begin( SERIAL_BAUD_RATE );
}
void loop()
{
int count;
count = Serial.available();
if( count > 0 )
{
if( count > BUFFER_SIZE )
{
count = BUFFER_SIZE;
}
Serial.readBytes( buf, count );
Serial1.write( (uint8_t*)buf, count );
}
count = Serial1.available();
if( count > 0 )
{
if( count > BUFFER_SIZE )
{
count = BUFFER_SIZE;
}
Serial1.readBytes( buf, count );
Serial.write( (uint8_t*)buf, count );
}
}
One bit a time version:
Code:
#define SERIAL_BAUD_RATE 115200
void setup()
{
Serial.begin( SERIAL_BAUD_RATE );
Serial1.begin( SERIAL_BAUD_RATE );
}
void loop()
{
if( Serial.available() )
Serial1.write( Serial.read() );
if( Serial1.available() )
Serial.write( Serial1.read() );
}
You can download the Java application I've made here: https://dl.dropboxusercontent.com/u...nsmission/Data Transmission v1.10 - Debug.jar
Run it with this bat so you can see the debug information: https://dl.dropboxusercontent.com/u...nsmission/Data Transmission v1.10 - Debug.bat
You need to have two micro controllers connected with each other, the micro controllers can be connected to the same computer or to two different computers.
What you should notice is that everything goes fine, you can send text messages over the two, etc, until you send a file. When you send a file, the receiver will still work properly, but the sender won't receive any bytes anymore. It will only send packets, not receive anything.
When I debugged the serial.readBytes() function, it reads bytes under normal circumstances, but when it's sending a file, it will always return null or 0 bytes on the sender's side.
The result on the sender's side is something like this: (--> is sending, <-- is receiving)
Code:
<-- PacketConnectionConfirm
<-- PacketConnectionConfirmRequest
--> PacketConnectionConfirm
--> PacketConnectionConfirm
--> PacketConnectionConfirm
--> PacketConnectionConfirmRequest
<-- PacketConnectionConfirm
<-- PacketConnectionConfirm
<-- PacketConnectionConfirm
write started
--> PacketTCPPartialPacketList
--> PacketTCPPartialPacket
--> PacketTCPPartialPacket
--> PacketConnectionConfirmRequest
--> PacketConnectionConfirmRequest
--> PacketTCPPartialPacket
--> PacketTCPPartialPacket
--> PacketConnectionConfirmRequest
--> PacketConnectionConfirmRequest
--> PacketTCPPartialPacket
--> PacketTCPPartialPacket
--> PacketConnectionConfirmRequest
--> PacketConnectionConfirmRequest
--> PacketTCPPartialPacket
--> PacketTCPPartialPacket
--> PacketConnectionConfirmRequest
--> PacketConnectionConfirmRequest
--> PacketTCPPartialPacketList
--> PacketTCPPartialPacket
--> PacketTCPPartialPacket
--> PacketConnectionConfirmRequest
--> PacketConnectionConfirmRequest
The receiver's side works like normal and gives: (--> is sending, <-- is receiving)
Code:
--> PacketConnectionConfirm
--> PacketConnectionConfirmRequest
<-- PacketConnectionConfirm
<-- PacketConnectionConfirm
<-- PacketConnectionConfirm
<-- PacketConnectionConfirmRequest
--> PacketConnectionConfirm
--> PacketConnectionConfirm
--> PacketConnectionConfirm
--> PacketConnectionConfirmRequest
<-- PacketTCPPartialPacketList
read started
--> PacketTCPReceiveNotification
--> PacketTCPReceiveNotification
--> PacketTCPReceiveNotification
--> PacketConnectionConfirmRequest
--> PacketConnectionConfirmRequest
--> PacketConnectionConfirmRequest
<-- PacketTCPPartialPacket
--> PacketConnectionConfirmRequest
--> PacketTCPReceiveNotification
--> PacketTCPReceiveNotification
--> PacketTCPReceiveNotification
--> PacketConnectionConfirmRequest
<-- PacketTCPPartialPacket
<-- PacketConnectionConfirmRequest
<-- PacketConnectionConfirmRequest
--> PacketConnectionConfirm
--> PacketConnectionConfirm
--> PacketConnectionConfirm
--> PacketConnectionConfirm
--> PacketConnectionConfirm
--> PacketConnectionConfirm
--> PacketConnectionConfirmRequest
--> PacketTCPReceiveNotification
--> PacketTCPReceiveNotification
I hope someone can help me out here.