cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to make a PIA tester with a STM32F103

Elektraglide
Associate III

I'm building a little tester for 6821 PIA using a STM32F103.

I need to be able to write to the data bus of the PIA, and also read from it.  (6821 has 4 registers that are addressed using 2-bits input RS0,RS1).

So 8 GPIO pins for the databus.  And I use 3 more GPIO pins for RS0,RS1 and R/W pin.

For writing to the PIA:
I set the GPIO pins to output,  set the output pins actual data and then make R/W low for writing.

For read from the PIA:
I set the GPIO pins to input,  make R/W high for reading and then read the input pins..


Does that sound right?   I'm concerned about the timing between the GPIO data bus pins switching from output to input (and back)  and then toggling the R/W line to the PIA. 

Is all this switching even needed?  


18 REPLIES 18
gbm
Principal

Considering the timing of STM32F103 and MC6821, everything the STM does is much faster then 6821 response. So, provide all the needed delays and the proper E line timing.

Basically, for writing:

  • set RW LOW
  • set data bus as output
  • set RSx and data value
  • set E high
  • delay
  • set E low
  • set data bus as inputs
  • delay to guarantee the proper timing for E low state

For reading:

  • data lines should be set as inputs - see above
  • set RW high
  • set RSx
  • set E high
  • delay
  • sample data
  • set E low
  • delay

I suspect you might be interested in this:

https://hackaday.io/project/185010-mc6800-computer

 

 

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

Nice.  Thank you.

I thought I saw in the 6821 spec sheet it doesn't clock under 150kHz  so I've been clocking it at around that but I do have delays between register writes etc.

And would bit banging the E clock input work?  

 

gbm
Principal

I already forgot that 6821 is not static. In that case, I would rather use timer output in PWM mode for E control and implement the state machine for 6821 access in timer ISR, using Update and CC interrupt. It's hard to achieve the required ISR performance with interrupt routing via HAL, so I'd recommend to write your own, full ISR using direct register access and definitely no HAL for setting the GPIO ports.

To relax timing constraints, instead of using update and CC interrupt from PWM output channel, you may use two other CC interrupts triggered before PWM output changes (close to the end of period and some time before PWM pulse end).

Contrary to what many people say, 300 kHz timer interrupt is not impossible for SMT32F103. I did something around 450 kHz with much more complex service than in your case. Just leave this single interrupt at the highest priority (0) and stay away from HAL for it. (You may still use HAL for configuration and other stuff outside of this ISR.)

I actually did something similar few years ago in my SDC_One MC6800 computer, in which STM32 was both supplying the clock for MC6800 and serving as memory and peripheral device for it.

Here is the link; unfortunately the MC6800 version is not mentioned and no photo is shown.

https://hackaday.io/project/164007-sdcone

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

> And would bit banging the E clock input work?  

Probably, assuming the 6821 is a static design.
You would have to check with the datasheet.

I hope you realize the 6821 is a 5V device, you will most probably need some level shifting electronics for the stimulation side.
And either choose 5V-tolerant inputs on the F103 side, or again use level shifting.

MC68xx is specifed at TTL-compatible levels, so it may be driven from 3.3 V circuits (only CLK inputs to MC6800 require higher input levels). It outputs 5 V, so yes, FT inputs are required in theory, In practice, series resistor of 3k is enough for non-FT inputs.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
mƎALLEm
ST Employee

Hello @Elektraglide ,

I'm a bit surprised that someone needs to build a tester for a such fossil IC from Motorola. An IC which dates from the 70's in the last century :)!

So I'm bit curious. You said you are planning to make a tester for that parallel interface MC6021 using STM32! Is it just a tester to make sure it's working as expected on all IOs on portA and PortB or you need just to expend the GPIO ports?

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@gbm wrote:

I already forgot that 6821 is not static. In that case, I would rather use timer output in PWM mode for E control and implement the state machine for 6821 access in timer ISR, using Update and CC interrupt. It's hard to achieve the required ISR performance with interrupt routing via HAL, so I'd recommend to write your own, full ISR using direct register access and definitely no HAL for setting the GPIO ports.

To relax timing constraints, instead of using update and CC interrupt from PWM output channel, you may use two other CC interrupts triggered before PWM output changes (close to the end of period and some time before PWM pulse end).

Contrary to what many people say, 300 kHz timer interrupt is not impossible for SMT32F103. I did something around 450 kHz with much more complex service than in your case. Just leave this single interrupt at the highest priority (0) and stay away from HAL for it. (You may still use HAL for configuration and other stuff outside of this ISR.)

 


Did exactly that and have TIM4 use AF to waggle PB9 @ 1MHz

And yes, I found I could do around 400kHz with a TIM4 interrupt by hitting registers directly:

if (TIM4->SR & TIM_IT_Update)
{
  TIM4->SR = ~TIM_IT_Update;

  TimeSec++;
  if ((TimeSec & 1) == 0)
    GPIOC->BSRR = GPIO_Pin_13;
  else
    GPIOC->BRR = GPIO_Pin_13;
}
 

@Ozone wrote:

I hope you realize the 6821 is a 5V device, you will most probably need some level shifting electronics for the stimulation side.
And either choose 5V-tolerant inputs on the F103 side, or again use level shifting.


Yep, using PA8 - PA12 for data bus connect to 6821

I am hoping I can get away without a level shifting chip..


@gbm wrote:

MC68xx is specifed at TTL-compatible levels, so it may be driven from 3.3 V circuits (only CLK inputs to MC6800 require higher input levels). It outputs 5 V, so yes, FT inputs are required in theory, In practice, series resistor of 3k is enough for non-FT inputs.


Meaning I need 3k series resistors on my databus connection to the PIA?   Ahh... 

Irony is that I only starting building this because the PIA on my Williams Defender machine seems busted so wanted an easy way of testing the other 6821s I have lying around.   But I suspect I may have already fried one on my breadboad.. Doh!