-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relays not switching #12
Comments
Kudos back to you forgetting this far! So far, as strange as it sounds, I concentrated on testing the protocol and did little to do the last step, namely implementing the basic I/O functionality for the relay board. Also I had planned to use the new "modular build" to provide configurations for the tiny STM8S001J3 board and for the C0135 relay board. That's easy enough, I just didn't do it. I guess that it's high time that I look at some unfinished things :-) Questions:
|
Thanks for your prompt reply!
|
First step: a C0135 binary with PD1/SWIM console: I used the C0135 board folder and used the following serial interface definition in
Here is the board binary I'm now using:
The next step will MODBUS coils output for C0135 relays. |
When using the C0135 binary from my last comment and the following code at the end of MBSERVER switching relays with qmodmaster works: \ Proto and I/O handler
:NVM
MBPROTO
coils @ out!
;NVM ( xt )
\ --- MODBUS server startup
: MBSERVER ( -- )
0 coils !
( xt ) LITERAL 'IDLE !
; This is my current binary - it worked OK with full-duplex serial and with my own RS485 interface: So far I didn't have any luck with my CH340 based Green+Black RS485 dongle. @tealbrains could you please test if the binary works with your RS485 adapter? EDIT: I just got it working with the "Green+Black" - strange since I didn't change anything. So far there are no errors in scan mode. |
I have been able to test a few things. Here are my findings: [About your first answer]
[Next post]
|
@TG9541 When I issues |
@tealbrains: you're right, the binary you've been using is the old one. I shared two new ones, one "C0135-with-PD1/SWIM-console" and one with "basic MODBUS-with-Relays". I certainly made too many non-communicated assumptions :-) The C0135 I'm now working on is a "board folder" in the STM8EF-MODBUS, and it's not the same as the C0135 in the STM8 eForth repository. The "modular build feature", which is work-in-progress, compiles a fresh board binary instead of using one from the "STM8 eForth Binary Release". You'll have to make some manual steps until the solution is fully automated (help would be appreciated, but I think I can get it done in the next days). Here are the steps that worked for me:
You can skip steps 1 and 2 if you replace the C0135 binary the STM8 eForth with the new C0135 binary in the comment above (this one will provide a PD1/SWIM console). As I said, this is work in progress, I'll finish the "modular build" as soon as the MODBUS features work. I'll push my changes in a bit. |
The commits implement some things that were missing:
Please note that the modular build is yet to be fully implemented. Please use the work-around above. |
@TG9541 I have compiled the binary as per your latest instructions (I had to install sdcc). The eForth terminal works and I am able to control the relays with the I understand that the RS485 uses PD6 for Rx on header so we can't have full duplex for the eForth terminal and have to use the SWIM pin but it looks as if the RS485 is now maybe conflicting with something? |
I have a couple of questions/observations around this update.
|
That's good - at least the compilation works. I'm thinking of doing this with the help of build-automation so that any user can download a ready-made binary for the C0135.
This shows that there is no hardware issue with V1.02. It's more likely something on the Forth side or with the configuration.
Technically it might be possible to have alternating Forth and MODBUS activities, although the only thing I can think of where the console wouldn´t get jammed by MODBUS is PD5-half-duplex mode. I've also been thinking of a console through MODBUS (but so far I had difficulties with the direction control).
As far as hobby applications are concerned the STM8S003 is the same chip as the STM8S103 - only the specs differ. I've yet to see the first one that has less than 640 Bytes EEPROM, or that is dead after 10000 Flash cycles, or that doesn't have the Unique-ID feature. The STM8S103 has some more interesting features if you look closely.
I didn't think of that - that's a problem indeed. You can do the following as a work-around:
What do you think of a "preset feature", e.g. "Press and hold the user key for > 5s" for resetting Node-ID and baud rate? What do you think about a "traditional mapping" of coils/input/holding registers in a holding address space? The EEPROM and the Flash ROM could have a distinct offset. |
I think this is likely too much trouble. It would only make life easy for debugging the application (leaving the programmer connected and having eForth OR Modbus) instead of having to connect/disconnect/connect, etc. Once it is is programmed, if you want Modbus and eForth it just makes sense to use the SWIM pin like you are doing now as it is not used...
I think that is a great idea and would not require any hardware as the board already has buttons. If you chain several nodes you can basically set one at a time this way, then it would be up to the developer to write the new address via the master.
That sounds good too. You can probably limit this to a minimum given the number of pins this board has, something to hold the status of the "Coils" (Relay and LED), something for the spare pins maybe... I think 99% of people would use this just for the relays. |
Please trace it, at least for updating the docs (for some users a console through this pin may also be viable). It would also be possible to have a full-duplex console through PA1-PA2 since the 8MHz crystal is currently unused. I can also think of providing something like DOUBLECOM, where the user can decide which interface to use for the console. That way it would be possible to program the device through the UART and at the end switch the console to PD1/SWIM.
I was thinking of running local control through Forth - the MODBUS master would then interact with something that runs fast, also interactive, logic locally. For example, @bademux had the idea of connecting light switches to the inputs so that relays can be controlled locally without any noticeable delay. The MODBUS master would then read COILS to learn about the new local state and manipulate it as needed. Another example is a local thermostat that receives a set-point through a holding register, and from which the MODBUS master could collect data. The beauty of such solutions is that they provide the basic feature even if the master or the connection has issues. Spouses and other significant stakeholders of home automation will appreciate reliable performance ;-) |
Yes I can see why there would be value there. I have just probed the board to see where the "DAT" labeled pin is going, and it goes to VCAP (pin 8). So no use for it as GPIO... I am not even sure why they would have it exposed and labeled as such. Maybe there is another uC in the family that actually has a GPIO instead of VCAP? |
@tealbrains: the only explanation I can offer is that the designers of the relay board prepared for using the Nuvoton MCS-51 style chip. That "pin-compatible component" has an extra GPIO in place of the STM8S Vcap. I hope that they won't use it since without a hot-air rework tool the µC would be very difficult to replace. I've got the modular build working. A minor adjustment will be needed to the STM8 eForth build tools to make it work with multiple board folders. Will push that shortly. By the way, what's your time zone? |
Deploying in GitHub Releases works - almost. I need to update the credentials (later on). @tealbrains: running |
@TG9541 Sounds great! I will be testing in the morning and report. My timezone is AEST :) |
There was a fat bug in one of the scripts of STM8 eForth which broke If you already made a I just tested the C0135 binary in releases - it works for me. |
I tested the new release (building from code) and most things seem to work. Here are my observations:
|
What works for me is a simple wired-or of the ST-Link SWIM pin and the serial interface 2-wire-hack-device (i.e. TXD sink-only with diode). I should have mentioned that. It's surprising that communication doesn't work. Would you mind giving the hex file in the releases a try? Please enter the following before testing with "Node-ID 1": ULOCK
1 $4000 !
0 $4002 !
LOCK I also tested with 19200 baud and different Node-IDs (qmodmaster sometimes needs to be reminded of settings). |
@TG9541 I should have added a second wire straight to SWIM when I added that diode + wire.. for the other direction. Entering the commands to set the slave address worked (sorry I forgot about this step!). Modbus is now working as expected! Thanks :) I tested all relays and LED. I will probe the pins tomorrow with the analyser to check the timings are correct (compared to the original firmware of the board) and will be able to proceed with my Modbus master development using this board as a tool for it. After that it will probably get repurposed for some home automation project :) You will probably polish a few things here and there but for me this is good enough :) Let me know if you need any extra feedback. |
@tealbrains that's great to hear - thanks for patience and support :-) I'm looking forward to timing test results! I'll close this issue now and open a new issue for the next steps. On my list are better support for a traditional MODBUS address space, node-id and baud rate init, maybe a blinkenlights for node hit, miss and CRC error, and certainly more docs. |
@TG9541 Just checked timing. It works! The original firmware would receive commands from my master fine but the reply would be out of whack. Your implementation of modbus works great. |
@tealbrains thanks! This reminds me of a test I did before starting this project: That issue there contains some points that might be interesting for you :-) |
Hi Thomas,
I know pretty much next to nothing when it comes to eForth. I did not know what it was until a couple of days ago when I was trying to see if there would be a better firmware for the 4 relay board (it seems the newer ones have a "DAT" pin next to "SWIM" pin and are labelled "v1.2", mine has an STM8S003F3 on it).
Kudos for all the great work!
Now to my problem:
I have flashed the device and loaded the modbus files of this repo successfully after doing that diode mod.
My terminal application on the PC can talk to the device via a USB-RS485 adapter, but the "Write Single Coil" function is not activating the relays. Is there anything extra that needs to be done after the "make load" to get them working?
I don't think I will be diving too deep into eForth, I just needed a good reliable firmware that would respect the timings of modbus RTU the original firmware was completely ignoring.
Any ideas?
The text was updated successfully, but these errors were encountered: