Adventures with I2C & Minerva Mk2
Re: Adventures with I2C & Minerva Mk2
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
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
Re: Adventures with I2C & Minerva Mk2
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 wellPr0f wrote: Sun Sep 07, 2025 11:58 amThe Mivera manual says the following: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.
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.
Re: Adventures with I2C & Minerva Mk2
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
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.
Re: Adventures with I2C & Minerva Mk2
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)
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.
Re: Adventures with I2C & Minerva Mk2
Hi PopopoPopopo 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
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
-
- QL Wafer Drive
- Posts: 1131
- Joined: Sat Oct 25, 2014 9:53 am
Re: Adventures with I2C & Minerva Mk2
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...
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...
Re: Adventures with I2C & Minerva Mk2
Thanks Martyn. This a project for the future so will bear this in mindmartyn_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...
Many thanks
Tony
Re: Adventures with I2C & Minerva Mk2
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
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
Re: Adventures with I2C & Minerva Mk2
Have created a simple i2c bus scanner
Devices which were attached for the example output were:
Minerva Mk2 RTC/NVRAM (&5C/&50)
AT24C256 32KB (&54)
LCD Display (&27)
HTU21D Temperature/Humidity (NOT DETECTED)
I believe the non-detection of HTU21D is a known problem, but will look into it a bit more
EDIT: There is no solution for HTU21D as it will only respond to a specific write at start, so it doesn't respond to a read which is used for detection, and I think it would be foolish to send a write command to every i2c address given the havoc it could cause
Sample output
Devices which were attached for the example output were:
Minerva Mk2 RTC/NVRAM (&5C/&50)
AT24C256 32KB (&54)
LCD Display (&27)
HTU21D Temperature/Humidity (NOT DETECTED)
I believe the non-detection of HTU21D is a known problem, but will look into it a bit more
EDIT: There is no solution for HTU21D as it will only respond to a specific write at start, so it doesn't respond to a read which is used for detection, and I think it would be foolish to send a write command to every i2c address given the havoc it could cause
Code: Select all
100 WHEN ERRor
110 f=0
120 CONTINUE
130 END WHEN
150 PRINT "SCAN STARTING"
200 c$=CHR$(188) & CHR$(255)
210 FOR x = 0 TO 127
220 f=1
230 r$=I2C_IO(c$,1,x,1)
240 IF f=1 THEN PRINT "I2C Device Found at " & HEX$(x,8) & " (" & HEX$(x*2,8) & ")"
250 NEXT x
260 PRINT "SCAN COMPLETE"
Re: Adventures with I2C & Minerva Mk2
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.
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.