6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed May 15, 2024 3:20 am

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Wed Dec 07, 2022 8:02 pm 
Offline

Joined: Mon Oct 03, 2022 9:44 pm
Posts: 26
Hello, I'm working on a PCB Design for my 8-Bit 6502 computer Project. I want a Serial Port connected to a 6522 VIA. I want the serial Port to connect to a modern Computer for a Keyboard, to send 6502 Assembly code files directly into the CPU's memory and to troubleshoot the Computer easily. However, I'm confused on exactly how I can connect the 9 Pins of a Serial Port to a 6522 Via's 8-Bit I/O pins and I have some other questions that I have. Here is a Small list of questions I have.

  • how I can connect the 9 Pins of a Serial Port to a 6522 Via's 8-Bit I/O pins?
  • Are there any Serial Interface ICs that's compatible with the 6502 CPU I should use instead of the 6522?
  • The feature I want where I can directly send 6502 Assembly code into the CPU's ROM chip, Is that even Possible?

Any help and Advice will appreciated and thanked in Advance!


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 07, 2022 9:53 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8183
Location: Midwestern USA
PC Building Yoshi wrote:
Hello, I'm working on a PCB Design for my 8-Bit 6502 computer Project. I want a Serial Port connected to a 6522 VIA. I want the serial Port to connect to a modern Computer for a Keyboard, to send 6502 Assembly code files directly into the CPU's memory and to troubleshoot the Computer easily. However, I'm confused on exactly how I can connect the 9 Pins of a Serial Port to a 6522 Via's 8-Bit I/O pins and I have some other questions that I have. Here is a Small list of questions I have.

  • how I can connect the 9 Pins of a Serial Port to a 6522 Via's 8-Bit I/O pins?
  • Are there any Serial Interface ICs that's compatible with the 6502 CPU I should use instead of the 6522?
  • The feature I want where I can directly send 6502 Assembly code into the CPU's ROM chip, Is that even Possible?

Any help and Advice will appreciated and thanked in Advance!

I recommend you use a UART for this purpose. While the 6522 does have a serial shift register feature, it isn’t designed to communicate with a standard TIA-232 serial port, such as on a PC.

The 65C51 UART will directly interface to the 6502 bus, however the WDC version has a serious hardware bug that complicates use of the transmitter in an efficient manner. There are workarounds for the problem, as well as other UARTs that can be used, which information you should be able to find with the forum search functions.

Meanwhile, I strongly recommend you study Garth’s build-a-6502-computer write-up in its entirety before making any design decisions.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 08, 2022 1:28 pm 
Offline
User avatar

Joined: Tue Oct 25, 2016 8:56 pm
Posts: 360
As BDD said, the VIA is not the right chip for this task. You probably could bit-bang a serial port on a VIA, but it'd be a lot of hassle and software writing. You're much better off getting a dedicated UART chip.

Also, it may just be a misunderstanding on a point of nomenclature, but in case it really is an issue:

You cannot upload assembly code directly into a 6502 computer and expect it execute, without having a significant amount of software already running on the machine: firstly to handle the Serial communication part, and secondly to assemble the assembly code into machine code for execution. This code will have to already be on the computer at boot (in an EEPROM, for example), or you'll need some kind of fancy way of loading into the RAM before you let the CPU loose on it (such as by connecting a separate microcontroller to handle the boot process).

Realistically you'll want to assemble some basic routines (such as serial port support!) first using an assembler on your PC, then burn them into an EEPROM. attach that to your 6502 computer (SBC). Once you have that in place, you can now talk to your SBC over Serial and download more machine code into it (not raw assembly code - the machine code you get out of the assembler).

If you really, really do mean you want to be able to boot from code sent over serial on a ROM-less 6502 computer, there's a topic where we discussed methods of doing this at some length: http://forum.6502.org/viewtopic.php?f=4&t=6841. However, I would not recommend this as a starting point for your first build. As BDD said, have a look at Garth's how-to guide.

_________________
Want to design a PCB for your project? I strongly recommend KiCad. Its free, its multiplatform, and its easy to learn!
Also, I maintain KiCad libraries of Retro Computing and Arduino components you might find useful.


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 08, 2022 2:00 pm 
Offline
User avatar

Joined: Fri Nov 09, 2012 5:54 pm
Posts: 1394
True.

