How to display whitespace in rust byte string?

Posting this question after breaking my head for a week and don't see it going anywhere.
Following is the code:

let note = b"Hell World\n";

for i in 1..10 {
    for c in note.iter() {
        while (uart.poll_tx_busy()){

If let note = b"HelloWorld\n", it spits "0x48 0x65 0x6c 0x6c 0x6f 0x57 0x6f 0x72 0x6c 0x64 0x0a" as expected on the serial and displays HelloWorld.

However, when let note = b"Hell World\n"; it spits 0x48 0x65 0x6c 0x6c 0xa0 0xd5 0x4b 0xb1 0x91 0x29 and displays HellK)

This is just an example. Any long string without SPACE is displayed properly, the moment SPACE is introduced, could n't interpret the displayed text.

Is there anything,I should take care to display whitespace using byte string in RUST?

I suspect this isn't a Rust problem, but a hardware problem.

How are you displaying the characters? If you are printing them on something like an LCD display, are you sure it supports the ASCII space character?

Also, are you sure the data isn't being messed up as it gets sent across your UART connection?

At a previous workplace we used to use serial to communicate between a computer and a microcontroller in a noisy cabinet and we found the UART transmissions would sometimes be garbled and need re-sending. If you can, you might want to inspect the bytes as they are received to see if they are what you sent.

1 Like

0xA0 is interesting because it's exactly 0x80 more than the ASCII space character, 0x20. So, one possibility is that the high bit got set (0xA0 = 0x20 | 0b1000_0000 = 0b1010_0000) somehow in transmission.

(It also happens that 0xA0 is the Unicode (and Latin-1) code point for non-breaking space.)

But if that happens, that doesn't explain why the following bytes changed too. Nor does the result look like a UTF-8 mis-encoding (it might be something else).

Whatever the answer to your problem is, it won't be found with just general Rust knowledge.


Its displayed on serial console (serial monster app). It supports space.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.