Teensyv3.5, Serial3, write a black diamond with a white question mark

Status
Not open for further replies.

sntnjrg

Member
Hi,

I'm a newbie. I'm using a Teensy version 3.5. Through the serial port 3 (Serial3), I'm trying to create a communication with a sensor. The sensor receives commands via messages in ASCII code and sends data using the ASCII code as well.

I checked that the serial port connection is created. I can also get the sensor readings from the serial port but when I try to send a command, the sensor doesn't interpret it well. For example, when I send the "reset" command, the following happens:

Code:
reset
ERROR .....
�reset
^
Main->000.156
000.162
000.162

I don't understand why that character appears at the beginning. The command was sent through the serial connection as follows:

Code:
size_t bytes_transferred = 0;
bytes_transferred += Serial3.write('r');
bytes_transferred += Serial3.write('e');
bytes_transferred += Serial3.write('s');
bytes_transferred += Serial3.write('e');
bytes_transferred += Serial3.write('t');
bytes_transferred += Serial3.write('\n');

The communication is created as follows:

Code:
  Serial3.begin(9600, SERIAL_8N1);
  while (!Serial3) {;} // Wait for serial port to connect
  while (Serial3.read() >= 0) {;}
  Serial.println(F("Create connection by Serial3 with sensor\nSend reset command"));

Who is responsible for writing that black diamond with a white question mark? Is it a software configuration problem?

I'm using the arduino IDE. Is it an IDE configuration problem?

Thank you
 
Try adding delay(50); after Serial3.begin(), so the transmit pin is idle for a while before you send anything.

Or try connecting a 10K resistor between TX3 and 3.3V, so the transmit pin is at the idle logic high state as Teensy boots up and before you activate the serial port.
 
Hi,

I added the delay but the problem persisted. Before I send the command I run: Serial3.flush(). However, I have checked that if I send two "reset" commands one after the other, the sensor responds: the first time, the error occurs but the second time it works.

Would applying the 10k resistor solution solve the problem, or is it a problem with my code?

Thank you for the help.
 
Hi,

I added the delay but the problem persisted. Before I send the command I run: Serial3.flush(). However, I have checked that if I send two "reset" commands one after the other, the sensor responds: the first time, the error occurs but the second time it works.

Sorry not sure if I understand your call to Serial3.flush();

The flush operation (https://www.arduino.cc/reference/en/language/functions/communication/serial/flush/), says: Waits for the transmission of outgoing serial data to complete.
Yes before Arduino 1.0 release it used to: remove any buffered incoming serial data.

With current Teensy releases you can do: Serial3.clear();
Which will remove any data currently in the input queue or you can do something like: while(Serial3.read() != -1) ;
 
Hi,

I have studied your comments. I added this code before I opened the port:
Code:
 uint8_t txen_pin = 8;
 pinMode(txen_pin, INPUT_PULLUP);
 digitalWrite(txen_pin, HIGH);


With this change, my application is working. I don't have to send two commands in a row.

Thanks for the help.
 
Status
Not open for further replies.
Back
Top