Closing an RS-232 channel

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
srowe
Vic 20 Scientist
Posts: 1338
Joined: Mon Jun 16, 2014 3:19 pm

Closing an RS-232 channel

Post by srowe »

I've recently been rediscovering the various subtle ways of RS-232 connections (like using >=128 for the LFN to get CRLF at the end of a line). One thing I'm still struggling with is checking the transmit queue is empty before closing the channel. The Programmer's Reference Guide says
Care should be taken to ensure all data is transmitted before closing the channel. A way to check this from BASIC is:

100 IF ST=0 AND (PEEK(37151) AND 64)=1 GOTO 100
110 CLOSE lf
I tried this but 37151 never seemed to have the 64 bit set, so the close happened prematurely.

Is there a recommended way to check for an empty transmit queue?
User avatar
Mike
Herr VC
Posts: 4830
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Closing an RS-232 channel

Post by Mike »

Hmm ...

at first it looks like an obvious typo in the PRM. If one masks out 64 from an integer value, the result can only be 0 or 64, therefore this comparison always fails. OTOH, in register 37151, neither bit 0 (value: 1) nor bit 6 (value: 64) are related to RS232. :?

...

Ah! We had this discussed some time ago here: 'Userport Serial programming nonsense'.

...

I dug a bit in the KERNAL. There are two byte pointers into the RS232 transmit buffer, $029D ("one after byte just sent") and $029E ("next free place"). When these two are equal, the KERNAL disables the NMI timer for output instead of transferring the next byte into the byte output buffer. Thus you might try:

Code: Select all

100 IFPEEK(669)<>PEEK(670)THEN100
to check for an empty transmit buffer.

Greetings,

Michael
Last edited by Mike on Mon Jun 30, 2014 2:59 pm, edited 1 time in total.
User avatar
srowe
Vic 20 Scientist
Posts: 1338
Joined: Mon Jun 16, 2014 3:19 pm

Re: Closing an RS-232 channel

Post by srowe »

Ah, thanks. That's the sort of test I expected. I'll update my ROM dump program to use this.
Post Reply