Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:08 24 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : DS1621 Temperature Measurement

Author Message
crackerjack

Senior Member

Joined: 11/07/2011
Location: Australia
Posts: 164
Posted: 03:33pm 27 Sep 2011
Copy link to clipboard 
Print this post

Not an earth-shattering post by any means, but just a little program to demonstrate using the MM to obtain a temperature from a DS1621 via I2C. It may prove of interest to somebody - particularly if you compare trying to do the same thing in C or on an Arduino which would be many lines of code plus libraries. On the MM it can be done in very few lines.

The code posted below could have been made a whole lot shorter, but I've made it a bit verbose on purpose as a bit of a tutorial. The DS1621 command values and config register settings are defined as variables, but could easily just be literals.

I have also included a trace of the I2C bus activity of a single temperature "transaction" for those who may want to follow the steps of the I2C commands from the MM.

Note that in the example given the DS1621 was wired at address &H48 (all three address input pins at ground). Alternate address config would of course require changing the value of ds1621_addr at line 50.

Hope this is of some use to somebody, somewhere...

[code]
10 CLS
20 INPUT "How many seconds between Temperature measurements"; delay
30 CLS
40 delay = delay * 1000
50 ds1621_addr = &h48
60 config_cmd = &hAC
70 ' MSb Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 LSb
80 ' Done THF TLF NVB X X POL 1SHOT
90 config_reg = &b00000001
100 start_convert_cmd = &hEE
110 read_temp_cmd = &hAA
120 DIM temp(2)
130 I2CEN 100, 100
140 DO WHILE a$ = ""
150 a$ = INKEY$
160 I2CSEND ds1621_addr, 1, 2, config_cmd, config_reg
170 I2CSEND ds1621_addr, 0, 1, start_convert_cmd
180 I2CSEND ds1621_addr, 1, 1, read_temp_cmd
190 I2CRCV ds1621_addr, 0, 2, temp(0)
200 temp = (temp(0) * 256 + temp(1)) / 128 * 5 / 10
210 IF temp(0) >= 128 THEN
220 temp = temp - 256
230 ENDIF
240 LOCATE 50, 50
250 ? "As at " TIME$ " Temperature is" temp " degrees C "
260 PAUSE delay
270 LOOP
280 I2CDIS
[/code]

The reads, writes, stops, starts, acks and nacks on the bus:

[code]
I2C START BIT
WRITE: 0x90 ACK
WRITE: 0xAC ACK
WRITE: 0x01 ACK
I2C START BIT
WRITE: 0x90 ACK
WRITE: 0xEE ACK
I2C STOP BIT
I2C START BIT
WRITE: 0x90 ACK
WRITE: 0xAA ACK
I2C START BIT
WRITE: 0x91 ACK
READ: 0x17
READ: ACK 0x80
NACK
I2C STOP BIT
[/code]
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024