I am writing ASCII commands over a UART interface in an embedded linux system.
I tested the code with a laptop to begin with. Both the embedded platform and the laptop share a ftdi usb dongle. The code should be identical on the two platforms (I thought).
I am creating a string and sending it like so,
char cmd[MAX_STR_LEN];
sprintf(cmd,"r %02x %02x\n",chipAddr,naddr);
ssize_t bytes_tx = write(fd, (char *)cmd, strlen(cmd));
if (bytes_tx < 0){
ERROR_PRINT("%s\n",strerror(errno));
return -1;
}
When I monitor the output of the serial device on an oscilloscope when running the code from the PC I see that \n is correctly interpreted as 0x0a.
When I run the same code snippet on the embedded platform I see \n is being interpreted as 0x0d 0x0a or \r\n.
How do I force the embedded platform to send only \n or 0x0a? The embedded platform is running Linux Kernel 4.4.x generated with buildroot.
--- UPDATED Full Test Code
Placed full code here : https://pastebin.com/5dWhaaDv
result on both embedded and laptop targets,
Connected to /dev/ttyUSB0
strlen 8 : r 40 00
tx cmd[0] = 72 r
tx cmd[1] = 20
tx cmd[2] = 34 4
tx cmd[3] = 30 0
tx cmd[4] = 20
tx cmd[5] = 30 0
tx cmd[6] = 30 0
tx cmd[7] = 0a
bytes_tx = 8
sizeof(\n) : 4