I2C_IO Help Please?
- XorA
- Site Admin
- Posts: 1733
- Joined: Thu Jun 02, 2011 11:31 am
- Location: Shotts, North Lanarkshire, Scotland, UK
Re: I2C_IO Help Please?
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.
There are nasty things in I2C like clock stretching that not all I2C hosts support.
Re: I2C_IO Help Please?
I have one of those (got it to capture mdv signals following Danieles instructions), no real idea what to do thoughXorA 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.
Re: I2C_IO Help Please?
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
Am fairly confident in how to write/read that so will see how I get on
Re: I2C_IO Help Please?
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)
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?
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
Many thanks all
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))
- XorA
- Site Admin
- Posts: 1733
- Joined: Thu Jun 02, 2011 11:31 am
- Location: Shotts, North Lanarkshire, Scotland, UK
Re: I2C_IO Help Please?
Its almost certainly clock stretching then. I guess Minerva I2C does not support that!
Re: I2C_IO Help Please?
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)XorA wrote: Thu Sep 04, 2025 5:39 pm Its almost certainly clock stretching then. I guess Minerva I2C does not support that!
Re: I2C_IO Help Please?
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
And a sample output from it
Again, thanks to all
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
Again, thanks to all
- NormanDunbar
- Forum Moderator
- Posts: 2506
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Buckie, Scotland
- Contact:
Re: I2C_IO Help Please?
Glad you got it working! Might I just say that it seems a lot easier in Assembly on an Arduino!
Cheers,
Norm.

Cheers,
Norm.
Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
-
- Font of All Knowledge
- Posts: 4854
- Joined: Mon Dec 20, 2010 11:40 am
- Location: Sunny Runcorn, Cheshire, UK
Re: I2C_IO Help Please?
just have find a way to programme an Arduino on the QL.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.
Regards, Derek