Bonfra wrote:
Yes: receiving data works, the problem is with sending data. I can use another pc to `echo "Hello There" > /dev/ttyUSB0` to the serial port and it's successfully received but when a response is sent back, nothing is caught by `cat /dev/ttyUSB0` (this exact procedure worked with the two machines running Linux).
This could be an issue with the Linux device. Have you configured it properly using
setserial? With FIFO for example it could be that the received bytes are sitting in the queue and not returned by the device. Or that the received bytes are sitting in the kernel buffer, and again, not returned by the device. With "echo" you have explicitly also sent a "\n" which might flush the buffer on the other side, but your code probably doesn't do that.
I'd strongly recommend to install minicom, as others have already suggested.
sudo apt-get install minicom or something. It should be a standard package, no trickery needed to install. One of the many benefits of minicom is that it calls the
termios system calls to configure the serial device in raw, buffer-less mode (also turns off buffering in the kernel for the device). Or you could also use my
raspbootcom.c version, which compiles on a modern Linux without a fuzz and does all that termios setup I've mentioned. By default it prints all bytes it receives, and you don't have to worry about the other things it can do if you don't send 3 times Ctrl+C in a row.
About detection, in my experience many boards which does not have a 16550, and does not emulate it either, will return 0xFF on the status port. It's a good thing to check for that, because normally the status port can never return that value (that would mean byte received, able to receive, send buffer full and send buffer empty all at the same time, which is not possible with real hardware).
Finally about initialization,
this code has been tested on real hardware and known to work, feel free to use it.
Cheers,
bzt