6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Sep 20, 2024 4:33 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Feb 05, 2019 1:49 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1228
Location: Soddy-Daisy, TN USA
I have built a crude serial card using the (beloved?..lol) 65C51. Yes, I know...it's not the one to use but it's what I have at the moment.

Previously, I built it on a breadboard and it worked pretty good. That is, with one exception. I had to press Enter twice for it to process the EhBASIC.

For example, if I type:

Code:
PRINT "HELLO"   <enter>


I would see the text in the window...but it didn't RUN it. Pressing Enter a second time would generate the desired effect and I would see the result run ("HELLO").

This was annoying, but I was living with it. I assumed it was a problem with my serial code.

So I put the project on the shelf over the holidays and this last weekend, I decided to dust it off and built a plug-in card instead of the bread board.

The card seems to work pretty well. Receiving text from the SBC works like a treat. But sending text is another story.

On this new plug-in card, I have the original problem above. I have to press Enter twice for it to take.

But now, I have a new problem. Not all of what I type gets sent.

For example, if I type:

Code:
PRINT "HELLO"  <enter>


This is printed:

Code:
PRN


No matter what I type, it only grabs about 3 characters at random from the string. So pressing ENTER a second time generates a syntax error because "PRN" is not a valid command in EhBASIC.

So to recap:

1) Receiving text works 100% as far as I can tell. SBC can send any text over to host PC.

2) I have to press Enter twice for the SBC to receive and process the text I send.

3) Only about 3 characters per line are sent over.


Any ideas?

I've tried running my SBC at both 1 MHz and 4 MHz. 4 MHz is my preferred speed. BTW, when I was on a breadboard, it ran at 8 MHz with only issue #2 above.

Below is my acia.asm listing. I can provide any other info as needed.


Code:

.segment "SERIAL"

MSGL            = $ED
MSGH            = $EE


ACIA            := $5800
ACIA_CTRL       := ACIA + 3
ACIA_CMD        := ACIA + 2
ACIA_SR         := ACIA + 1
ACIA_DAT        := ACIA
TXDATA          := ACIA
RXDATA          := ACIA

INIT_ACIA:
        CLD                     ; Clear decimal arithmetic mode.
        CLI

        PHA                     ; Push A to stack

        LDA     #$1F            ; ACIA to 19200 Baud.
        STA     ACIA_CTRL
        LDA     #$0B            ; No Parity.
        STA     ACIA_CMD

        LDA     #$0D
        JSR     ECHO            ; New line.

        LDA     #<MSG1          ; Setup and print welcome message
        STA     MSGL
        LDA     #>MSG1
        STA     MSGH
        JSR     SHWMSG          ; Show Welcome.

        LDA     #$0D
        JSR     ECHO            ; New line.

        PLA                     ; Restore A

        RTS

ECHO:
        PHA         ; Save A
        AND     #$7F            ; Change to "standard ASCII"
        STA     ACIA_DAT        ; Send it.
        JSR     DELAY1
        PLA                     ; Restore A
        RTS

; Read character from serial port and return in A
GetKey:
        LDA     #$08
RXFULL: BIT     ACIA_SR
        BEQ     RXFULL
        LDA     RXDATA
        AND     #%01111111
        RTS


RDCHR:
        LDA     ACIA_SR         ; Read the ACAI status to
        AND     #$08            ; Check if there is character in the receiver
        BEQ     NOCHAR          ; Exit now if we don't get one.
        LDA     ACIA            ; Load it into the accumulator
        SEC                     ; Set Carry to show we got a character
        RTS                     ; Return
NOCHAR:
        CLC                     ; Clear Carry (no char)
        RTS



SHWMSG:
        LDY #0
@PRINT:
        LDA (MSGL), Y
        BEQ @DONE
        JSR ECHO
        INY
        BNE @PRINT
@DONE
        RTS


MSG1:
        .byte "Welcome to Potpourri6502...", 0

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 05, 2019 2:47 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1466
Location: Scotland
I've not used this chip, so no idea about your initialisation and use code, however are you sure EhBASIC is calling your RDCHR routine and not GetKey ?

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 05, 2019 2:52 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1228
Location: Soddy-Daisy, TN USA
Hmmm. Not really. At the time I had a few things going which included reading a PS/2 keyboard, writing to an LCD screen, serial, and EhBASIC.

