0

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 :)

3
  • Have you tried anything other than the oscilliscope, e.g., a feedback loop (connect tx to rx)?
    – goldilocks
    Apr 30, 2018 at 16:17
  • I am quite familiar with the scope, so I am 99% sure that TX pin just don't do its thing. I can try TX to RX feedback, but I can't understand what this would help/proof. Apr 30, 2018 at 17:01
  • You are using Wheezy, but have obviously also been reading tutorials about current Raspbian - anything posted after mid 2015 is not relevant.
    – Milliways
    May 1, 2018 at 0:09

2 Answers 2

0

If you want to "test" your port you NEED a realistic test program.

It unclear what your missing program does, but serial.write will NOT actually output anything! I will (probably) put 6 characters in the buffer. It doesn't cost any more to output a continuous stream - try writelines.

0

You can try sending data direct to the device:

cp some_file /dev/ttyAMA0

At least that tells you if the UART TX port has not been damaged.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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