Serial port control question

Nagging hardware related question? Post here!
User avatar
bwinkel67
QL Wafer Drive
Posts: 1187
Joined: Thu Oct 03, 2019 2:09 am

Serial port control question

Post by bwinkel67 »

I'm trying to see if I can connect a FireCracker X-10 module to my QL. It uses a serial port connection but its control depends on changing DTR and CTS as you "bit bang" 40 bits to the device to get it to send a signal.

Some background...X-10 allows for control of house electrical modules that can turn lights and other appliances on and off through the electrical wiring. There has to be a control unit into one outlet, some of which are basically wireless receivers that wait for signals telling it which device on which network to toggle. The FireCracker is a tiny transmitter that plugs into a DB9 serial port but is not RS232. It uses three wires, RTS, DTR, and GND, and expects each bit to be sent with about 50ms pause by toggling the RTS and DTR high low as follows:

Code: Select all

 Signal           RTS   DTR
-----------------------------
 Reset            0     0
 Logical '1'      1     0
 Logical '0'      0     1
 Standby          1     1
 

An example of a signal stream, with about 50ms between each change, would be:

Code: Select all

   Standby | '1' | Wait | '0' | Wait | '1' | Wait...
      _____________________       _____________________
RTS _|                     |_____|
      ________       ___________________       ________
DTR _|        |_____|                   |_____|
And with a 16 bit header and 8 bit footer that never changes, there is 16 bits that you change to send the particular code. Once it receives 40 bits it transmits the appropriate signal to the wireless receiver which then turns on the appropriate device.

So, can one easily control DTR and CTS directly? I'm guessing perhaps a couple of TRAP calls since I doubt you can do it via SuperBASIC. With a normal serial connection the DTR/CTS is controlled by the 8049, indirect to the user, correct?


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Serial port control question

Post by mk79 »

You have two problems there: 1st, every QL ser port only has one outgoing handshake line, you‘d have to combine two ports to get to two. But it doesn’t even matter, because secondly, you don‘t have any software control over these whatsoever, so I‘m afraid what you‘re trying to do is simply impossible with the standard QL serial ports.

If however you‘ve got an original SuperGoldCard or a Sandy SuperQBoard for example, the parallel port on those are perfectly suited for banging bits...

Cheers, Marcel


User avatar
janbredenbeek
Super Gold Card
Posts: 630
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: Serial port control question

Post by janbredenbeek »

bwinkel67 wrote: So, can one easily control DTR and CTS directly? I'm guessing perhaps a couple of TRAP calls since I doubt you can do it via SuperBASIC. With a normal serial connection the DTR/CTS is controlled by the 8049, indirect to the user, correct?
There is no way to control the outgoing DTR/CTS directly, as these are controlled by the IPC.
However, you can bit-bang the TxD output directly by writing the data bit to bit 7 of PC.TCTRL ($18002) with bit 3 holding the serial port number and bit 4 holding zero.
Example:

Code: Select all

; D1=$80 to raise RxD on SER1, 0 to lower it
; D1=$88 to raise TxD on SER2, 8 to lower it
	moveq	#%01100111,d0	; keep bits 0-3 and 5-6
	and.b	$280a0,d0	; get bits from SV.TMOD/SYS.TMOD
	or.b		d1,d0		; mask in bits 3 and 7 from D1 (other bits should be reset!)
	move.b	d0,$18002	; set TxD line
This should of course be done with interrupts disabled, else the transmit interrupt routine might interfere. Thus you will have all the hassles of software-based (delay loops) timing.

It is a not very well documented way to directly control the output line of the serial ports and used by some terminal programs (e.g. QLTerm) to emulate 1200/75 baud split speed in the pre-Hermes days.

Jan.


User avatar
bwinkel67
QL Wafer Drive
Posts: 1187
Joined: Thu Oct 03, 2019 2:09 am

Re: Serial port control question

Post by bwinkel67 »

janbredenbeek wrote: There is no way to control the outgoing DTR/CTS directly, as these are controlled by the IPC.
However, you can bit-bang the TxD output directly by writing the data bit to bit 7 of PC.TCTRL ($18002) with bit 3 holding the serial port number and bit 4 holding zero.
Example:

Code: Select all

; D1=$80 to raise RxD on SER1, 0 to lower it
; D1=$88 to raise TxD on SER2, 8 to lower it
	moveq	#%01100111,d0	; keep bits 0-3 and 5-6
	and.b	$280a0,d0	; get bits from SV.TMOD/SYS.TMOD
	or.b		d1,d0		; mask in bits 3 and 7 from D1 (other bits should be reset!)
	move.b	d0,$18002	; set TxD line
This should of course be done with interrupts disabled, else the transmit interrupt routine might interfere. Thus you will have all the hassles of software-based (delay loops) timing.