And please take a look at Daryl Rictor's SBC-2.

If you would be building your 6502 computer in a way that it has a SBC-2 compatible memory map,
you simply could use the SBC-2 monitor program as a starting point.

BTW: also please take a look at the 'Newbies' section of our forum.


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 08, 2022 4:26 pm 
Offline

Joined: Mon Oct 03, 2022 9:44 pm
Posts: 26
BigDumbDinosaur wrote:
PC Building Yoshi wrote:
Hello, I'm working on a PCB Design for my 8-Bit 6502 computer Project. I want a Serial Port connected to a 6522 VIA. I want the serial Port to connect to a modern Computer for a Keyboard, to send 6502 Assembly code files directly into the CPU's memory and to troubleshoot the Computer easily. However, I'm confused on exactly how I can connect the 9 Pins of a Serial Port to a 6522 Via's 8-Bit I/O pins and I have some other questions that I have. Here is a Small list of questions I have.

  • how I can connect the 9 Pins of a Serial Port to a 6522 Via's 8-Bit I/O pins?
  • Are there any Serial Interface ICs that's compatible with the 6502 CPU I should use instead of the 6522?
  • The feature I want where I can directly send 6502 Assembly code into the CPU's ROM chip, Is that even Possible?

Any help and Advice will appreciated and thanked in Advance!

I recommend you use a UART for this purpose. While the 6522 does have a serial shift register feature, it isn’t designed to communicate with a standard TIA-232 serial port, such as on a PC.

The 65C51 UART will directly interface to the 6502 bus, however the WDC version has a serious hardware bug that complicates use of the transmitter in an efficient manner. There are workarounds for the problem, as well as other UARTs that can be used, which information you should be able to find with the forum search functions.

Meanwhile, I strongly recommend you study Garth’s build-a-6502-computer write-up in its entirety before making any design decisions.


Thank you very much for the Information! I'll check Garth's Page!


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 08, 2022 4:34 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
Welcome, Yoshi. It might be good to link back to your previous query:
6502 CPU and TMS9918A VDP VRAM, Select and Write Logic Help

I'd reiterate what's been said already: you need somehow to get some initial code into that ROM, before you can run anything on your computer. There are various ideas in various threads, about this bootstrapping problem, or about programming a ROM using an Arduino or similar. You might well learn what you need from Garth's primer, or from other sources.

And also I'd reiterate that connecting to a serial port using a VIA is not an obvious or easy thing to do. The usual thing is to use a UART or a DUART (which is a dual UART). As with all engineering, there's more than one way to do it.

It might be worth noting that you don't necessarily need to connect to a serial port - to connect to a PC you might use some other protocol, with some hardware to adapt to USB and then use the USB connection to the PC. Both i2c and SPI are possibilities. But the UART is the most obvious.

The usual advice is to try very hard not to be too ambitious. Don't proceed as if this first build is going to be your only build. Treat the first build as a learning experience. The best idea is not to build your own design first, but to start with an existing simple design. You will learn a lot which will help you with your own design.

One simple design is Grant Searle's
http://searle.x10host.com/6502/Simple6502.html
but other designs would also serve the purpose.


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 08, 2022 4:43 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 575
What you want to do is possible and is often called a bit banged serial port. But it will be slower than a hardware UART. But here are some examples:

I own a 6502 40th Anniversary Computer Badge that bit bangs it's serial port. See: http://www.sunrise-ev.com/6502.htm

Back in the 80s I couldn't afford an 850 interface to connect a modem to my Atari 800, and I purchased a modem that connected to the joystick port. It was limited to 300 baud, but worked well enough. The Atari's Pokey chip is somewhat similar to the VIA.

The Radio Shack Color Computer uses the Motorola PIA chip to bit bang a serial port. That chip is similar to the VIA chip and it would be worth looking at the schematic on how it did it. As for software, the 6809 is different from the 6502 and the CoCo's ROM likely wouldn't directly translate, but it might give you some ideas.

As others have said, bit banging is slower than hardware and CoCo owners often bought a serial port cartridge with a hardware UART. I never bought an 850 interface but better modem options eventually were available for the Atari as well.


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 08, 2022 10:38 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8433
Location: Southern California
There's kind of a lot here, so you might need to digest it a little bit at a time.  What you're envisioning is more complex than you apparently anticipated; but none of it is insurmountable.  You'll undoubtedly come up with more questions, and then we can help you sort it out and get going.

