Skip to content

Instantly share code, notes, and snippets.

View TG9541's full-sized avatar

Thomas TG9541

View GitHub Profile
@TG9541
TG9541 / solboard.md
Created October 28, 2018 09:01
STM8SxxxKyT6C port assignment
Pin STM	Connected to
-------------------------------------
 1  NRST
 2  PA1        (Y1)
 3  PA2        (Y1)
 4  VSS        digital ground
 5  VCAP       (C)
 6  VDD        power supply
 7 AE3(VDDIO) AE3 (I/O power supply)
@TG9541
TG9541 / C0135-MODBUS-RTU.md
Last active December 21, 2018 17:39
C0135 MODBUS RTU Examples

Examples

Do not provide source communication MODBUS code

MODBUS RTU communication instruction:

Modbus RTU instruction

Baud rate: 96008 NONE 1

@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 / ws2812.fs
Last active September 29, 2023 09:57
STM8 eForth WS2812 LED Strip Demo
\ A STM8 eForth WS2812 demo with tested timing
\ for STM8S w/ 16MHz (HSI) clock
\ 3.3V MINDEV: PB4 with 1K pull-up to 5V works well
\res MCU: STM8S103
\res export PB_DDR PB_ODR PB_CR1
#require ]B!
#require ]CB
#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 / 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 / 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 / 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