2022-07-06 02:03 PM
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.
Solved! Go to Solution.
2022-07-07 05:34 PM
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.
2022-07-06 02:45 PM
The UART sends exactly what you order it to send. Check your code.
2022-07-06 03:38 PM
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.
2022-07-06 08:09 PM
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.
2022-07-06 08:10 PM
Don’t remember the use of sizeof or strlen. But will check out as soon I arrive to my office.
2022-07-07 12:16 AM
>>> The TX pin should normally be HIGH between transmissions.
I have removed this line of code and now I don't see the \0 at the end:
USART1->CR1 &= ~USART_CR1_TE; // Disable transmitter
I find out that line is disabling the transmitter by putting low bit on the third bit of the CR1 register of the UART. And now is not sending the \0. Is it ok that the transmitter is always enabled?
2022-07-07 01:40 AM
@Raúl Pérez Gómez "I find out that line is disabling the transmitter"
Well, that is what the comment says! ;)
"Is it ok that the transmitter is always enabled?"
It's fine as far as the STM32 is concerned.
Whether it's a Good Thing for your particular application is an entirely different question - you're going to have to research why your predecessor(s) did that; eg,
2022-07-07 07:10 AM
After I removed the line USART1->CR1 &= ~USART_CR1_TE; // Disable transmitter it seems that the TX buffer is not getting flushed. Is there a way to flush it which is not disabling the TX on the CR1 register?
2022-07-07 07:20 AM
@Raúl Pérez Gómez "it seems that the TX buffer is not getting flushed"
How do you determine that?
2022-07-07 07:24 AM
Before I removed the disable TX I was receiving \0 at the end of the transmissions from my device to may python script. I wanted to avoid that.
After I removed that line I get data from the prior command when transmitting from the device to my script.
Sorry I am quite new and I am quite lost.