The serial port is a low-level way to send data between the
Raspberry Pi and another computer system. The Raspberry Pi serial port
consists of two signals, a transmit signals and a receive signal, made
available on the GPIO header. To connect to another serial device you
connect the transmit of one to the receive of the other and vice versa.
You will also need to connect the Ground pins of the two devices
together. For this project two serial converters were used to
connect the USB
port of the Pi and the PC through the null-modem cable.
The Broadcom chip on the Raspberry Pi uses 0V and 3,3V logic
levels. The following parameters were set:
baud rate = 115200
bits = 8
parity = none
stop bit = 1
flow control = none
This was done with the code below:
#define SPEED
B115200
cfsetospeed
(&tty,
SPEED);
// Set output speed
cfsetispeed
(&tty,
SPEED);
// Set input speed
tty.c_cflag =
(tty.c_cflag & ~CSIZE) |
CS8; // 8-bit chars
tty.c_cflag &=
~(PARENB |
PARODD);
// No parity
tty.c_cflag &=
~CRTSCTS;
// No handshake
tty.c_iflag &=
~IGNBRK;
// Disable break processing
tty.c_lflag =
0;
// No signaling chars, no echo, no canonical processing
tty.c_oflag =
0;
// No remapping, no delays
tty.c_iflag &=
~(IXON | IXOFF |
IXANY);
// No xon/xoff ctrl
tty.c_cflag |= (CLOCAL |
CREAD);
// Ignore modem controls, enable reading
tty.c_cflag &=
~CSTOPB;
// Set bit stop
By default the Raspberry Pi’s serial port is configured to be used for console input/output. While this is useful if you want to login using the serial port, it means you can't use the Serial Port in your programs. To be able to use the serial port to connect and talk to other devices, the serial port console login needs to be disabled. There are two files that need to be edited: