Just wondered if anyone has already got a software stack written for
using the I2C protocol on an IO port / PIO / 8255 chip.
If so, can I have a copy as I cant seem to find a Z80 based one on the
net!
Cheers,
Dicky
Printable View
Just wondered if anyone has already got a software stack written for
using the I2C protocol on an IO port / PIO / 8255 chip.
If so, can I have a copy as I cant seem to find a Z80 based one on the
net!
Cheers,
Dicky
On Jul 3, 1:54*pm, dickydodds <di...@dickydodds.com> wrote:[color=blue]
> Just wondered if anyone has already got a software stack written for
> using the I2C protocol on an IO port / PIO / 8255 chip.
>
> If so, can I have a copy as I cant seem to find a Z80 based one on the
> net![/color]
Not sure if there's one in the z88dk libraries. May be worth a look.
dickydodds wrote:[color=blue]
> Just wondered if anyone has already got a software stack written for[/color]
A software stack?
push_bc:
dec hl
ld (hl),c
dec hl
ld (hl),c
ret
pop_bc:
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ret
You know what I meant - a software I2C implementation for the
spectrum.
I found a possible one on the net but it was converted from 8086 code
and not quite right. I aim to go through it and try making it work on
my hols in August. Not quite sure though how to handle the Open
Collector part of the I2C spec though when I use an 8255 chip....
dicky
On 2008-07-15, dickydodds <dicky@dickydodds.com> wrote:[color=blue]
> You know what I meant - a software I2C implementation for the
> spectrum.[/color]
It's quite easy, I've done software SPI and software TWI (two wire
interface) using a Z80. No fancy chips, just the relevant port decode
circuitry (which could be a 74HCT138, or perhaps 74HCT688) and a
74LVX273 flip flop (the 74LVX series, incidentally, is 3.3 volt logic
with 5v tolerant TTL compatible IO). I used the LVX series because my
SPI device wasn't 5v tolerant (the TWI device was, but it could also run
off 3.3v too).
Open collector output for the TWI was done by cheating a bit - simple
resistor multiplexing, a 1K resistor between the FF's output and input
so the same line leaving the board could both transmit and receive - the
Tx/Rx line of the TWI left the board at the junction between the flip
flop's input and the resistor. The Z80 would just tell that line to sit
high when idle (and so look like an open collector output with a pull-up
resistor to the TWI device at the other end). You could do the same with
the chip that you're using if it doesn't have open collector outputs.
The basic detail is you just need to roll bits out into the carry flag,
then toggle the appropriate line on the flip flop according to the state
of the carry flag. Presumably, you're controlling the clock signal. I'm
a little bit vague on the I2C protocol, but IIRC the wire protocol has a
clock signal (which the 'master' controls) so in most cases timing or
baud rate isn't critical so long as you don't try and drive it faster
than it can be driven.
Reading SPI or TWI is the reverse - test a bit and roll it into the
accumulator, then store it after 8 iterations.
If this part of it will be any use for giving you ideas, I'll stick the
source online. But be warned, I'm not the world's greatest Z80 asm
programmer!
--
From the sunny Isle of Man.
Yes, the Reply-To email address is valid.
[color=blue]
> If this part of it will be any use for giving you ideas, I'll stick the
> source online. But be warned, I'm not the world's greatest Z80 asm
> programmer!
>[/color]
Wow - thanks for the info - I like the sound of the 2 resistor method
pretending to be OC outputs! I was intending to just use a cheap
signal transistor to do it using 2 i/o lines but yours saves a line,
however, isnt the 273 output only? Dont you mean a 373 as its bi-
directional?
I am intending to use an 8255 - purely because it gives me 24 i/o
lines for other uses too (and becuase I ahve 2 lying around) - though,
to be honest, I dont know what else yet! I want the i2c so I can have
a real time clock but also use other chips - eg temperature. I have
loads of 146818 RTC's but they are clunky to use with their shared
address / data lines (Anyone want any? Let me know!).
For info, I have also been changing my spectrum to use lower power by
using Sami Vehemaa's info on changing the ram to a single chip (128k x
8) and changed the lower 16k rams to 4164's - all brings the current
down! I also stuck an LCD Video display on it but the one I have is
rubbish, but, a PSONE LCD looks promising so far.
BTW, I am not the best programmer either, but I get by and my code
works too!
If you dont mind (to save me re-inventing the wheel) would you post
your code online as I might be able to nick some parts of it!! When I
am all finished, I will put this project online too to share and
perhaps some kind souls will sreamline my code LOL!
Thanks for your info.
Dicky
Latest Update.
I added a PSOne LCD to a spectrum Plus2A and built in a PSU under the
cassette bit - portable spectrum! I took it on holiday with me and
manged to read the temperature from a ds1621+ in BASIC using the
Printer port and Dylans resistor hack to emulate open collector output
to an input port pin - Yeehaa I hear you say. I used BASIC to get the
basics of reading the chip sorted out.
However, now I am home, for some reason now it keeps reading -68 deg C
everytime I read it... I shall have to get to the bottom of that!
As for building the MC routines, it seems I am VERY rusty having not
programmed in it for a while - but I will get there.
I was also hoping to get a ds1307 clock chip running too but I took
the wrong crystals with me - doh!
When I get a working set of routines running, I will update you all -
someone might have a use for it when its finished apart from me!
Dicky