using_the_serial_port_march_2013
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
using_the_serial_port_march_2013 [2013/03/14 11:00] – created tomgee | using_the_serial_port_march_2013 [2013/03/14 11:35] (current) – tomgee | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== USE THE SERIAL PORT IN SOFTWARE ===== | ||
+ | By default, the serial port is configured as a console port for interacting with the Linux OS shell. | ||
+ | |||
===== Serial Library ===== | ===== Serial Library ===== | ||
WiringPi includes a simplified serial port handling library. It can use the on-board serial port, or any USB serial device with no special distinctions between them. You just specify the device name in the initial open function. | WiringPi includes a simplified serial port handling library. It can use the on-board serial port, or any USB serial device with no special distinctions between them. You just specify the device name in the initial open function. | ||
Line 56: | Line 59: | ||
man tcgetattr | man tcgetattr | ||
+ | |||
+ | ===== Sample Program ===== | ||
+ | |||
+ | /* | ||
+ | * serialTest.c: | ||
+ | | ||
+ | * the port to be looped back to itself\\ | ||
+ | *\\ | ||
+ | */\\ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main () | ||
+ | { | ||
+ | int fd ; | ||
+ | int count ; | ||
+ | unsigned int nextTime ; | ||
+ | |||
+ | if ((fd = serialOpen ("/ | ||
+ | { | ||
+ | fprintf (stderr, " | ||
+ | return 1 ; | ||
+ | } | ||
+ | |||
+ | if (wiringPiSetup () == -1) | ||
+ | { | ||
+ | fprintf (stdout, " | ||
+ | return 1 ; | ||
+ | } | ||
+ | |||
+ | nextTime = millis () + 300 ; | ||
+ | |||
+ | for (count = 0 ; count < 256 ; ) | ||
+ | { | ||
+ | if (millis () > nextTime) | ||
+ | { | ||
+ | printf (" | ||
+ | fflush (stdout) ; | ||
+ | serialPutchar (fd, count) ; | ||
+ | nextTime += 300 ; | ||
+ | ++count ; | ||
+ | } | ||
+ | |||
+ | delay (3) ; | ||
+ | |||
+ | while (serialDataAvail (fd)) | ||
+ | { | ||
+ | printf (" -> %3d", serialGetchar (fd)) ; | ||
+ | fflush (stdout) ; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | printf (" | ||
+ | return 0 ; | ||
+ | } | ||
+ | |||
+ | ===== Hardware Level Converter Hookup ===== | ||
+ | |||
+ | {{: | ||
+ |
using_the_serial_port_march_2013.1363273231.txt.gz · Last modified: 2013/03/14 11:00 by tomgee