It is a not very well documented way to directly control the output line of the serial ports and used by some terminal programs (e.g. QLTerm) to emulate 1200/75 baud split speed in the pre-Hermes days.

Jan.
So then I could substitute the TxD pin for one of the two I need. That still leaves me short the other pin since it needs to be toggled low/high for the other two states. BTW, I do have a Hermes chip, does that give me a leg up on the problem?


User avatar
janbredenbeek
Super Gold Card
Posts: 630
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: Serial port control question

Post by janbredenbeek »

bwinkel67 wrote: So then I could substitute the TxD pin for one of the two I need. That still leaves me short the other pin since it needs to be toggled low/high for the other two states. BTW, I do have a Hermes chip, does that give me a leg up on the problem?
You can use RxD on SER1 (which is the output line, like TxD on SER2).
Hermes has no direct means to control the DTR/CTS line, but the line will go high when you open a serial port and low when you close it. So there might be some way to control the lines by sending an open or close command, but I don't know if the timing will be accurate enough for your use case. Also, there is no guarantee that the lines remain high after an open, even if there is no input data - As far as I remember they might even be oscillating!

Jan


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

Re: Serial port control question

Post by vanpeebles »

I like the idea of someone loading a house control program from an iffy microdrive. All the lights in the house start flashing, and curtains open and close at random :lol:


User avatar
bwinkel67
QL Wafer Drive
Posts: 1187
Joined: Thu Oct 03, 2019 2:09 am

Re: Serial port control question

Post by bwinkel67 »

janbredenbeek wrote:
bwinkel67 wrote: So then I could substitute the TxD pin for one of the two I need. That still leaves me short the other pin since it needs to be toggled low/high for the other two states. BTW, I do have a Hermes chip, does that give me a leg up on the problem?
You can use RxD on SER1 (which is the output line, like TxD on SER2).
Hermes has no direct means to control the DTR/CTS line, but the line will go high when you open a serial port and low when you close it. So there might be some way to control the lines by sending an open or close command, but I don't know if the timing will be accurate enough for your use case. Also, there is no guarantee that the lines remain high after an open, even if there is no input data - As far as I remember they might even be oscillating!

Jan
Wow, that would be a masterpiece if I could create the control for it. Open serial port, push a 0 or 1 to TxD, close serial port --- uh oh, then I couldn't push 0 or 1 anymore on TxD so I guess that won't work since one of the four states would be DTR low and TxD High :-/ I can't believe they chose to do that kind of communication on the X-10 Firecracker...maybe it was cheaper than support an RS232 interface. I just bought a cheap X-10 CM11A that is not wireless but wired instead and does provide an actual serial interlace so I will give that a try (at 4800 bps). Control my house with the QL...we will see :-)

Bummer though since that Firecracker was a nice small attachment out of the back that could send a wireless signal controlled by the serial port (albeit non-standard communication).


User avatar
Pr0f
QL Wafer Drive
Posts: 1298
Joined: Thu Oct 12, 2017 9:54 am

Re: Serial port control question

Post by Pr0f »

Not to undo the good work and thinking going on here - but I seem to recollect an X-10 device with a real RS232 port running at 9600 baud - so just within the capabilities of even a standard QL.

There is CM12, TW-513 and I think that Keene electronics do an X-10 interface with USB, serial and TCP support.


User avatar
Ruptor
Gold Card
Posts: 418
Joined: Fri Dec 20, 2019 2:23 pm
Location: London

Re: Serial port control question

Post by Ruptor »

Pr0f wrote:Not to undo the good work and thinking going on here - but I seem to recollect an X-10 device with a real RS232 port running at 9600 baud - so just within the capabilities of even a standard QL..
Party pooper you have taken all the fun out of the problem. :lol: To not spend any money I would have used one of the PICs I have lying around and knocked up a serial to bit output adapter so the QL could send normal serial commands and the PIC converts them to the required bit sequence, just for fun. :)


User avatar
Pr0f
QL Wafer Drive
Posts: 1298
Joined: Thu Oct 12, 2017 9:54 am

Re: Serial port control question

Post by Pr0f »

Ruptor wrote:
Pr0f wrote:Not to undo the good work and thinking going on here - but I seem to recollect an X-10 device with a real RS232 port running at 9600 baud - so just within the capabilities of even a standard QL..
Party pooper you have taken all the fun out of the problem. :lol: To not spend any money I would have used one of the PICs I have lying around and knocked up a serial to bit output adapter so the QL could send normal serial commands and the PIC converts them to the required bit sequence, just for fun. :)
It all depends on the objective - I have lot of projects that are 'a waste of time' because I could just buy something - but as you say - that's not always the point. PIC's are ideal for little tasks like this - as are the AVR series (don't want to start a fan boy war).


Post Reply