%DASHBOARD{ section="dashboard_start" }% %DASHBOARD{ section="banner" image="%PUBURLPATH%/Cosmac/ForthSTM32WB/nucleo-header.jpg" title="Terminal IO (Serial Communication)" titlestyle="color:#F00000;" }% %DASHBOARD{ section="box_start" title="Intro" width="485" height="250"}% ---+ Intro To work with a Forth system you need some kind of a [[https://en.wikipedia.org/wiki/System_console][console]]. A text [[https://en.wikipedia.org/wiki/Computer_terminal#Text_terminals][terminal]] with [[https://en.wikipedia.org/wiki/RS-232][RS-232]] port has been used for this purpose in the past, today's PCs have software to emulate terminals but have no more any RS-232 interface. But there are usually USB interfaces instead. The [[https://en.wikipedia.org/wiki/USB_communications_device_class][USB-CDC]] appears as a traditional RS-232 port in your operating system (Linux =/dev/ttyACMx=, Windoze =COMx=). No need to bother with baud rates, handshaking, parity and other awkward things. %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" title="Contents" width="460" height="250"}% %TOC% %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="300" }% ---+ Terminal-IO Default console is USB-CDC, but if you press button SW2 on reset, the console is redirected to the UART [[https://en.wikipedia.org/wiki/RS-232][RS-232]] serial device (for details see [[https://github.com/spyren/Mecrisp-Cube/blob/master/Forth/cube/mecrisp.s][mecrisp.s]]). If you press button SW1 on reset, the console is redirected to the Bluetooth LE Cable Replacement Service. <pre> emit? ( -- Flag ) Ready to send a character? key? ( -- Flag ) Checks if a key is waiting key ( -- Char ) Waits for and fetches the pressed key emit ( Char -- ) Emits a character hook-emit? ( -- a-addr ) Hooks for redirecting terminal IO on the fly hook-key? hook-key hook-emit uart ( -- ) redirect console to serial interface (UART) cdc ( -- ) redirect console to USB-CDC crs ( -- ) redirect console to BLE CRS </pre> <pre> : ascii ( -- ) 127 32 do i emit loop ; : crs-ascii ( -- ) 127 32 do i crs-emit loop 10 crs-emit / LF ; </pre> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="300" }% ---+ USB-CDC Serial Communication (API) Buffered USB-CDC serial communication. The [[https://en.wikipedia.org/wiki/USB_communications_device_class][USB-CDC]] appears as a traditional RS-232 port in your operating system (Linux =/dev/ttyACMx=, Windoze =COMx=). No need to bother with baud rates, handshaking, parity and other awkward things. <pre> cdc-emit ( c -- ) Emits one character to the USB-CDC interface. Blocking if the Buffer is full. cdc-key ( -- c ) Waits and gets one character from the USB-CDC interface. Blocking if the buffer is empty. cdc-emit? ( -- ? ) Ready to send a character. Buffer is not full. cdc-key? ( -- ? ) Checks if a character is in the buffer. </pre> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="300" }% ---+ UART Serial Communication (API) <pre> serial-emit ( c -- ) Emits one character to the UART interface. Blocking if the Buffer is full. serial-key ( -- c ) Waits and gets one character from the UART interface. Blocking if the buffer is empty. serial-emit? ( -- ? ) Ready to send a character. Buffer is not full. serial-key? ( -- ? ) Checks if a character is in the buffer. baudrate! ( u -- ) sets baud rate (e.g. 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, <b>115200</b>) paritybit! ( u -- ) sets parity bit <b>0 none</b>, 1 odd, 2 even wordlength! ( u -- ) sets word length 7, <b>8</b>, 9 (including parity) stopbits! ( u -- ) sets stop bits <b>0 1 bit</b>, 1 1.5 bit, 2 2 bit </pre> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="300" }% ---+ BLE Cable Replacement Serial Communication (API) https://spyr.ch/crs-terminal/ <pre> crs-emit ( c -- ) Emits one character to the UART interface. Blocking if the Buffer is full. crs-key ( -- c ) Waits and gets one character from the UART interface. Blocking if the buffer is empty. crs-emit? ( -- ? ) Ready to send a character. Buffer is not full. crs-key? ( -- ? ) Checks if a character is in the buffer. </pre> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="300" }% ---+ Terminal Emulators Terminal emulator applications for PCs, e.g.: * [[http://www.putty.org/][PuTTY]] - Windows and Linux * [[http://en.sourceforge.jp/projects/ttssh2/][Tera Term]] - Windows * [[http://realterm.sourceforge.net/][Realterm]] - Windows * minicom, microcom, CuteCom, screen - Linux %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="dashboard_end" }% -- %USERSIG{PeterSchmid - 2020-04-20}% ---++ Comments %COMMENT%
This topic: MecrispCube
>
WebHome
>
TerminalIO
Topic revision: r9 - 2020-05-21 - PeterSchmid
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback