TG9541 / stm8ef-modbus

A lightweight framework for MODBUS RTU nodes in STM8 eForth that can do more than just I/O
https://github.com/TG9541/stm8ef/wiki/Board-C0135
MIT License
32 stars 12 forks source link

Support board "modbus_relay8" #40

Open TG9541 opened 3 years ago

TG9541 commented 3 years ago

A MODBUS board with the name "modbus_relay8 v1.2" arrived a few days ago: image It has an STM8S103K3T6C, an LM2596-5V switching power supply (7..30V, 2-3A), 8 relays and 8 insulated inputs. The usual price is at $15.

I made a Gist with Forth code for I/O based on SWIMCOM. GPIOs for I/O are documented in the code.

Other GPIOs traced so far are:

GPIO usage
PA1 Q (crystal not populated)
PA2 Q (crystal not populated)
PB6 S2 (key)
PB7 LED (not populated)
PD7 RS485 direction
TG9541 commented 2 years ago

This works with the latest deferred BUSCTRL:

\ STM8EF-MODBUS eForth RS485 bus control for RS485 board RelayX8 

\res MCU: STM8S103
\res export PD_ODR PD_DDR PD_CR1

#require ]B!

NVM
  \ Set RS485 Driver to "RX"
  : rx ( -- )
    [ 0 PD_ODR 7 ]B!
  ;

  \ Set RS485 Driver to "TX"
  : tx ( -- )
    [ 1 PD_ODR 7 ]B!
  ;

  \ Initialize GPIO and RS485 Driver
  : CTRL ( -- )
    BUSrx
    [ 1 PD_DDR 7 ]B!
    [ 1 PD_CR1 7 ]B!
  ;

  ' rx is BUSrx
  ' tx is BUStx
  ' ctrl is BUSctrl
RAM