08M2 and DS1631 Control Register

PADJ

Member
I'm using a 8M2 to read temperature from I2C DS1631 and format as serial data for a remote PC. Simple conversion from published arduino code, but the 1631 requires write to a control register to start the conversion.
No data is involved, just needs 2 bytes sent - the device address and the register ($51) location.

The published code does this
Code:
Wire.beginTransmission(DS1631_ADDRESS);
Wire.write(0x51);
Wire.endTransmission();
I tried hi2cout $51 - but this gives syntax error. Can this be done with the 8M2?

PJ
 

srnet

Senior Member
I tried hi2cout $51 - but this gives syntax error
To be expected, thats not the format of the hi2cout command ...................

Perhaps you want to use;

HI2COUT location,(variable,...)

As described on page 74 of manual2
 

PADJ

Member
To be expected, thats not the format of the hi2cout command ...................

Perhaps you want to use;

HI2COUT location,(variable,...)

As described on page 74 of manual2
But there is no variable to be written!

Edit:
Tried
hi2cout $51,() - Syntax error
 
Last edited:

Technical

Technical Support
Staff member
You can send single bytes, and don't forget hi2csetup first

Code:
hi2csetup i2cmaster, DS1631_ADDRESS, i2cbyte, i2cslow
do
hi2cout ($51)
pause 1000
hi2cin $AA,(b20,b19)
pause 1000
loop
 

PADJ

Member
You can send single bytes, and don't forget hi2csetup first

Code:
hi2csetup i2cmaster, DS1631_ADDRESS, i2cbyte, i2cslow
do
hi2cout ($51)
pause 1000
hi2cin $AA,(b20,b19)
pause 1000
loop
Thanks technical - I didn't realize that 'location' was optional, but now I've RTFM (again) it's obvious.
In fact if I'd downloaded the latest manual I would have seen the logic plot as well!

Lesson learned, and I'll wire it up tonight if the snow doesn't bring the power down <g> and report back.

UPDATE That seems to do the job! Thanks again. Now for the fun part.
 
Last edited:

PADJ

Member
A year later, and time to add more sensors.
To do this I need multiple hi2csetup statements, so to minimize code space can DS1631_ADDRESS be a variable?
This passes syntax OK, but I don't have the parts yet.
Code:
for b0 = $90 to $9E step 2
hI2CSetup I2CMASTER,b0,i2cslow,i2cbyte
...
...
next
 

hippy

Technical Support
Staff member
There should be no problem setting the address via a variable. In almost all cases, wherever a pin identifier, number or named constant is usually specified, it can be substituted by a variable holding an appropriate number.

In the few cases where a variable cannot be used the compiler will give an error when a variable is used.
 

PADJ

Member
There should be no problem setting the address via a variable. In almost all cases, wherever a pin identifier, number or named constant is usually specified, it can be substituted by a variable holding an appropriate number.

In the few cases where a variable cannot be used the compiler will give an error when a variable is used.
Interesting, thanks. So if I used a 20M2 with 8 DS18B20 instead, could I do something like this?
Code:
for b0 = b.0 to b.7
readtemp12 b0,w13
...
...
next
 
Top