I have read quite a lot of tutorials and tips about the issue, but serial port just doesn't work. There has to be some configuration that I have missed.
The setup
Raspberry Pi 1 Model B (oldest revision, with Ethernet port)
pi@raspberrypi ~ $ cat /etc/*-release
PRETTY_NAME="Raspbian GNU/Linux 7 (wheezy)"
NAME="Raspbian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
I used python to send some random data to serial port while scoping TX pin with my oscilloscope. TX pin was always high.
Python snippet:
import serial
port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=3.0)
port.write("qwerty")
Done so far
I modified cmdline.txt so that ttyAMA0 won't be used for serial console
pi@raspberrypi ~ $ cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline rootwait
I also commented out ttyAMA0 form inittab
pi@raspberrypi ~ $ cat /etc/inittab | grep ttyAMA0
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Finally I modified /boot/config.txt by adding line "enable_uart=1" which should make sure that serial port pins are in correct mode after boot. This was double checked with gpio.
pi@raspberrypi ~ $ gpio readall
+-----+-----+---------+------+---+-Model B1-+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | ALT0 | 1 | 3 || 4 | | | 5v | | |
| 3 | 9 | SCL.1 | ALT0 | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 0 | 7 || 8 | 1 | ALT0 | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | ALT0 | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | IN | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | IN | 0 | 23 || 24 | 0 | IN | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 0 | IN | CE1 | 11 | 7 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+-Model B1-+---+------+---------+-----+-----+
ttyAMA0 is present
pi@raspberrypi ~ $ ls -l /dev | grep ttyAMA0
crw-rw---T 1 root dialout 204, 64 Jan 27 08:42 ttyAMA0
And user is in dialout group
pi@raspberrypi ~ $ groups
pi adm dialout cdrom sudo audio video plugdev games users netdev i2c input indiecity spi gpio
I can switch serial port pins high and low with GPIO-library, so they are working electrically.
I would appreciate any help.
Solved
It turned out that my test was just bad. Serial port was probably working all the time.
First I copied file to dev/ttyAMA0 and scoped it. Port was working as expected.
Next I put feedback link from TX to RX and made small Python program that wrote text continously to serial port and read the input buffer at the same time. I got text back as expected. I also saw data in the scope.
Lessons learned: use proper test scripts or stand alone program for testing.
Thanks for the help and sorry for the hassle :)