Serial1.write((byte) 0x00)

Hello,

I use UART binary communication channel on 33iot. All works fine except transmitting zero byte 0x00. I have read few other threads on related topics and they suggested to include explicit (byte) typing to avoid misinterpretation with null string termination.

However even explicit Serial1.write((byte) 0x00) does not send anything. All other non-zero values are being sent OK.

any hints?

thanks

Jan

Start by posting an example sketch that illustrates the problem, using code tags when you do

What is receiving the data that you transmit ?

This is a part of large project that I cannot post here. However I am sure that all other aspects (eg. UART serial connection initialisation, all HW aspects, etc.) are working OK. I was able to isolate the problem to this single code line:

Serial1.write((byte) 0x01) ... works OK and correctly sends the byte
Serial1.write((byte) 0x00) ... does not send anything

the UART communication is between Arduino and other microcontroller (based on xmc4200)

Jan

How do you know that nothing is sent ?

Are you absolutely sure that the problem is not at the receiving end ?

I am sure by both, observing the receive register on xmc4200 side (by attached debugger) and by observing the UART Tx line by oscilloscope.

Then something else is wrong

Running this sketch on a Nano 33 IOT

void setup()
{
  Serial1.begin(9600);
}

void loop()
{
  Serial1.write((byte)0x0);
  delay(1000);
}

and this sketch on a Nano classic

void setup()
{
  Serial.begin(9600);
}
void loop()
{
  if (Serial.available())
  {
    Serial.println("got a byte");
    Serial.read();
  }
}

prints the "got a byte" message every second as expected

The two Nanos have a common GND connection and the boards are connected by a single wire from the TX1 pin on the 33 to the Rx pin on the classic. I did not bother with a voltage level shifter because of the direction of the transmission from 3V3 to 5V

are you sending binary data or ASCII? ASCII char strings are by convention terminated with a NUL, 0x0

something that delimits the start and end of binary data is required such as start and end values. those values need to be escaped if sent as data, usually by preceding them with an escape value, which also needs to be escaped when sent as data

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.