Quote:
  • how I can connect the 9 Pins of a Serial Port to a 6522 Via's 8-Bit I/O pins?

First, this is definitely not ideal; but I'll get to that in a minute.

If you were to connect it to a VIA, you could connect the various signals to port I/O pins.  Most of the pin choice will not be critical; but I would recommend connecting the RxD (receive data) to one of the CA or CB lines as well as a PA or PB pin, so that besides being able to read the pin, you can also get an interrupt if data starts coming in when you're not watching for it in a loop. Next, I would recommend that the PA or PB pin to which you connect the RxD be bit 6, since reading the port with the BIT instruction automatically puts bit 6 in the V flag which you then transfer to the C flag to shift into the byte you're building, or you can do a conditional branch on it.

If you're using the higher voltages of RS-232 (that's the common traditional name; the up-to-date language is "TIA-232") rather than TTL-level serial, you'll be going through line drivers and receivers to get from those higher voltages to TTL levels and vice-versa.  Probably the most popular line driver and receiver IC is the MAX232; but there are many others.  I've usually used the MC145406 (same thing as the SN75C1406), because I've always had the ±10V (actual voltage is very non-critical) power-supply voltages available on the board, and this IC takes less board space because it doesn't need external capacitors and the extra pins to connect to them for the charge pumps.  The 16-pin DIP has three line drivers and three line receivers.

However:

Quote:
  • Are there any Serial Interface ICs that's compatible with the 6502 CPU I should use instead of the 6522?

The 6522 and 65c22 have indeed been used to bit-bang asynchronous serial even at 57,600 bps; but it's definitely not ideal.  Since timing is stringent, instruction cycle counts have to be exact, and nothing else can be allowed to interrupt during the process, and the processor can't be doing anything else during transmission or reception.

Traditionally, it has been the 6551 or 65c51 (ie, CMOS version) that have been put on the 6502's bus to get asynchronous serial communication.  I've used the 65c51 for decades and never had any trouble with it.  I could wish that a couple of the functions had been separated rather than being controlled by the same bit in the command register; but it hasn't been any real problem in my applications, and separating them would have required adding another register-select pin.  The WDC W65C51 (which I have not used, but it's the only one still in production) has a serious bug in that the transmit-register-empty flag in the status register makes it look like it's always ready to accept another byte when you're transmitting.  There are ways around it, including ways that are better than just doing a software delay loop.  However, these, and possibly the absence of FIFOs (First-In, First-Out, multi-byte buffers) for transmit and receive [1], have caused it to fall out of favor, and other UARTs to become more popular.  One of those has been the 28L92, which unfortunately has recently been discontinued—see viewtopic.php?f=4&t=7289 —but the topic gives alternatives that are partially compatible.

One UART I've exercised but not put to serious use yet is the 16-pin MAX3100 SPI-interfaced one that's available in a 14-pin DIP.  So instead of

    6502  -->  6551 ACIA  -->  line drivers & receivers  -->  RS-232 (TIA-232)

you'd have (assuming you big-bang the SPI with a 6522):

    6502  -->  6522 VIA  -->  (via SPI)  -->  MAX3100 UART  -->  line drivers & receivers  -->  RS-232 (TIA-232)

(or different line drivers and receivers can get you to RS-422 or -485; or you can forgo the line drivers and receivers altogether if you just want TTL-level serial).

It may initially look pointless to go through a serial interface to get to an IC that gives you another serial interface.  SPI however is synchronous serial, not asynchronous serial, so it is much, much easier to bit-bang, not having any timing requirements, let alone stringent ones like RS-232 has.  Further, if you have SPI, you can simultaneously connect many other things to it as well, and there are hundreds, if not thousands, of ICs on the market that interface through SPI, for example A/D and D/A converters, flash memories, USB interfaces, programmable-gain amplifiers, signal generators, GPIO, etc..  There's sample working code to bit-bang SPI with a VIA, on my site.

It's not clear, Yoshi, in your head post (welcome, BTW), if you are familiar with the differences between synchronous and asynchronous serial.  I try to give a concise description and comparison of the various popular serial interfaces at viewtopic.php?p=7606#p7606, and a more in-depth article, somewhat 6502/6551-oriented, on RS-232 (which is asynchronous serial), at http://wilsonminesco.com/RS-232/RS-232primer.html .  My apologies—it's one of the very first articles I ever wrote, and is all text for the first half of it.  Hopefully my writing has improved considerably since then, but hopefully also it will be plenty understandable.


