2
\$\begingroup\$

TL;DR: I can open screen or putty session in terminal to the /dev/ttyUSB0, but characters transmitted are invisible. What could be the possible issue ?

I have PICDEM board with PIC18F87J11 and PIC18F8722 microcontrollers, connecting the board through serial to USB cable to my Ubuntu Linux laptop. The code in the microcontroller is supposed to transmit any character typed on the keyboard back to the console. This works alright with Windows 7 computers and putty. With Ubuntu - there is connection established in screen or putty, but the output is invisible - only the cursor continuously moves upon each keypress (which is the same behavior with Window 7).

Doing hexdump reveals the following:

skolodya@ubuntu:$ sudo hexdump -c /dev/ttyUSB0                                 
[sudo] password for xieerqi: 
0000000  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b
*
0001900  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b  \b  \n  \n
0001910  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n

cat /dev/ttyUSB0 reveals that characters are there, except show up in the caret notation, ^H , ^E , like that.

The code on the microcontroller itself doesn't reveal any hints of issue. The char array rxBuffer receives its characters from RCREG1 like so rxBuffer[rxCount] = RCREG1 .

Additional Info(as requested):

Currently the code is spitting out "HelloWorld string" (TXREG1 = txStr[txCount]).

Output of hexdump -C /dev/tty | head -n 10

skolodya@ubuntu:$ hexdump -C /dev/ttyUSB0 | head -n 10                         
00000000  0f 01 17 0f 09 0c 0a 08  15 0c 0c 0f 01 17 0f 09  |................|
00000010  0c 0a 08 15 0c 0c 0f 01  17 0f 09 0c 0a 0f 01 17  |................|
00000020  0f 09 0c 0a 08 15 0c 0c  0f 01 17 0f 09 0c 0a 08  |................|
00000030  15 0c 0c 0f 01 17 0f 09  0c 0a 0f 01 17 0f 09 0c  |................|
00000040  0a 08 15 0c 0c 0f 01 17  0f 09 0c 0a 08 15 0c 0c  |................|
00000050  0f 01 17 0f 09 0c 0a 0f  01 17 0f 09 0c 0a 08 15  |................|
00000060  0c 0c 0f 01 17 0f 09 0c  0a 08 15 0c 0c 0f 01 17  |................|
00000070  0f 09 0c 0a 0f 01 17 0f  09 0c 0a 08 15 0c 0c 0f  |................|
00000080  01 17 0f 09 0c 0a 08 15  0c 0c 0f 01 17 0f 09 0c  |................|
00000090  0a 0f 01 17 0f 09 0c 0a  08 15 0c 0c 0f 01 17 0f  |................|

The output of stty -aF /dev/ttyUSB0

skolodya@ubuntu:$ stty -aF /dev/ttyUSB0                                        
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

Update: Trying out different computer with Ubuntu 14.04 32 bit didn't work either , same result

Update 4/20:

I've placed very simple code into the main :

 while (1) {

        while (!PIR1bits.RC1IF);  //Wait for a byte
        sprintf(txStr,"%X",RCREG1);
        LCDWriteLine(txStr,0);
        continue;

It's supposed to show the hex value of RCREG1 on LCD screen. For a letter typed on keyboard windows produces 61 as expected, but on Linux I get E1. Oddly enough, the last 4 bits are correct regardless of what I type. But for top 4 i get values usually from D to F. So for hex value 62 , I get E2.

\$\endgroup\$
  • \$\begingroup\$ What is the output for hexdump -C that is a capital C? \$\endgroup\$ – jippie Feb 5 '16 at 18:15
  • \$\begingroup\$ What is the output for stty -aF /dev/ttyUSB0? \$\endgroup\$ – jippie Feb 5 '16 at 18:17
  • \$\begingroup\$ This may help troubleshooting: git.linformatronics.nl/gitweb/?p=cat_usbCable;a=summary Fiddle a bit with the settings in lines 31~35. Forget the udev file in that archive, that solves the issue of owners/permissions and naming. EDIT: this doesn't help because the perl script only read from the serial port \$\endgroup\$ – jippie Feb 5 '16 at 18:25
  • \$\begingroup\$ Extra info added as requested \$\endgroup\$ – Sergiy Kolodyazhnyy Feb 5 '16 at 18:28
  • \$\begingroup\$ Looks as if the baudrate isn't set correctly. Are you sure the board is configured for 9600Bd? There should be settings like Baudrate, number of data bits, number of stop bits and parity type. I personally like PuTTY Linux native version to fiddle with these settings until I get them right, don't use Wine with the Windows version. \$\endgroup\$ – jippie Feb 5 '16 at 18:28
4
+25
\$\begingroup\$

It appears that Ubuntu is getting bit7 set in all the characters it receives.

For example: Sending 'a' is 0x61 or 0b01100001 and it is receiving 0xE1 or 0b11100001.

In serial format, bit0 is sent first and bit7 is sent last, so this can happen if your terminal settings are mismatched. For example if the PIC is sending 7 data bits, no parity, 1 stop bit but Ubuntu is expecting 8 data bits, no parity, 1 stop, then Ubuntu will clock in one extra bit and bit7 will always be high.

So make sure your USB-to-serial/terminal settings match the PIC UART settings exactly. Hope that helps. -Vince

\$\endgroup\$
2
\$\begingroup\$

Your stty settings are disabling local-echo (is that what was intended?)

Try using minicom or picocom instead of stty.
You could also try 'screen /dev/ttyUSB0 9600'

\$\endgroup\$
  • \$\begingroup\$ screen /dev/ttyUSB0 9600 is exactly how I am connecting, but no result. Baud rate is 100% correct - I've cheked and rechecked that. Tried minicon but not picocom, will see if that one works. Echo .. . .interesting obvervation . . . I believe I've tried setting local echo, but not 100% sure. Will report if I find out anything \$\endgroup\$ – Sergiy Kolodyazhnyy Feb 10 '16 at 18:51
  • \$\begingroup\$ Made a small edit to my question,please review \$\endgroup\$ – Sergiy Kolodyazhnyy Apr 20 '16 at 19:28
  • \$\begingroup\$ I also believe your terminal settings are mismatched from the target. You are getting data and you know it works with Windows/puTTY. Reading your whole project you do want local-echo disabled. \$\endgroup\$ – Quazil Apr 29 '16 at 16:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.