I think I'm going to wipe everything out and focus on one section at a time. I think I may have code stepping on each other.

Thanks.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 05, 2019 3:38 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1382
Well, I assume you're using the latest WDC 65C51, which has the transmit bug. This requires that you have a delay after writing a byte to the register before trying to send another byte. The delay needs to be at a minimum the time to send a single character at the baud rate you're using. at 19.2K, that requires at least 521 microseconds. Make sure your delay is at least that.

Also, you don't mention how you're interfacing the 65C51 as a console. Handshake lines need to be properly configured and connected to some terminal program. By default, I use RTS/CTS handshaking with a 5-wire interface:
- Ground, RTS, CTS, TxD, RxD
You can try using ExtraPutty. I've been using it for years and it works flawlessly with the 65C51 when properly configured.

I would also recommend you structure your code differently. Look at a single routine which only initializes the chip and nothing else. You can then have separate routines that read a character and write a character. I can dig out my old code that supports the W65C51 (with the bug) but you'd have to make a few changes to run on your board. Writing a small BIOS could help with debugging and some added flexibility.

Finally, make sure the baud clock is running correctly. If you're using a crystal, ensure you have a 1meg resistor in parallel with it and a 20pf cap to ground as per the datasheet. If you're using a can oscillator, ensure it has adequate power supply bypass and is putting out a stable clock. You can check the baud clock output from the chip directly on pin5 (DIP) after the chip is initialized.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 05, 2019 3:51 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1228
Location: Soddy-Daisy, TN USA
floobydust wrote:
Well, I assume you're using the latest WDC 65C51, which has the transmit bug.


AH! Yeah, that's right. In fact, now that you mention it, I remember looking on the chip a long time ago for the batch number (or something like that) and determined it was the "bad" version. I bet that's it!


floobydust wrote:
This requires that you have a delay after writing a byte to the register before trying to send another byte. The delay needs to be at a minimum the time to send a single character at the baud rate you're using. at 19.2K, that requires at least 521 microseconds. Make sure your delay is at least that.


Will do. I will add that in there when I clean up all of the code.


floobydust wrote:
Also, you don't mention how you're interfacing the 65C51 as a console. Handshake lines need to be properly configured and connected to some terminal program. By default, I use RTS/CTS handshaking with a 5-wire interface:
- Ground, RTS, CTS, TxD, RxD
You can try using ExtraPutty. I've been using it for years and it works flawlessly with the 65C51 when properly configured.


Sorry, I should have mentioned that. For now, I'm just using straight TxD and RxD. I'm not using any hardware handshaking at the moment. In my final design (that will use the NXP), I plan on adding a driver, etc. so that I can interface with some of my legacy equipment that expect real RS-232 interfaces. Thanks for recommending ExtraPutty...I will check that out.



floobydust wrote:
I would also recommend you structure your code differently. Look at a single routine which only initializes the chip and nothing else. You can then have separate routines that read a character and write a character. I can dig out my old code that supports the W65C51 (with the bug) but you'd have to make a few changes to run on your board. Writing a small BIOS could help with debugging and some added flexibility.


Oh, I agree. This isn't my final draft. More of a "slop it together and then clean it up". I learned a long time ago that premature optimization can sometimes prevent you from actually finishing anything. :-)


floobydust wrote:
Finally, make sure the baud clock is running correctly. If you're using a crystal, ensure you have a 1meg resistor in parallel with it and a 20pf cap to ground as per the datasheet. If you're using a can oscillator, ensure it has adequate power supply bypass and is putting out a stable clock. You can check the baud clock output from the chip directly on pin5 (DIP) after the chip is initialized.


Thanks, I will look into that too. I am using a can oscillator. I don't have a cap directly near the can but I will add one for good measure. My ACIA has a cap right under the board about 2mm away from the power pin. Then I have a couple larger caps driving those too. My slots have a large cap as well.

Thanks again!


**EDIT**

A little OT here...but speaking of caps and canned oscillators, I saw a video from the EEVBlog where he opened one up and saw that it had an internal cap or two. Not sure if all of them do...but it was an interesting video.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: