Using the Dallas 1Wire Java API with J2ME CLDC and JemBuilder

Dallas OneWire Last Modified:2002 Apr 24

Summary:
In order to use the Dallas 1Wire Java API with J2ME CLDC, you must properly configure some JemBuilder libraries, properties and forName string entries. This applies equally to SaJe or JStamp.

Instructions

J2ME CLDC is a more restricted Java edition and configuration than the 1Wire Java API assumes. For this reason you need to use the latest and greatest 1Wire J2ME package available from Dallas.

The JemBuilder information below refers to a specific project of course, but the principles apply to any 1Wire project. The com port property and the forName strings need to be specific to your circumstances.


Files specific to this project:

listOW_ram JAR file (20 KBytes) Jar file with all the sources, JBuilder and JemBuilder project files, javadocs, etc specific to this example.

Files you will need for any J2ME-CLDC 1Wire project:

Dallas 1Wire J2ME JAR (900 KBytes)
April 2002
You don't need the 1Wire patch classes anymore if you use the 1Wire J2ME package. At the moment it is owapi_1_00B_J2ME.tgz but check the ftp site for any newer versions. At the moment this J2ME package doesn't have javadocs, get them in the generic 1Wire Java API package.
Dallas Java 1Wire API ftp site Here is the whole 1Wire file archive including the generic 1Wire API which has the JavaDocs.

Using 1Wire with JStamp and the JStamp Development Station:

The use of Dallas 1Wire network is the same with JStamp or SaJe, the only difference is where the serial to 1Wire adapter is, and how it is powered. The Java code is identical. SaJe has a DS2480 on board and a Dallas-pinout RJ12 with power and 1Wire signals already there. With JStamp you need to plug in a DS9097U plus add a power connection to power the adapter, since the DS9097U steals power from the serial port RTS and DTR lines, and these are unconnected on JStamp dev station PCB rev 1.10 and older.

RTS and DTR are pins 4 and 7 on the JSDS DB9M. The DS9097U doesn't say how much current it needs, but these pins feed a small 5V regulator, so assume they need to be at least 5V. The latest DS9097U data sheet (www.iButton.com) specifies >= 5V supply. They can handle at least up to 10 or 12 volts since these are normal RS232 levels.

With a DS9097U-09 on a JSDS, applying power to DB9M pin 4
5V = 1.9 mA
6V = 1.65 mA
7 to 10V = 1.65 mA

Now with a blue dot reader DS1402-DR8 and a DS1920 button:
brief surge then same 1.65 mA

The DS9097U seems to be short circuit limited to 16 mA, that was the most I could pull into it with the 1Wire outputs shorted (as can happen when inserting an iButton a bit cocked into the reader).

The DS1920 can require up to 1 mA of current during conversion, according to its data sheet.

For 3 mA of supply to the DS9097U you could use a 1600 to 2000 ohm resistor from the MAX232A's 10V signal (U1 pin2). Note that U1 is under the JStamp socket, and its a small surface mount part. This makes soldering to it a challenge. Plus then you need to get the wire from the top of the board to the bottom to attach it to the DB9 pin.

Better yet, and a lot easier, power the DS9097U with 5V from the underside of the board. J8 pin 4 (adjacent to JStamp pin 40) is Vcc. I used a 10 ohm resistor (it provides some minimal isolation from Vcc to the 1Wire adapter - 500 mA short circuit current through a 1/8 watt resistor should turn it into a fuse). Tie this to serial A pin 4. With the 9097U and blue dot with DS1920 it still has 5.00 volts and seems happy.

Close up photo of the 5V power supply added to serial A. the resistor is 10 ohms. The voltage at the DB9 pin 4 must be as close as possible to 5V to satisfy the DS9097U. Click the photo for a larger version. Note: there is more clearance between the resistor lead and the JP4 paste jumper than appears. Be safe and apply some heatshrink or sleeving around the resistor leads since they are tied directly to Vcc.

Use a similar approach for serial B.


In addition you need to configure JemBuilder as shown here:
Create a JemBuilder library and make its classpath the OneWireAPI_J2ME Jar file. (Ignore the rest of the libraries I show here, they are not relevent to this example)
Now that you have the library defined you still need to tell JemBuilder to use it, in the JVM0->classpath options. (Ignore all the other unused libraries, they are irrelevent to this example).

In addition, the 1Wire API expects some system properties. (These must be set as shown or you will get runtime null pointer errors). Note that the onboard SaJe DS2480 uses COM2 but on a JStamp Development Station you can use a DS9097U serial adapter on COM1 or COM2. You will need to make onewire.port.default=com1 or com2 as appropriate and make sure your code references the correct port (if it uses OneWireAccessProvider.getAdapter instead of OneWireAccessProvider.getDefaultAdapter(). These values are case sensitive.

The os.arch is the architecture. The os.name property keeps the 1Wire package from thinking we're a desktop with J2SE.

Finally, you need to add the USerialAdapter and OneWireContainer strings to the forName options. In addition you need to add a OneWireContainerXX string (where XX is the Dallas hexadecimal device type) for every 1Wire device which you wish to support. If you fail to add all the 1Wire devices here, and one is plugged into your network, you will get a runtime null pointer error, so be sure to place a try-catch block in your code and handle such a possibility. In this case I have added four strings. The highlighted one is the support for device type 10 which is the DS1920 temperature sensor.

Also set the drivers to support whichever com ports on JStamp you will be using. Do *not* direct system.out to the same port you will be using with the 1Wire adapter! Since the 1Wire package uses javaxcomm (not system.out) you do not need to direct system.out to either port in order to use the 1Wire API. You *do* need to tell JemBuilder to use the com drivers (to that it links in javaxcomm support).
Here is output from Charade with an 8x1 wire board (4 DS2406 - device type 12) and a DS1920
(device type 10) present (device 09 is in the DS9097U adapter):

vm.0 charadeIO active
vm.0 heap monitor active
vm.0 heap monitor active
[TEXTIO.0]->ListOW bab Apr 2002 A
[TEXTIO.0]->Default Adapter: DS9097U
[TEXTIO.0]->Default Port: com1
[TEXTIO.0]->
[TEXTIO.0]->Adapter: DS9097U Port: com1
[TEXTIO.0]->
[TEXTIO.0]->Try enumerating all devices
[TEXTIO.0]->AF00000054A94110
[TEXTIO.0]->EE00000011DB7212
[TEXTIO.0]->0C00000011D05D12
[TEXTIO.0]->5500000011DBBD12
[TEXTIO.0]->7C00000011D96F12
[TEXTIO.0]->60000001888D7C09