GithubHelp home page GithubHelp logo

kyolaing / rpirtscts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mholling/rpirtscts

0.0 0.0 0.0 31 KB

Enable hardware flow control signals on the Raspberry Pi serial port.

License: GNU General Public License v3.0

C 95.82% Makefile 4.18%

rpirtscts's Introduction

rpirtsrtc

rpirtscts is a simple linux command for enabling the hardware flow control pins for the ttyAMA0 serial port on the Raspberry Pi.

Hardware Flow Control & the Raspberry Pi

Hardware flow control can be used with RS-232 serial ports to co-ordinate data transmission between the data terminal equipment (DTE) and the data circuit-terminating equipment (DCE). In our case, the Raspberry Pi is the DTE, and the serial peripheral the DCE. Flow control is useful when data coming from the DTE has the potential to overflow the buffer in the DCE, or vice-versa.

Two distinct handshake signal, known as RTS (Request to Send) and CTS (Clear To Send) are used to implement hardware flow control. RTS is asserted by the DTE (the Raspberry Pi) to indicate to the serial peripheral that it is able to receive data. Conversely, CTS is asserted by the peripheral to indicate its readiness to receive data. The peripheral de-asserts CTS to indicate that it has no buffer space left to receive further data. The serial driver on the Raspberry Pi will automatically pause data transmission until the peripheral re-asserts the CTS signal.

On the Raspberry Pi (except the revision 1 model B), an unpopulated header, P5, brings out RTS and CTS. The signals are implemented as alternate functions of GPIO30 and GPIO31, which can be found on pins 5 and 6, respectively, of the header. (Pay close attention to the location of these pins; the mirrored numbering reflects the header's default position on the underside of the board.) By soldering your own header, you can access RTS and CTS for use with your serial peripheral. Note that they are 3.3V, active-low logic signals.

Newer Raspberry Pi boards have a 40 pin GPIO header replacing the 26 pin and P5 headers. This requires switching the GPIO which support CTS and RTS to GPIOs 16 (pin 36 on 40 pin header) and 17 (pin 11) respectively. rpirtscts will attempt to detect the model of the Raspberry Pi and configure the appropriate GPIOs.

This code implements a simple program to enable the alternate functions on GPIO30 and GPIO31 (or GPIO16 and GPIO 17), thereby enabling the RTS and CTS flow control signals to be used along with the data signals TXD and RXD located on the GPIO header P1.

Usage

Building the program is simple. You will need gcc, make and git. (Depending on the Linux distribution you're using, these packages may or may not come pre-installed.) From the command line, download the code:

git clone git://github.com/mholling/rpirtscts.git

This will create a directory containing the files. Next, enter the directory and build the executable:

cd rpirtscts
make

All going well, an rpirtscts executable will be built. The command takes a single option, either on or off, to respectively enable or disable the flow control pins. Running it requires root permissions, so:

sudo ./rpirtscts on

Any other invocation produces a short usage description.

It is also possible to alter file permissions so that sudo is not necessary:

sudo chown root rpirtscts
sudo chmod 4755 rpirtscts

Finally, you will need to instruct the serial port driver to use the hardware flow control signals. This is a simple matter:

stty -F /dev/ttyAMA0 crtscts

(With /dev/ttyAMA0 being the character device for the Raspberry Pi serial port.)

rpirtscts's People

Contributors

mholling avatar cbst avatar tobiasvogel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.