I2C_IO Help Please?

Anything QL Software or Programming Related.
User avatar
NormanDunbar
Forum Moderator
Posts: 2506
Joined: Tue Dec 14, 2010 9:04 am
Location: Buckie, Scotland
Contact:

Re: I2C_IO Help Please?

Post by NormanDunbar »

Hi Derek,

you would need a cross compiler, or Assembler on the QL, then a Ercall port that copes with 112500 baud and a version of "avrdude" to do the uploads over serial.

I don't think we can do this. :(

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.
Derek_Stewart
Font of All Knowledge
Posts: 4854
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: I2C_IO Help Please?

Post by Derek_Stewart »

t0nyt wrote: Thu Sep 04, 2025 7:06 pm 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


IMG_5011.jpeg


Again, thanks to all
Hi Tony,

Does the register retain the measured input of is the value updated from the input source?


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

Re: I2C_IO Help Please?

Post by t0nyt »

Derek_Stewart wrote: Fri Sep 05, 2025 7:40 am Does the register retain the measured input of is the value updated from the input source?
Hi Derek,

Not sure I 100% understand the question, but if you mean could you request the measurement, go off to do something else (rather than just pause) and come back and read the value it measured previously then I believe so (not tested though)

I don't know what would happen if you accessed another device on the i2c bus between measure and read, that will need testing!

My plan for the assembler basic extension would be to offer the options to either measure/pause/read OR just measure and separately read the return value

Something like i2c_htu21d("T" or "H",<function>) where function is "W"ait, "M"easure or "R"ead


Post Reply