Re: [Ftdi-usb-sio-devel] Data corruption on serial link using FTDI USB to serial driver and RS232
Brought to you by:
bryder
From: Mats J. <mat...@te...> - 2018-03-20 16:05:27
|
<html><head><title>Re: [Ftdi-usb-sio-devel] Data corruption on serial link using FTDI USB to serial driver and RS232</title> </head> <body> <span style=" font-family:'Arial'; font-size: 12pt;">Hi,<br> <br> I think I am closing in on this issue a bit.<br> <br> I have noticed using a logical analyzer (digview) that the FTDI is normally high (+3.3V) between ground and TX/RX, while on the PC the signal is normally low.<br> <br> So on the FTDI output the startbit makes the line go low, while on the PC the startbit makes the line go high.<br> <br> If I in tell the DigiView software to interpret the signal inverted from the PC it will read the bytes as 30 31 32 33 34 35 36 37 38 39.<br> <br> I don’t see why it is this way?<br> <br> Is there something that needs to be configured in our driver in our embedded system to make it invert the signals, so that the PC can recogize it correctly?<br> <br> /Mats<br> <br> <br> <br> Med vänlig hälsning,<br> Mats </span><a style=" font-family:'arial'; font-size: 12pt;" href="mailto:mat...@te...">mailto:mat...@te...</a><br> <br> <br> <span style=" font-family:'Arial'; font-size: 12pt;">den 19 mars 2018, skrev du till mig:<br> <br> </span><table> <tr> <td width=2 bgcolor= #0000ff><br> </td> <td><span style=" font-family:'arial'; font-size: 12pt;">Hej Bill and Michael,<br> <br> As I said two ports on my embedded system. These are both USB ports.<br> <br> I have now tried out connecting an FTDI USB-Serial converter to both of these and connnected them to each other.<br> This way I can echo to one of the ports e.g /dev/ttyUSB0 and I get the correct data sent to the other port, i.e. /dev/tty/USB1.<br> It also works like a charm when I send the other way, i.e. from /dev/ttyUSB1 to /dev/ttyUSB0. <br> <br> It works both if use the default settings of the ports, and also if i use the stty command to set the parameters to raw.<br> <br> When connecting to my Windows machine I still get the same error.<br> <br> I am trying to set up so that my virtual machine with Ubuntu 16.04 running under Windows and Virtual box to use the serial port COM1 of my computer, but without any luck so far.<br> I get access denied when I try to access it, using echo.<br> <br> Med vänlig hälsning,<br> Mats </span><a style=" font-family:'arial'; font-size: 12pt;" href="mailto:mat...@te...">mailto:mat...@te...</a><br> <br> <br> <span style=" font-family:'arial'; font-size: 12pt;">den 17 mars 2018, skrev du till mig:<br> <br> </span><table> <tr> <td width=2 bgcolor= #0000ff><br> </td> <td><span style=" font-family:'arial'; font-size: 12pt;">Good call Michael.<br> <br> The pattern in the bytes is indicative of mismatched serial parameters.<br> <br> Re the different byte counts you are getting - that completely depends on when the data is available on the interface - there's no guarantee that the blocks of data you are sending will be delivered in the same chunks you have put them on the interface unless you make extra system calls.<br> <br> I see you are missing the last little chunk of data which suggests there was still that data in the buffers to be read.<br> <br> <span style=" font-size: 11pt; color: #222222;">Your expected output should include a newline because echo puts a newline on the output stream if you don't use the -n option<br> <span style=" font-size: 12pt; color: #000000;">In ubuntu 1604 (and probably most linuxes) you can use this to check the serial settings<br> <br> sudo stty -a --file=/dev/ttyUSB0<br> <br> <b>speed 9600 baud</b>; rows 0; columns 0; line = 0;<br> intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;<br> eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;<br> werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;<br> <b>-parenb -parodd</b> -cmspar <b>cs8</b> hupcl <b>-cstopb </b>cread clocal -crtscts<br> -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff<br> -iuclc -ixany -imaxbel -iutf8<br> opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0<br> isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt<br> echoctl echoke -flusho -extproc<br> <br> man stty will tell you what the settings are.<br> <br> You can change them with stty as well - but - at least in the old days - you have to hold that device open, or the settings will reset when the file is closed.<br> <br> I suggest you use the tool screen to talk to the serial interface, you can set parity etc and everything you type should go to the port and you'll have proper control over the serial parameters.<br> <br> screen isn't necessarily installed by default so you may have to install it.<br> <br> On 17 March 2018 at 12:14, Michael Plante <</span></span></span><a style=" font-family:'arial'; font-size: 12pt;" href="mailto:mic...@gm...">mic...@gm...</a><span style=" font-family:'arial'; font-size: 12pt;">> wrote:<br> </span><table> <tr> <td width=2 bgcolor= #3200ff><br> </td> <td><span style=" font-family:'arial'; font-size: 12pt;">Mats,<br> <br> I don't know the answer, but I see patterns in the data. I suggest carefully checking parity, 1vs2 stop bits, and 7vs8 bits/char and reporting what you see. I can't remember the chipset, but I've seen some converters don't respect all those settings, so you might try 8n1 if you can. Buffering with usb to serial is hit or miss in my experience. I assume the converter is COTS, not custom, and it's a plain serial cable. An oscope would make this easier. Maybe also try sending other patterns involving 5,A,3,C.<br> <br> <span style=" color: #888888;">Michael<br> <br> <br> <span style=" color: #000000;">On Mar 16, 2018 10:33, "Mats Jansson" <</span></span></span><a style=" font-family:'arial'; font-size: 12pt;" href="mailto:mat...@te...">mat...@te...</a><span style=" font-family:'arial'; font-size: 12pt;">> wrote:<br> </span><table> <tr> <td width=2 bgcolor= #6400ff><br> </td> <td><span style=" font-family:'arial'; font-size: 12pt;">Hi,<br> <br> I have a problem with the FTDI USB Serial port driver in an embedded<br> system.<br> The embedded system is a running Linux kernel 4.4, and we have an<br> atmel processor.<br> <br> The FTDI USB Serial port driver is built into the kernel.<br> <br> I attach an the USB end of an FTDI USB to RS232 adapter to the linux unit and connect<br> the RS232 connector to a PC.<br> <br> In a terminal window on my linux unit I do the following<br> $ echo 01234567899876543210 > /dev/ttyUSB0<br> $ echo 01234567899876543210 > /dev/ttyUSB0<br> $ echo 01234567899876543210 > /dev/ttyUSB0<br> $ echo 01234567899876543210 > /dev/ttyUSB0<br> $ echo 01234567899876543210 > /dev/ttyUSB0<br> <br> In the other end I have connected a PC and built a very simple program<br> that opens the COM port, reads data and prints it out.<br> I was expecting to get the data as (printed in hex values):<br> Read 20 bytes [30 31 32 33 34 35 36 37 38 39 39 38 37 36 35 34 33 32 31 30]<br> Read 20 bytes [30 31 32 33 34 35 36 37 38 39 39 38 37 36 35 34 33 32 31 30]<br> Read 20 bytes [30 31 32 33 34 35 36 37 38 39 39 38 37 36 35 34 33 32 31 30]<br> Read 20 bytes [30 31 32 33 34 35 36 37 38 39 39 38 37 36 35 34 33 32 31 30]<br> Read 20 bytes [30 31 32 33 34 35 36 37 38 39 39 38 37 36 35 34 33 32 31 30]<br> <br> But the resulting data on the PC from the three lines of echo above is:<br> Read 14 bytes [D6 B6 96 76 56 36 16 F6 D6 D6 F6 16 36 56 ]<br> Read 28 bytes [76 96 B6 D6 F6 B6 00 D6 B6 96 76 56 36 16 F6 D6 D6 F6 16 36 56 76 96 B6 D6 F6 B6 00 ]<br> Read 14 bytes [D6 B6 96 76 56 36 16 F6 D6 D6 F6 16 36 56 ]<br> Read 15 bytes [76 96 B6 D6 F6 B6 00 D6 B6 96 76 56 36 16 F6 ]<br> Read 29 bytes [D6 D6 F6 16 36 56 76 96 B6 D6 F6 B6 00 D6 B6 96 76 56 36 16 F6 D6 D6 F6 16 36 56 76 96 ]<br> <br> Not only the data is not all what I suspected, there seems to be some<br> buffering issue.<br> <br> I have tested with different speeds on the line, 2400, 9600, 57600 and<br> 115200 and the result is the same in all cases. I have also tested to<br> send data the other way, and the result is similar.<br> <br> Does anyone have any idea what could be wrong here?<br> Why is the data corrupted?<br> <br> Best Regards,<br> Mats mailto:</span><a style=" font-family:'arial'; font-size: 12pt;" href="mailto:mat...@te...">mat...@te...</a><br> <br> <br> <span style=" font-family:'arial'; font-size: 12pt;">------------------------------------------------------------------------------<br> Check out the vibrant tech community on one of the world's most<br> engaging tech sites, Slashdot.org! </span><a style=" font-family:'arial'; font-size: 12pt;" href="http://sdm.link/slashdot">http://sdm.link/slashdot</a><br> <span style=" font-family:'arial'; font-size: 12pt;">_______________________________________________<br> Ftdi-usb-sio-devel mailing list<br> </span><a style=" font-family:'arial'; font-size: 12pt;" href="mailto:Ftd...@li...">Ftd...@li...</a><br> <a style=" font-family:'arial'; font-size: 12pt;" href="https://lists.sourceforge.net/lists/listinfo/ftdi-usb-sio-devel">https://lists.sourceforge.net/lists/listinfo/ftdi-usb-sio-devel</a></td> </tr> </table> <br> <span style=" font-family:'arial'; font-size: 12pt;">------------------------------------------------------------------------------<br> Check out the vibrant tech community on one of the world's most<br> engaging tech sites, Slashdot.org! </span><a style=" font-family:'arial'; font-size: 12pt;" href="http://sdm.link/slashdot">http://sdm.link/slashdot</a><br> <span style=" font-family:'arial'; font-size: 12pt;">_______________________________________________<br> Ftdi-usb-sio-devel mailing list<br> </span><a style=" font-family:'arial'; font-size: 12pt;" href="mailto:Ftd...@li...">Ftd...@li...</a><br> <a style=" font-family:'arial'; font-size: 12pt;" href="https://lists.sourceforge.net/lists/listinfo/ftdi-usb-sio-devel">https://lists.sourceforge.net/lists/listinfo/ftdi-usb-sio-devel</a></td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </body></html> |