Q68 I2C Driver

Anything QL Software or Programming Related.
Martin_Head
Aurora
Posts: 852
Joined: Tue Dec 17, 2013 1:17 pm

Q68 I2C Driver

Post by Martin_Head »

I have been working on patching the Minerva I2C driver to work with the Q68.

This is my first working version (00.4). But I don't have any I2C devices to test it with other than the Q68's built in RTC chip.

Is anyone prepared to do some testing with external I2C devices to see if it is working OK.

At the moment the driver is only running at a clock speed of about 34KHz. The next job is to try to get it up to the standard 100KHz

This test program will set and read the Q68's Real Time Clock

Code: Select all

100 REMark *** Q68 I2C test program ***
110 REMark Martin Head 24/03/2022
120 REMark Version 00.4
130 c=RESPR(2000)
140 LBYTES dos1_i2c_q68_BIN,c
150 PRINT "code loaded at ";c,HEX$(c,32)
160 CALL c
170 PRINT "   II_DRIVE at ";PEEK_L(c+4),HEX$(PEEK_L(c+4),32)
180 STOP
190 :
200 REMark Tests
210 :
220 REMark Read Q68 backup clock
230 x$=CHR$(164)& CHR$(0) : REMark Address device
240 x$=x$&CHR$(4)&CHR$(188) : REMark Read 4 bytes
250 x$=x$&CHR$(255) : REMark Terminate cmd
260 t$=I2C_IO(x$,4,104,1)
270 :
280 REMark Result from RTC will be in little edian format
290 PRINT DATE$(2^24*CODE(t$(4))+65536*CODE(t$(3))+256*CODE(t$(2))+CODE(t$(1)))
300 STOP
310 :
320 REMark Set the Q68 backup clock
330 REMark Set RTC to 21/3/2022   ($73261E0F)
340 REMark Note send in little edian format
350 x$=CHR$(164)&CHR$(0)&CHR$($F)&CHR$($1E)&CHR$($26)&CHR$($73)
360 x$=x$&CHR$(255) : REMark Terminate cmd
370 t$=I2C_IO(x$,4,104,5)
380 STOP
390 :
Attachments
Q68_I2C_004.zip
(1.58 KiB) Downloaded 68 times
Q68 I2C User Manual.pdf
(71.65 KiB) Downloaded 74 times


User avatar
Pr0f
QL Wafer Drive
Posts: 1300
Joined: Thu Oct 12, 2017 9:54 am

Re: Q68 I2C Driver

Post by Pr0f »

There are some 8 bit parallel I2C breakout boards on ebay - https://www.ebay.co.uk/itm/273468863517 ... SwuzFgR-Be

That may be useful for testing - you can have several of these on the bus. Also - to protect the Q68 - you may want one of the isolated buffer boards that's available for I2C - I think they work upto 400KHz SCL clock - so should work for most boards.


FrancoisLanciault
Trump Card
Posts: 167
Joined: Mon Aug 08, 2011 11:08 pm

Re: Q68 I2C Driver

Post by FrancoisLanciault »

Thank you Martin! I looked onto this a few years ago, but the task was too difficult for me. Does it runs only from normal memory or do you need to use some of the Q68 fast memory ?

François


Derek_Stewart
Font of All Knowledge
Posts: 3957
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Q68 I2C Driver

Post by Derek_Stewart »

Hi,

Looks great, excellent software, as usual from Martin.

I was going to assemble similar boards as Prof mentioned to emulate TF Services I2C interfaces.


Regards,

Derek
User avatar
Pr0f
QL Wafer Drive
Posts: 1300
Joined: Thu Oct 12, 2017 9:54 am

Re: Q68 I2C Driver

Post by Pr0f »

There are a lot of good boards out there already - at reasonably cheap prices - I picked up a few good I2C boards when I ordered a jumbo experimenters pack for Arduino - came with all sorts of goodies, but did also include some interesting I2C devices - like temp / humidity sensor, I2C display, RTC, and some general I/O devices. Was a kit of over 100 parts in total.


Martin_Head
Aurora
Posts: 852
Joined: Tue Dec 17, 2013 1:17 pm

Re: Q68 I2C Driver

Post by Martin_Head »

FrancoisLanciault wrote:Does it runs only from normal memory or do you need to use some of the Q68 fast memory ?
Normal memory. I have not yet tried using fast memory. It may go a bit faster, but it uses the Q68 hardware timer for the serial clock. Which would limit it.

It uses a subroutine to introduce delays to time the serial clock and data reading. Initially just to get it working, I disregarded processor instruction times and set the delays to be about 4.5uS serial clock pulses. Which would be about 100KHz. But I found that the clock pulses came out about three times longer than wanted. Hence it 's running at about a third of the desired speed.

Yesterday I had a play with the delay routine, figuring out the processor instruction times overhead. I found that if I just had an empty delay subroutine, with just the return. Then the serial clock was pushing 200KHz. At this speed I could still read the RTC. But on my Q68 the rise time of the SDA line was starting to get in the way. The rise time of the SCL was about 0.2uS, but the rise time of the SDA line was about 2.2uS

I am going to try some trial and error tests of different delay counts to try to get the SCL to about 100KHz.


User avatar
Peter
QL Wafer Drive
Posts: 1987
Joined: Sat Jan 22, 2011 8:47 am

Re: Q68 I2C Driver

Post by Peter »

Hi Martin,

excellent job! The rise time on the SDA line comes from the 10 K Pullup on the Q68 which is typical for 100 kHz standard mode. It is possible to add smaller values like 2.2 K externally if 400 kHz fast mode is desired.

All the best
Peter


Martin_Head
Aurora
Posts: 852
Joined: Tue Dec 17, 2013 1:17 pm

Re: Q68 I2C Driver

Post by Martin_Head »

Version 0.06
After some speed optimization of the timing delay routine, The driver now runs at the I2C standard speed of 100KHz in normal RAM.
Interrupts are now disabled during the I2C_IO function.
Attachments
Q68_I2C_006.zip
(19.32 KiB) Downloaded 51 times
Q68_I2C Manual.zip
(70.13 KiB) Downloaded 63 times


User avatar
Peter
QL Wafer Drive
Posts: 1987
Joined: Sat Jan 22, 2011 8:47 am

Re: Q68 I2C Driver

Post by Peter »

Hi Martin, many thanks for the good work. One correction to the manual: Pullups of 2.2 K or larger to 5V are allowed.


Martin_Head
Aurora
Posts: 852
Joined: Tue Dec 17, 2013 1:17 pm

Re: Q68 I2C Driver

Post by Martin_Head »

Here's version 0.07

This version auto-configures itself for the Q68's normal or fast memory.

As there are no other changes, I have not bothered about a manual update.
Attachments
Q68_I2C_007.zip
(21.16 KiB) Downloaded 52 times


Post Reply