0

I am trying to transfer individual bytes from a binary file over UART from a Linux MPU to a separate MCU. The code I am using to transfer the data is shown below:

echo -ne $data > /dev/ttyS1

This code has been working great for me except for in one situation when the data includes a hex value of \x0A (newline character). Whenever I echo the \x0A value with the code above, it actually sends \x0D\x0A (carriage return and newline character). Because of this, I get errors in my binary file transfer.

I have tried sending the following commands:

echo -ne "\x0A" > /dev/ttyS1
echo -ne "\n" > /dev/ttyS1

When I do that, the UART bus is showing the 0x0D0A transfer as shown in the image below.

UART Transfer

Is there a way I can force the echo to just send the 0x0A character without the 0x0D character appended to it?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Smithy
  • 1
  • 1
  • try using `printf` instead. good luck – shellter Jul 14 '23 at 18:48
  • 2
    Duplicate of https://stackoverflow.com/q/71524964/103167 (except that you're using the shell, so you'll need the `stty` command instead of calling OS functions). Try `stty -F /dev/ttyS1 raw` – Ben Voigt Jul 14 '23 at 21:37
  • as said, you need to [use raw mode instead of cooked mod](https://stackoverflow.com/q/70922286/995714) – phuclv Jul 22 '23 at 10:48
  • Those articles about configuring the Linux terminal did resolve my question. I somehow missed that setting in the STTY configuration. Thanks for your help! – Smithy Jul 24 '23 at 17:03

0 Answers0