Skip to content

Instantly share code, notes, and snippets.

View TG9541's full-sized avatar

Thomas TG9541

View GitHub Profile
#include <stdio.h>
typedef unsigned short WORD;
typedef unsigned char BYTE;
WORD CRC16 (const BYTE *nData, WORD wLength)
{
static const WORD wCRCTable[] = {
0X0000, 0XC0C1, 0XC181, 0X0140, 0XC301, 0X03C0, 0X0280, 0XC241,
@TG9541
TG9541 / modbus-rxtest.fs
Last active December 27, 2018 21:07
WIP: STM8 eForth MODBUS node
#require WIPE
NVM
20 CONSTANT RXLEN
VARIABLE rxbuf RXLEN 2- ALLOT
VARIABLE rxpoint
VARIABLE tstamp
16 CONSTANT TXLEN
VARIABLE txbuf TXLEN 2- ALLOT
@TG9541
TG9541 / RS485DE
Created January 2, 2019 08:04
TM8 eForth MODBUS - stubs for bus media access
\ STM8 eForth MODBUS stubs for bus media access
\res MCU: STM8S103
\res export PB_ODR PB_DDR
#require ]B!
NVM
\ Set RS485 Driver to "RX"
: RS485rx ( -- )
@TG9541
TG9541 / SerialCoilsTest.java
Created January 2, 2019 16:34
CLI test for MODBUS RTU FC01 "Read Coils" with JAMOD
/**
* Copyright 2002-2010 jamod development team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@TG9541
TG9541 / SerialDOTest.java
Created January 2, 2019 16:35
CLI test for MODBUS RTU FC05 "Write Single Coils" with JAMOD
/**
* Copyright 2002-2010 jamod development team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@TG9541
TG9541 / MBTEST
Last active January 2, 2019 16:55
Minimal MODBUS test program
#require MBCRC
#require 'IDLE
VARIABLE coils
: process ( -- )
rxp @ 2- ( a1 ) DUP rxbuf ( a1 a1 a0 ) MBCRC
( a1 crc-le ) SWAP @ =
CR CR
( crc-ok ) IF
@TG9541
TG9541 / MBCRC
Created January 2, 2019 16:56
STM8 eForth dependencies of MBTEST
#require UARTISR
#require CRC16
#require WIPE
NVM
: mbslv ( -- c )
rxbuf C@
;
: mbfc ( -- c )
@TG9541
TG9541 / MBPROTO
Created January 5, 2019 23:44
MODBUS protocol implementation
#require UARTISR
#require CRC16
#require ]B!
#require WIPE
NVM
: mbslv ( -- c )
;
\ get MODBUS FC
@TG9541
TG9541 / UARTISR
Last active January 6, 2019 13:01
STM8S buffered UART implementation with support for RS485 flow shared medium
#require WIPE
NVM
20 CONSTANT RXLEN
VARIABLE rxbuf RXLEN 2- ALLOT
VARIABLE rxp \ receive xfer pointer in ISR
VARIABLE tstamp \ receive timestamp
20 CONSTANT TXLEN
VARIABLE txbuf TXLEN 2- ALLOT
@TG9541
TG9541 / USBaspLoader-for-USBasp.hex
Created January 12, 2019 11:05
An USBaspLoader modified to work on a USBasp dongle. Plug in with JP1 closed to start in USBaspLoader mode. Of course, the USBasp firmware can be loaded onto the USBasp with the USBaspLoader :-)
:101800004BC07FC064C063C062C061C060C05FC0C5
:101810005EC05DC05CC05BC05AC059C058C057C0F4
:1018200056C055C054C00000EC2DFD2DB7B6B0FC1D
:10183000FDCF27BFE895B7B6B0FCFDCF21E1B7B625
:10184000B6FCF4CF089509021200010100803209AC
:10185000040000000000000012011001FF00000859
:10186000C016DC050201010200010E035500530001
:1018700042006100730070001C037700770077005E
:101880002E00660069007300630068006C002E0083
:10189000640065000403090411241FBECFE5D4E0F1