Adventures with I2C & Minerva Mk2

Anything QL Software or Programming Related.
User avatar
Popopo
Super Gold Card
Posts: 553
Joined: Wed Apr 07, 2021 10:37 am

Re: Adventures with I2C & Minerva Mk2

Post by Popopo »

Very interesting T0nyt,
this post will help me a lot with some tests that I am doing.
I had no idea that QL could use I²C nativaly. What saves a lot of time.

Thank you


User avatar
t0nyt
QL Wafer Drive
Posts: 1169
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Adventures with I2C & Minerva Mk2

Post by t0nyt »

Pr0f wrote: Sun Sep 07, 2025 11:58 am
Pr0f wrote: Sun Sep 07, 2025 11:48 am I think the address is correct - and it's the bottom bit of the byte that selects whether reading or writing, the next bit in is the selectable address (A0 or A2) that it can operate at.
The Mivera manual says the following:

Thus to write $1234 to location $56, the following is sent:
<start><$A0><$56><$l2><$34><stop>
Note that the address of 80 is doubled to $A0, and the write bit, 0, inserted as the least
significant bit.
To read back from locations $60.63, the following is sent:
After the second start condition the device address is sent out again, but this lime with a
read bit, 1, inserted as the LSB, so $AI is sent: at this point the 8583 starts outputting
data until the stop condition occurs.
Thanks. I’d better go back thru my posts and adjust the addresses if this applies to everything rather than just $A0/$50. Will double check the others as it explains why the 32kb device says $A0 as well


User avatar
t0nyt
QL Wafer Drive
Posts: 1169
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Adventures with I2C & Minerva Mk2

Post by t0nyt »

Ok, I just found more information that I think explains it all

The HTU21D Datasheet says it does have a 7 bit address, in this case &40

But it gets shifted left to add a read/write bit so &40 becomes &80

So I2C_IO uses just the 7 bit address &40, but if used in the command string it needs to be &80

Thanks Pr0f, it all makes sense now

I'll go thru and correct my posts, will also re-check the clock stretching as I may of been using the wrong address in the command string
Last edited by t0nyt on Sun Sep 07, 2025 3:15 pm, edited 1 time in total.


User avatar
t0nyt
QL Wafer Drive
Posts: 1169
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Adventures with I2C & Minerva Mk2

Post by t0nyt »

Have now corrected the device posts

Will re-try the clock stretching test as soon as I've knocked up a test program

EDIT: can't get clock stretching to work with I2C_IO so far, will leave it until I start work on assembler versions


The next devices I'll be trying as time allows will be:
Light Sensor (test program written, waiting part to test)
Text to Speech (will be concentrating on this once part arrives)
Barometric Pressure (really complicated maths in this one)
An OLED 128x64 Display (think this will be a lot of work too)
Last edited by t0nyt on Sun Sep 07, 2025 5:34 pm, edited 2 times in total.


User avatar
t0nyt
QL Wafer Drive
Posts: 1169
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Adventures with I2C & Minerva Mk2

Post by t0nyt »

Popopo wrote: Sun Sep 07, 2025 12:25 pm Very interesting T0nyt,
this post will help me a lot with some tests that I am doing.
I had no idea that QL could use I²C nativaly. What saves a lot of time.

Thank you
Hi Popopo

Not sure it can be considered "native" as it needs the Minerva Mk2?

One thing I do want to look into though is whether, since I have both JS and Minerva ROM's switchable in my Minerva Mk2, I could lift the I2C code from Minerva to run as a LRESPR'd binary under JS and still access the I2C bus & RTC


martyn_hill
QL Wafer Drive
Posts: 1131
Joined: Sat Oct 25, 2014 9:53 am

Re: Adventures with I2C & Minerva Mk2

Post by martyn_hill »

Hi tOnyt!

Whilst in principle it should be perfect tly.possinle.to access the I2C bus whilst running a different QDOS version, I suspect that the tight timing loops that are used by the I2C toolkit rely on the primitive routines running in uncontended memory at a fixed or at least consistent execution speed - i.e. in ROM. Doable...


User avatar
t0nyt
QL Wafer Drive
Posts: 1169
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Adventures with I2C & Minerva Mk2

Post by t0nyt »

martyn_hill wrote: Sun Sep 07, 2025 4:45 pm Hi tOnyt!

Whilst in principle it should be perfect tly.possinle.to access the I2C bus whilst running a different QDOS version, I suspect that the tight timing loops that are used by the I2C toolkit rely on the primitive routines running in uncontended memory at a fixed or at least consistent execution speed - i.e. in ROM. Doable...
Thanks Martyn. This a project for the future so will bear this in mind

Many thanks
Tony


User avatar
t0nyt
QL Wafer Drive
Posts: 1169
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Adventures with I2C & Minerva Mk2

Post by t0nyt »

Interestingly, to me at least, the Datasheet for the BH1750 Barometric Pressure Sensor seems to specify just the 7 bit address whereas all the others, so far, are the shifted 1 bit values

It specifies (depending on jumper) either &23 or &5C

So those would seem to be the values to use for I2C_IO parameter 3, but would need to be doubled if used in the command string


User avatar
t0nyt
QL Wafer Drive
Posts: 1169
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Adventures with I2C & Minerva Mk2

Post by t0nyt »

Have created a simple i2c bus scanner

DELETED AS NEW VERSION IS ON PAGE 5
Attachments
IMG_5027.jpeg
Last edited by t0nyt on Mon Sep 08, 2025 8:01 am, edited 1 time in total.


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

Re: Adventures with I2C & Minerva Mk2

Post by Pr0f »

So for the AT24C256 device :

And the PCF8583 device:

Meaning if A0,A1 and A2 on the NVRAM are all grounded, and A0 on the RTC is grounded - then they are using the same address - which explain the contention you were seeing Tony.
Attachments
Screenshot pcf8583.png
Screenshot_24C256.png


Post Reply