Quote:
  • The feature I want where I can directly send 6502 Assembly code into the CPU's ROM chip, Is that even Possible?

If you send it assembly language, your 6502 computer will need an assembler to translate that into machine language.  There's basically a 1:1 relationship; but the assembly language is the human-readable source code (although much of what we see posted can hardly be called "readable,"  :lol: ), whereas the machine language is just a string of hexadecimal numbers which is ultimately the only thing the processor can use.

OTOH, if you have it already assembled on the PC and just want to put the hex numbers in memory, you'll need some overhead bytes to tell your 6502 computer what addresses to put these in.  That, along with error-detection, is the purpose of Intel Hex, Motorola S-Record, and other such file types.  Decoding that will take some software on your 6502 computer as well.

Next, you mention putting it in ROM.  ROM is "Read-Only Memory," meaning the computer generally cannot write to it.  There is however EEPROM (electrically erasable programmable read-only memory) which the computer can indeed write to in-circuit; but the writing is much much slower than writing to RAM, and you'll need software to control that process, too.  You might do better starting with a separate, dedicated PROM / EPROM / EEPROM / flash programmer.  You'll kind of need that anyway to get some sort of boot code onto the computer, as Ed and Alarm Siren said.



[1] I don't particularly think of the lack of a FIFO in the '51 to be a problem, because the 6502 has such good interrupt performance, and the interrupt overhead you have to go through for each byte received or transmitted is minimal, unlike the situation with many other processors that truly need the UART to have FIFOs.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 09, 2022 1:24 pm 
Offline

Joined: Mon Oct 03, 2022 9:44 pm
Posts: 26
BigEd wrote:
Welcome, Yoshi. It might be good to link back to your previous query:
6502 CPU and TMS9918A VDP VRAM, Select and Write Logic Help

I'd reiterate what's been said already: you need somehow to get some initial code into that ROM, before you can run anything on your computer. There are various ideas in various threads, about this bootstrapping problem, or about programming a ROM using an Arduino or similar. You might well learn what you need from Garth's primer, or from other sources.

And also I'd reiterate that connecting to a serial port using a VIA is not an obvious or easy thing to do. The usual thing is to use a UART or a DUART (which is a dual UART). As with all engineering, there's more than one way to do it.

It might be worth noting that you don't necessarily need to connect to a serial port - to connect to a PC you might use some other protocol, with some hardware to adapt to USB and then use the USB connection to the PC. Both i2c and SPI are possibilities. But the UART is the most obvious.

The usual advice is to try very hard not to be too ambitious. Don't proceed as if this first build is going to be your only build. Treat the first build as a learning experience. The best idea is not to build your own design first, but to start with an existing simple design. You will learn a lot which will help you with your own design.

One simple design is Grant Searle's
http://searle.x10host.com/6502/Simple6502.html
but other designs would also serve the purpose.


Luckily I've been following your last bit of advice.

Dose the 6551 count as a UART?

Thank you for the information!


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 09, 2022 1:48 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1373
Yes, the 6551 counts, but they refer to it as an ACIA (Asynchronous Communications Interface Adapter).

I wouldn't recommend it, and I have many of them from various manufacturers, NMOS, CMOS and a decent quantity of the recent WDC parts which are defective. Coding around this problem is not something I care to do. However, if you really want to use one, I suggest you look for a Rockwell R65C51, as these do work properly. Note that a "Px" is at the end, where the "x" is 1 to 4, being the maximum rated clock speed in megahertz. Also, if you want some code to test your hardware setup around a 6551, then you can try my Micromon code (github) which has a small monitor and an interrupt-driven transmit and receive for the 6551 acting as a console.

I moved over to the NXP UARTs some years ago (after BDD's recommendation) and they are excellent. Sadly, NXP have discontinued them. TI are making a replacement, but in QFP (quad flat package) only. You could also look at getting a couple older NXP SCC2691 UARTs, which are available in DIP, making it easier to work with. I have code that runs those too, as I use it on my C02 Pocket SBC.

Good luck on making progress.... and have fun.

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


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 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:  
cron