writing and reading a binary word on some pins

If doesn't fit into any other category ....
its1000
Posts: 76
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 3 times
Been thanked: 1 time

Re: writing and reading a binary word on some pins

Post by its1000 »

Thank you. I won’t have any audio signal in the same cable so no issue with this I hope

With this program does the slave will accept the value only when it wants? Because the salve may be ready to « learn » the variables values after master is ready to tell. That’s why I thought I had to initiate the « send me the var values » from the slave to the master to be sure the slave is not doing something else
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: writing and reading a binary word on some pins

Post by BeanieBots »

Not knowing more about what each device is doing and how critical any timing is, it is hard to give firm advice.
So, we'll keep plugging away until you have something you are comfortable with and does what you want.
There is 'onserial' which will make it automatically stop what it's doing and then service the incomming serial data. Maybe that is an option?
It can be on either of or both the slave and master.
"bugs" points out some good advice about other stuff which can come over serial such as boot information, error messages and any print statements.
It's not hard to cope with this but let's get your architechture sorted first and worry about details later.
So, do you really want the slave to request the data or is it OK for the slave to (automatically) respond to the master when it sends something?
It really doesn't matter (from a programming perspective) which way you do it, so just pick a preference knowing that either way is possible and there is no real difference in complexity.
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: writing and reading a binary word on some pins

Post by Electroguard »

If you have 2 spare devices available, use them to test serial communications without messing with your existing.
If you have any problems with hardware serial receiving system messages then use software serial2 instead, but that will use up 2 extra pins.
If using hardware serial, change all references of serial2 to serial

This is not tested, its just off the top of my head to point you in the serial direction.
Obviously serial2.chr$ would be triggered by every incoming character, so presumably serial2.input$ should be triggered by an incoming CR or LF, but I seem to remember there may be something peculiar about it, so you will need to check.
Either way, you would wait for a complete incoming string terminated by CR or LF then save it as msg$.
Both master and slave can be the same, it's just that the master will check if the incoming message is "send" and send the appropriate vars, whereas the slave will turn error checking off while it evalutes the incoming msg$, which will either be actioned if valid, or ignored if invalid.
You will need to arrange for the "send" trigger to be sent to from the slave to the master, so only uncomment the timer0 on the slave.

serial2.mode 9600, 4, 5
onserial2 incomingmsg:
'timer0 5000, triggerMASTER

incomingmsg:
msg$=SERIAL2.INPUT$ 'Returns all the characters present in the input buffer of the serial port #2
wlog msg$
IF (INSTR(msg$,"send") <> 0) THEN
GOSUB SEND 'If msg$ contains "send" trigger from SLAVE then branch to send vars
msg$=""
ELSE
ONERROR SKIP
COMMAND msg$
msg$=""
ENDIF
return

SEND:
'wlog "sending variables to slave"
serial2.print "var1=" + str$(var1)
serial2.print "var2=" + str$(var2)
return

triggerMASTER:
'wlog "sending SEND trigger to master"
serial2.print "send"
return
its1000
Posts: 76
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 3 times
Been thanked: 1 time

Re: writing and reading a binary word on some pins

Post by its1000 »

thank you to all for your help.
I am pretty deciced with what I want to do.

at this step I am in the planing phase to determine what I will do with my various esp in both PSU and monoblocs, I am designing and testing each function I want to do with my programm, I test it individually and i will assemble all in one big program once I have validated each.
thanks to you in an old post, I control the color screen and I can screen whatever I want, I also solved keeping my counters in a file for lamp life duration, and I know how to correctly use timers...

my last subject was this communications between various annex, without using wireless wifi communication.
it is clear that serial com allows me to do nearly everything and transfering much more information than just a simple state of some pins...

So I will preferably use the serial communication, and if I don't succeed doing what I want I will use binary word as described by Ciccio and reduce what i transfer from master to slave..

I have to be carrefull with the timer, because I may need them for another usage in the program.
I have enough cables available to manage at the same time tx and rx from master to both slaves.

the only thing i need to test and manage, is the moment when master send info to slave or slave asks master to send it to him, to avoid having master sending it and master not being ready.
but it's a very interesting exercise to do!
I am currently on hollydays, with some esp and small hardware I will have time to do some testing
.
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: writing and reading a binary word on some pins

Post by BeanieBots »

Glad you are getting there.
I think Electroguard has given you enough to get started with serial comms.
If not, speak up and he or I (or others) can give you some more pointers.
Don't worry about "using up" timers. With a few tricks you can have as many as you want 8-)
Post Reply