AVR as UART/ACIA IC
AVR as UART/ACIA IC
Hi guys
I've been playing around with an ATMEGA 328P Microcontroller for communication with RS232C.
All works quite well.
I was wondering: Has anyone tried to use an AVR or PIC as a ACIA/UART in a 65C02 design? I was thinking of either interfacing a '328P with a VIA or, even better, talk directly with the 65C02 bus.
I can't see this being a major problem. I could even simulate an 65C51 flags, memory mapped locations, etc...
Can anyone see any potential issues?
I've been playing around with an ATMEGA 328P Microcontroller for communication with RS232C.
All works quite well.
I was wondering: Has anyone tried to use an AVR or PIC as a ACIA/UART in a 65C02 design? I was thinking of either interfacing a '328P with a VIA or, even better, talk directly with the 65C02 bus.
I can't see this being a major problem. I could even simulate an 65C51 flags, memory mapped locations, etc...
Can anyone see any potential issues?
Last edited by banedon on Mon Sep 14, 2015 10:08 pm, edited 1 time in total.
Re: AVR as UART/ACIA IC
It would work well hooked up to a VIA with handshaking etc. Less sure about directly hooking it to the CPU bus. Maybe with some very tight AVR ASM... Whats the max clock rate on that AVR?
Not my cup of tea in any case.
Not my cup of tea in any case.
8 bit fun and games: https://www.aslak.net/
Re: AVR as UART/ACIA IC
Max clock is 20MHz
Re: AVR as UART/ACIA IC
Hi banedon.
Could you use something like a flip-flop with the ACIA chip select signal as an input and the output connected to the 65C02 'RDY' line to have the 65C02 "wait" for the time required by the AVR to (A) recognize it's chip select, (B) select internal UART register based on the A0..A3 address lines, (C) setup port data direction register according to the R/W line, and, (D) push or pull data to/from the data bus? Of course the AVR would have to clear the flip-flop to allow the 65C02 to complete the current 65C02 cycle.
Could you use something like a flip-flop with the ACIA chip select signal as an input and the output connected to the 65C02 'RDY' line to have the 65C02 "wait" for the time required by the AVR to (A) recognize it's chip select, (B) select internal UART register based on the A0..A3 address lines, (C) setup port data direction register according to the R/W line, and, (D) push or pull data to/from the data bus? Of course the AVR would have to clear the flip-flop to allow the 65C02 to complete the current 65C02 cycle.
Re: AVR as UART/ACIA IC
The AVR microcrontroller have several interrupt lines that can trigger by a high-low or low-high transition. So you could immediately react on a chip select signal. If clocked fast enough there should be enough time to set the RDY line for the CPU. You have enough time to read the databus and the address lines and react on that. You could simulate several hardware by one 328P by trggering different code on different chip select signals. You ATMEGA could work as ACIA and as VIA at the same time.
How should I know what I think, until I hear what I've said.
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: AVR as UART/ACIA IC
banedon wrote:
I was wondering: Has anyone tried to use an AVR or PIC as a ACIA/UART in a 65C02 design?
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: AVR as UART/ACIA IC
The biggest issue would be dealing with reading the UART, since the AVR would have to very quickly assert the data, then tri state the bus on the very next clock.
I second BBDs question.
I second BBDs question.
8 bit fun and games: https://www.aslak.net/
Re: AVR as UART/ACIA IC
Hi banedon,
to interface the 6502 with a microcontroller you need to implement some registers that can be read or written by the 6502. You need to create a protocol so the 6502 and the AVR can exchange "data". So the effort is quite high. You basically have two options, a asynchronous design and a synchronous design. The Asynchronous design would use "ready" and "ack" status signals that tell the other side when a datum has been sent or when a datum has been read by the either side. Daryls' text video V2 is an example when the 6502 writes to the AVR. The reverse can be used to allow the AVR to send data to the 6502. Or you use the RDY to stop the 6502 and use an interrupt to let the AVR do the rest.
The synchronous design would require that everything happens synchronously to PHI2. The easiest is to have the AVR create PHI2 and poll a "chip-select" and read some address bits to know when to read or write to the 6502 like in Michaels viewtopic.php?f=1&t=2854&p=31658&hilit=test#p31658 3-chip design. But this is limited to rather low PHI2 clock rates, even if the AVR just copies from the 6502 to the internal registers this uses at least 10-20 cycles. Using Interrupts of the AVR in a synchronous design is out of the question this is too slow. You require at least 7 cycles before the first instruction of the ISR
is executed.
In any case, you should build a solution that is as universal as possible, because to only use the USART of the AVR it is not worth the effort as BDD mentions correctly, however if you once have a general solution then you could use the plethora of IO features of a AVR, including I2C, SPI, Timers etc.
Using a VIA to interface with the AVR is possible but very slow and it uses a lot of pins. Also it is not trivial to build a bidirectional bus between the AVR and the VIA, as each side decides on the direction of the IO pins. Instead of a VIA I would use something like the 74HCT652.
Cheers
Peter
to interface the 6502 with a microcontroller you need to implement some registers that can be read or written by the 6502. You need to create a protocol so the 6502 and the AVR can exchange "data". So the effort is quite high. You basically have two options, a asynchronous design and a synchronous design. The Asynchronous design would use "ready" and "ack" status signals that tell the other side when a datum has been sent or when a datum has been read by the either side. Daryls' text video V2 is an example when the 6502 writes to the AVR. The reverse can be used to allow the AVR to send data to the 6502. Or you use the RDY to stop the 6502 and use an interrupt to let the AVR do the rest.
The synchronous design would require that everything happens synchronously to PHI2. The easiest is to have the AVR create PHI2 and poll a "chip-select" and read some address bits to know when to read or write to the 6502 like in Michaels viewtopic.php?f=1&t=2854&p=31658&hilit=test#p31658 3-chip design. But this is limited to rather low PHI2 clock rates, even if the AVR just copies from the 6502 to the internal registers this uses at least 10-20 cycles. Using Interrupts of the AVR in a synchronous design is out of the question this is too slow. You require at least 7 cycles before the first instruction of the ISR
is executed.
In any case, you should build a solution that is as universal as possible, because to only use the USART of the AVR it is not worth the effort as BDD mentions correctly, however if you once have a general solution then you could use the plethora of IO features of a AVR, including I2C, SPI, Timers etc.
Using a VIA to interface with the AVR is possible but very slow and it uses a lot of pins. Also it is not trivial to build a bidirectional bus between the AVR and the VIA, as each side decides on the direction of the IO pins. Instead of a VIA I would use something like the 74HCT652.
Cheers
Peter
Re: AVR as UART/ACIA IC
A hybrid solution would be to let the AVR control the clock only when selected. Normally the 65C02 would run at its maximum clock, but when the IO address for the AVR is selected, a simple gate could disconnect the main clock and allow the AVR to clock when it is ready.
And yes, only replacing the UART is not worth the effort. But as Peter said, there is much more in a microcontroller, not just serial interfaces and timers, but an analog comparator, analog converters, PWM outputs, a timer capture input, clock output, lots of flash-ROM... So the possibilities are plenty.
In the next release of my emulator, you will be able to connect other AVRs to utilize their IO capacity. Unfortunately it is a 4 bit bus structure requiring the cooperation of the master AVR and therefore nothing for a native parallel bus CPU.
And yes, only replacing the UART is not worth the effort. But as Peter said, there is much more in a microcontroller, not just serial interfaces and timers, but an analog comparator, analog converters, PWM outputs, a timer capture input, clock output, lots of flash-ROM... So the possibilities are plenty.
In the next release of my emulator, you will be able to connect other AVRs to utilize their IO capacity. Unfortunately it is a 4 bit bus structure requiring the cooperation of the master AVR and therefore nothing for a native parallel bus CPU.
6502 sources on GitHub: https://github.com/Klaus2m5
Re: AVR as UART/ACIA IC
cbscpe wrote:
The synchronous design would require that everything happens synchronously to PHI2. The easiest is to have the AVR create PHI2 and poll a "chip-select" and read some address bits to know when to read or write to the 6502 like in Michael's 3-chip design.
Quote:
But this is limited to rather low PHI2 clock rates, even if the AVR just copies from the 6502 to the internal registers this uses at least 10-20 cycles.
Quote:
... only using the USART of the AVR it is not worth the effort as BDD mentions correctly...
Last edited by Michael on Tue Sep 15, 2015 2:43 pm, edited 1 time in total.
Re: AVR as UART/ACIA IC
Klaus2m5 wrote:
A hybrid solution would be to let the AVR control the clock only when selected. Normally the 65C02 would run at its maximum clock, but when the IO address for the AVR is selected, a simple gate could disconnect the main clock and allow the AVR to clock when it is ready.
I would not change the clock. I would prefer a solution using RDY. A changing clock inhibits parallel use of 65xx peripherals. I already thought about such a solution. But I have still some issues with my setup using RDY. To start a AVR cycle is rather easy, you only need to sample the chip-select that selects the AVR with PHI2 using a 74C74 flip flop. The same chip-select also informs the AVR. Now the AVR has all the time he needs to transfer the datum from the 65xx bus to the internal register or reading a register and put it onto the 65xx bus. However now starts the tricky part. Now the AVR needs to release RDY and at the same time the sampling of the chip-select signal must work immediately in case the next cycle is again for the AVR, e.g. if you use the flash. With high 65xx system clock rates this could be a challenge. I have not encountered a good solution for this. However using the flash will be slow, so I would not consider it, but still RDY must be released considering that the next cycle might still use the AVR, e.g. when you use 16-bit transfers together with a W65C816.
Cheers
Peter
P.S. I'm looking forward to your solution to use AVR as IO for your emulator
Re: AVR as UART/ACIA IC
It occurs to me that in my earlier post I was describing Jeff's (Dr Jefyll's) "wait state generators" from this post and this post in another thread. My apologies to Jeff for the missing attribution.
Forgive me if I'm going off-topic, but, I'm curious... Could that wait-state logic be duplicated in a GAL/PAL?
Forgive me if I'm going off-topic, but, I'm curious... Could that wait-state logic be duplicated in a GAL/PAL?
Re: AVR as UART/ACIA IC
Michael wrote:
Forgive me if I'm going off-topic, but, I'm curious... Could that wait-state logic be duplicated in a GAL/PAL?
You can use this as a starting point.
Daryl
Please visit my website -> https://sbc.rictor.org/
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: AVR as UART/ACIA IC
Michael wrote:
It occurs to me that in my earlier post I was describing Jeff's (Dr Jefyll's) "wait state generators" from this post and this post in another thread. My apologies to Jeff for the missing attribution.
Forgive me if I'm going off-topic, but, I'm curious... Could that wait-state logic be duplicated in a GAL/PAL?
Forgive me if I'm going off-topic, but, I'm curious... Could that wait-state logic be duplicated in a GAL/PAL?
As a reminder, the NMOS 6502 does not respond to RDY during a write cycle. That deficiency was one of the reasons Commodore used "clock stretching" in the C-128 when I/O devices were being accessed.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: AVR as UART/ACIA IC
All these wait state generators generate a fixed predicted number of wait states. Has anyone a more bus related wait-state generator? I mean something like used in typical bus protocols where the CPU is always halted until a ACK signal is generated by the selected device (IO, Memory, ROM etc). Preferably the ACK should be a edge sensitive signal. E.g. in a PDP-11 system the CPU always stalled when performing a read or write until a CONT signal was asserted on the bus. Even Memory had to create the CONT signal.