Skip to main content
RPG
Associate III
July 6, 2022
Solved

After UART send the bytes from the buffer, \0 is also received.

Why I get \0 at the end of the transmission?

I imaging the \0 is a NUL termination character but I have seen from the terminal that sometimes is not received or arrives with a big delay.

Could somebody tell me anything about it?

Thanks in advance.

This topic has been closed for replies.
Piranha
PiranhaBest answer
Principal III
July 8, 2022

Probably the receiver has no pull-up on it's Rx line and, when the MCU releases the Tx pin, the whole line is floating. If the line goes low, such a situation could be interpreted as a start bit + 0x00 data byte. You can test/solve it by enabling a pull-up on MCU's Tx pin.

And yes - you need to understand why the original code disabled the transmitter at all.

25 replies

gbm
Super User
July 6, 2022

The UART sends exactly what you order it to send. Check your code.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Tesla DeLorean
Guru
July 6, 2022

Hard to say, use strlen() not sizeof() for strings passed to the output routines, the latter with describe/include the trailing NUL too.

The TX pin should normally be HIGH between transmissions.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
RPG
RPGAuthor
Associate III
July 7, 2022

The code I saw from the previous developer is using the registers to send the content of the buffer. In the buffer there is no \0.

Piranha
PiranhaBest answer
Principal III
July 8, 2022

Probably the receiver has no pull-up on it's Rx line and, when the MCU releases the Tx pin, the whole line is floating. If the line goes low, such a situation could be interpreted as a start bit + 0x00 data byte. You can test/solve it by enabling a pull-up on MCU's Tx pin.

And yes - you need to understand why the original code disabled the transmitter at all.

RPG
RPGAuthor
Associate III
July 8, 2022

Thank you Piranha. This made it work. I have learnt A lot fro this issue.

I changed the TX pin to pull-up and now is working fine.