Do not provide source communication MODBUS code
MODBUS RTU communication instruction:
Modbus RTU instruction
Baud rate: 96008 NONE 1
/** | |
* 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 |
/** | |
* 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 |
\ 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 ( -- ) |
#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 |
#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 |
#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, |
\ 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 |
#require WIPE | |
NVM | |
20 CONSTANT RXLEN | |
VARIABLE rxbuf RXLEN 2- ALLOT | |
VARIABLE rxpoint | |
VARIABLE tstamp | |
16 CONSTANT TXLEN | |
VARIABLE txbuf TXLEN 2- ALLOT |
Do not provide source communication MODBUS code
MODBUS RTU communication instruction:
Modbus RTU instruction
Baud rate: 96008 NONE 1
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)