3

Core question: How does UART connection on *nix differ from UART connection on Windows ? What settings need to be kept in consideration for proper data transmission and reception ?

Context for asking this question: This question is related to my other one on Electrical Engineering site. Basically, I've a serial (USB to RS-232) connection with my Ubuntu laptop to microcontroller, and I receive last 4 bits correctly, but not first 4. On Windows I receive all 8 bits. What could be the possible issue ? More importantly , I am interested in the difference of Windows UART vs Linux UART

Specifics:

Themain on the microcontroller I am using ( PIC 18F87J11 ) has very simple code:

  while (1) {
        while (!PIR1bits.RC1IF);  //Wait for a byte
        sprintf(txStr,"%.5X",RCREG);
        LCDWriteLine(txStr,0);

The point here is that it receives a byte and prints its hex value to LCD screen. In theory, this should work without issues. Baud rate is 9600 , no parity , nothing out of the ordinary. On Windows I use putty, on Linux - screen . Same settings in both.

Yet, on Windows I receive hex value of 0x61 for a character, while on Linux I get 0xE1. Last 4 bits get received correctly , first 4 are not correct. Somebody pointed out that Linux may be setting 7th bit, which seems to check out -

$ echo "ibase=16;obase=2;E" | bc  
1110


$ echo "ibase=16;obase=2;6" | bc                                               
110

Output of stty :

$ stty -F /dev/ttyUSB0 -a                                                      
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^H; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 100; time = 2;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

Going back to the core of my question : what is the difference between Windows UART and Linux UART connection? In theory , this should work the same, but it is not ! What are the settings that should be changed to make it work ?

Addressing on-topic-ness of the question: As I've stated in the comments and in the /dev/chat , the question ask a specific question and stays well within the bounds:

  • "Using or administering a *nix desktop or server"
  • "UNIX C API and System Interfaces"
  • Since I've tested this on Raspberry Pi as well, it relates to "The underlying *nix OS on an embedded system" topic.

Update

Using python -c 'print("a")' > /dev/ttyUSB0 does work - the board receives bytes which correspond to characters, but alternates between upper and lower case regardless of what i am sending. For instance, printing a will receive 0x61, but c will get 0x43 (upper case C in ascii values). It also ignores input - printing a or A invokes 0x61 always

  • you need to provide more details on exactly how you're using the serial port, including some sample code. Do not add these details or especially code samples in comments, edit your question and add the info/code there. Use the {} icon to format code etc as code. BTW, it's probable that this question is off-topic here and more suited to stackoverflow.com – cas Apr 21 '16 at 11:13
  • @cas sure will edit - i'm not new around here :) As for being on-topic , my questions explicitly asks whether behavior of Windows uart connection is different from uart conection on Linux. This falls under category "Using or administering a *nix desktop or server". Lots of servers use UART , Raspberry ( and other embedded devices ) use serial connection. It also falls under "System Interfaces". My question is also not unclear , I am asking a very specific question: difference in serial connection on *nix and on Windows. – Sergiy Kolodyazhnyy Apr 21 '16 at 23:01
  • Close voters: please see the comment above ^. My question is on topic and not unclear. – Sergiy Kolodyazhnyy Apr 21 '16 at 23:02
  • 2
    Could it have a correlation to Start/Stop bits? – Runium Apr 21 '16 at 23:31
  • @Sukminder I am fairly certain that in both putty and screen I am using single stop bit. Any idea on how I could investigate this as a potential cause of issue ? – Sergiy Kolodyazhnyy Apr 21 '16 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.