Last active
December 27, 2018 21:07
-
-
Save TG9541/25a0d8e2e68e42d08ecec13c7e9a9981 to your computer and use it in GitHub Desktop.
WIP: STM8 eForth MODBUS node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#require WIPE | |
NVM | |
20 CONSTANT RXLEN | |
VARIABLE rxbuf RXLEN 2- ALLOT | |
VARIABLE rxpoint | |
VARIABLE tstamp | |
16 CONSTANT TXLEN | |
VARIABLE txbuf TXLEN 2- ALLOT | |
VARIABLE txpoint | |
RAM WIPE | |
\res MCU: STM8S103 | |
\res export UART1_DR UART1_CR2 INT_UARTRX | |
\res export PB_DDR PB_ODR | |
#require :NVM | |
#require ]B! | |
#require 'IDLE | |
NVM | |
#require CRC16 | |
: put ( c -- ) | |
rxpoint @ DUP rxbuf - RXLEN < IF | |
SWAP OVER C! | |
1+ rxpoint ! THEN ; | |
:NVM | |
SAVEC | |
UART1_DR C@ put | |
TIM tstamp ! | |
IRET [ OVERT INT_UARTRX ! | |
: nack ( -- ) ; | |
: rxoff ( -- ) | |
[ 0 UART1_CR2 5 ]B! ; | |
: rxon ( -- ) | |
[ 1 UART1_CR2 5 ]B! ; | |
: rxres ( -- ) | |
rxbuf rxpoint ! ; | |
: bufdump ( -- ) | |
rxbuf rxpoint @ OVER - DUMP ; | |
: OUT! ( f -- ) | |
0= PB_ODR 5 B! ; | |
: process ( -- ) | |
BASE @ HEX | |
rxpoint @ 2- ( a ) | |
-1 ( CRC seed ) OVER rxbuf ( -1 a a ) DO | |
I C@ DUP . CRC16 | |
LOOP | |
( a CRC16 ) . ( a ) @ ( CRC-LE ) EXG ( CRC ) . CR | |
BASE ! ; | |
: itask ( -- ) | |
rxbuf rxpoint @ - IF | |
1 OUT! | |
3 TIM tstamp @ - < IF | |
process | |
bufdump | |
rxres | |
THEN | |
0 OUT! | |
THEN ; | |
: rxinit ( -- ) | |
1 PB_DDR 5 B! | |
rxres rxon | |
[ ' itask ] LITERAL 'IDLE ! ; | |
RAM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem with MODBUS RTY reception of 0x00 bytes fixed (?RX ignores them!).