![]() |
| Prototyping the serial port interface. |
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.

thanks for sharing.
ReplyDeleteHow can I listen for data on AMA0 in the console without any other scripts?
ReplyDeleteNeed to stop OS from using the serial port as described in the post.
ReplyDelete(Feel free to use nano in place of vi as the editor.)
Then set baud rate with command like:
sudo setserial /dev/ttyAMA0 baud_base 9600
The you could do something as simple as
cat /dev/ttyAMA0
and any data from the serial port would echo on the console.
Hopefully not binary data, and line feeds (or a lack of them) can be a problem to readablility.
Press Ctrl-C to stop
If you want a full terminal emulator on the console, you could use minicom.
If you are on X you could use gtkterm.
Hy,
ReplyDeleteCould you explain more about the purpose of the capacitors?
I would use this IC http://sk.fotoarchiefje.nl/Datasheets/max232.pdf
Does that mean it has built in capacitors and i don't need to use extra ones?
That is the typical MAX232 chip and does need capacitors.
DeleteThe chip has to take 5V and produce +15V and -15V. In reality, it will typically only produce around 9V.
The chip uses a circuit called a "charge pump" to achieve this.
Capacitors are needed to store the additional charge required for this circuit.
MAX232 chips are intended for 5V circuits. Since the Raspberry Pi is a 3.3V device, a better choice would be the MAX3232 chip, which will work for 3.0 to 5.5V
There are versions of the MAX232 that have built in capacitors. Also, some versions use external 1uF caps while others use 0.1uF caps.Check the data sheet for whatever chip you use to be sure you have it right. Using larger caps than required is OK.
And the MAX3232 chip needs to be powered from the 3.3 Volt GPIO pin 1 NOT 5V.
Delete"which will work for 3.0 to 5.5V"
DeleteIt will work from either for power.
However, the data pins are 3.3V so you don't need level convertors.
Thanks for posting this! It's just what I was looking for.
ReplyDelete