Page 2 of 3
Re: I2C_IO Help Please?
Posted: Thu Sep 04, 2025 12:31 pm
by XorA
Get yourself a cheap USB logic analyser, that will decode what is happening on the actual I2C bus for you!
There are nasty things in I2C like clock stretching that not all I2C hosts support.
Re: I2C_IO Help Please?
Posted: Thu Sep 04, 2025 12:57 pm
by t0nyt
XorA wrote: Thu Sep 04, 2025 12:31 pm
Get yourself a cheap USB logic analyser, that will decode what is happening on the actual I2C bus for you!
There are nasty things in I2C like clock stretching that not all I2C hosts support.
I have one of those (got it to capture mdv signals following Danieles instructions), no real idea what to do though
Re: I2C_IO Help Please?
Posted: Thu Sep 04, 2025 2:06 pm
by t0nyt
I’ve got a NVRAM I2c board coming tomorrow
Am fairly confident in how to write/read that so will see how I get on
Re: I2C_IO Help Please?
Posted: Thu Sep 04, 2025 2:58 pm
by t0nyt
Made some progress with the HTU-21D
I did a read of the config register instead and I get the correct default value returned of 00000010 (2)
Re: I2C_IO Help Please?
Posted: Thu Sep 04, 2025 3:20 pm
by t0nyt
JACKPOT!!!
I had to break down the command into 2 sections so I could pause
A write to trigger the measurement
*** then pause while measurement completed ***
A read to get the values
This is the test code that's working for temperature reading (E3) but also works for Humidity (E5)
I was expecting the HTU-21D "hold mode" to pause everything itself, but it seems not
Code: Select all
100 C$=CHR$(164) & CHR$(HEX('E3')) & CHR$(255)
110 r$=I2C_IO(C$,0,HEX('40'),1)
120 PAUSE 200
130 C$=CHR$(2) & CHR$(188) & CHR$(255)
140 r$=I2C_IO(С$,3,HEX('40'),1)
150 PRINT Code(r$)
160 PRINT Code(r$(2 to 2))
170 PRINT Code(r$(3 to 3))
Many thanks all
Re: I2C_IO Help Please?
Posted: Thu Sep 04, 2025 5:39 pm
by XorA
Its almost certainly clock stretching then. I guess Minerva I2C does not support that!
Re: I2C_IO Help Please?
Posted: Thu Sep 04, 2025 7:03 pm
by t0nyt
XorA wrote: Thu Sep 04, 2025 5:39 pm
Its almost certainly clock stretching then. I guess Minerva I2C does not support that!
Yes, that has to be the case I guess. Shame but at least there's a workaround (don't know if there will always be a workaround though)
Re: I2C_IO Help Please?
Posted: Thu Sep 04, 2025 7:06 pm
by t0nyt
This is the TEST program for the HTU-21D (will eventually write an extension for it in assembler)
No error checking as it's just for testing
Code: Select all
100 c$=CHR$(164) & CHR$(HEX('FE')) & CHR$(255): REMark Soft Reset
110 r$=I2C_IO(c$,0,HEX('40'),1)
120 PAUSE 20 : REMark pause after reset?
130 r$=GetValue("T"): PRINT "Temperature: " & r$ & "c"
140 r$=GetValue("H"): PRINT "Relative Humidity: " & r$ & "%"
150 DEFine FuNction GetValue(V$)
160 LOCal e,v,c$,r$
170 SELect ON V$
180 ="H","h": e=HEX("E5") : REMark Relative Humidity
190 ="T","t": e=HEX("E3") : REMark Temperature
200 END SELect
210 c$=CHR$(164) & CHR$(e) & CHR$(255)
220 r$=I2C_IO(c$,0,HEX('40'),1)
230 PAUSE 200 : REMark WHAT PAUSE NEEDED???
240 c$=CHR$(2) & CHR$(188) & CHR$(255)
250 r$=I2C_IO(c$,3,HEX('40'),1)
300 v=CODE(r$(2 TO 2))
310 v=v&&253 : REMark strip status bits
320 v=v+(CODE(r$)*256)
330 SELect ON V$
340 ="H","h": v=-6+125*(v/65336)
350 ="T","t": v=-46.85+175.72*(v/65536)
360 END SELect
370 v=INT(v*10)/10
400 RETurn v
500 END DEFine
And a sample output from it
Again, thanks to all
Re: I2C_IO Help Please?
Posted: Thu Sep 04, 2025 8:56 pm
by NormanDunbar
Glad you got it working! Might I just say that it seems a lot easier in Assembly on an Arduino!
Cheers,
Norm.
Re: I2C_IO Help Please?
Posted: Thu Sep 04, 2025 10:00 pm
by Derek_Stewart
NormanDunbar wrote: Thu Sep 04, 2025 8:56 pm
Glad you got it working! Might I just say that it seems a lot easier in Assembly on an Arduino!
Cheers,
Norm.
just have find a way to programme an Arduino on the QL.