Quantcast
Channel: The Raspberry Pi Hobbyist
Viewing all articles
Browse latest Browse all 60

Raspberry Pi Serial Port

$
0
0
Prototyping the serial port interface.
Many of the GPIO pins on the Pi have other special uses.  The most useful of these are the serial port pins #8 and #10, which are transmit and receive for an RS-232 serial port.  By default this port will output diagnostic messages during boot and then provide a user login.  The configuration is 8 bits, no parity, 1 stop bit, no hardware handshaking, at 115200 baud.  The device name is /dev/ttyAMA0.

I need to use this serial port to interface to my X10 system via a CM11A computer interface module.  That can be a topic for several future posts.

First lets cover some important facts about RS-232 and voltage levels.  The Pi uses levels that are 0V to represent a zero and 3.3V to represent a one.  RS-232 uses -3V to -15V to represent a zero and 3V to 15V to represent a one.  Thus, a level converter is required to create this interface.  The MAX232 series of chips was designed for this exact purpose.

External capacitors are needed to drive the charge pumps inside the chip.  Note: There are several variations of the MAX232 chip which have different requirements.  The one shown in the circuit here uses 0.1uF capacitors.  The ones I have use 1.0uF and some versions even have the capacitors built in.  When in doubt, check the datasheet for the chart that shows the requirements for each variation.
Data Sheet for MAX232 family

If, like me, you want to take complete control of the serial port for your own uses, there are two configuration changes to make:

First, disable the boot up and diagnostic output to the serial port.
sudo vi /boot/cmdline.txt
and remove the two options referring to the serial port.
So, this
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
becomes this
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Second, disable the login prompt
sudo vi /etc/inittab
find the line near the end
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
and delete it or comment it out by putting a # at the start of the line.

Reboot and the serial port will now be free for your exclusive use.

Viewing all articles
Browse latest Browse all 60

Trending Articles